|
@ -373,19 +373,22 @@ async def handle_pad(args, padid, data, info, session): |
|
|
# once the content is settled, compute a hash |
|
|
# once the content is settled, compute a hash |
|
|
# and link it in the metadata! |
|
|
# and link it in the metadata! |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# include magic words |
|
|
# include magic words |
|
|
if args.magicwords: |
|
|
if args.magicwords: |
|
|
|
|
|
|
|
|
########################################## |
|
|
########################################## |
|
|
## INCLUDE __XXX__ MAGIC WORDS |
|
|
## INCLUDE __XXX__ MAGIC WORDS |
|
|
########################################## |
|
|
########################################## |
|
|
pattern = r'__[a-zA-Z0-9]+?__' |
|
|
pattern = r"__[a-zA-Z0-9]+?__" |
|
|
magic_words = re.findall(pattern, text) |
|
|
magic_words = re.findall(pattern, text) |
|
|
magic_words = list(set(magic_words)) |
|
|
magic_words = list(set(magic_words)) |
|
|
if magic_words: |
|
|
if magic_words: |
|
|
meta["magicwords"] = magic_words |
|
|
meta["magicwords"] = magic_words |
|
|
print('FOUND MAGIC WORD(s): {} in {}'.format(magic_words, padid)) |
|
|
print( |
|
|
|
|
|
"FOUND MAGIC WORD(s): {} in {}".format( |
|
|
|
|
|
magic_words, padid |
|
|
|
|
|
) |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
links = [] |
|
|
links = [] |
|
|
if args.css: |
|
|
if args.css: |
|
@ -470,7 +473,15 @@ async def handle_pad(args, padid, data, info, session): |
|
|
# mb: line causing the error of not writing the correct HTML content to the correct HTML file: |
|
|
# mb: line causing the error of not writing the correct HTML content to the correct HTML file: |
|
|
# url = info["localapiurl"] + "getHTML?" + urlencode(data) |
|
|
# url = info["localapiurl"] + "getHTML?" + urlencode(data) |
|
|
# mb: warning, HACK! Catching the error by writing the API request url manually ... |
|
|
# mb: warning, HACK! Catching the error by writing the API request url manually ... |
|
|
url = info["localapiurl"] + "getHTML?" + "padID=" + padid + "&" + 'apikey=' + data["apikey"] |
|
|
url = ( |
|
|
|
|
|
info["localapiurl"] |
|
|
|
|
|
+ "getHTML?" |
|
|
|
|
|
+ "padID=" |
|
|
|
|
|
+ padid |
|
|
|
|
|
+ "&" |
|
|
|
|
|
+ "apikey=" |
|
|
|
|
|
+ data["apikey"] |
|
|
|
|
|
) |
|
|
# print(url) |
|
|
# print(url) |
|
|
html = await agetjson(session, url) |
|
|
html = await agetjson(session, url) |
|
|
ver = {"type": "html"} |
|
|
ver = {"type": "html"} |
|
@ -487,7 +498,11 @@ async def handle_pad(args, padid, data, info, session): |
|
|
html, treebuilder="etree", namespaceHTMLElements=False |
|
|
html, treebuilder="etree", namespaceHTMLElements=False |
|
|
) |
|
|
) |
|
|
html5tidy( |
|
|
html5tidy( |
|
|
doc, indent=True, title=padid, scripts=args.script, links=links, |
|
|
doc, |
|
|
|
|
|
indent=True, |
|
|
|
|
|
title=padid, |
|
|
|
|
|
scripts=args.script, |
|
|
|
|
|
links=links, |
|
|
) |
|
|
) |
|
|
async with await trio.open_file(ver["path"], "w") as f: |
|
|
async with await trio.open_file(ver["path"], "w") as f: |
|
|
output = ET.tostring(doc, method="html", encoding="unicode") |
|
|
output = ET.tostring(doc, method="html", encoding="unicode") |
|
@ -498,7 +513,15 @@ async def handle_pad(args, padid, data, info, session): |
|
|
# print("PANIC: {}".format(exception)) |
|
|
# print("PANIC: {}".format(exception)) |
|
|
|
|
|
|
|
|
if args.all or args.magicwords: |
|
|
if args.all or args.magicwords: |
|
|
url = info["localapiurl"] + "getHTML?" + "padID=" + padid + "&" + 'apikey=' + data["apikey"] |
|
|
url = ( |
|
|
|
|
|
info["localapiurl"] |
|
|
|
|
|
+ "getHTML?" |
|
|
|
|
|
+ "padID=" |
|
|
|
|
|
+ padid |
|
|
|
|
|
+ "&" |
|
|
|
|
|
+ "apikey=" |
|
|
|
|
|
+ data["apikey"] |
|
|
|
|
|
) |
|
|
# print(url) |
|
|
# print(url) |
|
|
html = await agetjson(session, url) |
|
|
html = await agetjson(session, url) |
|
|
ver = {"type": "magicwords"} |
|
|
ver = {"type": "magicwords"} |
|
@ -512,15 +535,21 @@ async def handle_pad(args, padid, data, info, session): |
|
|
ver["path"] = p + ".magicwords.html" |
|
|
ver["path"] = p + ".magicwords.html" |
|
|
ver["url"] = quote(ver["path"]) |
|
|
ver["url"] = quote(ver["path"]) |
|
|
for magic_word in magic_words: |
|
|
for magic_word in magic_words: |
|
|
replace_word = "<span class='highlight'>"+magic_word+"</span>" |
|
|
replace_word = ( |
|
|
|
|
|
"<span class='highlight'>" + magic_word + "</span>" |
|
|
|
|
|
) |
|
|
if magic_word in html: |
|
|
if magic_word in html: |
|
|
html = html.replace(magic_word,replace_word) |
|
|
html = html.replace(magic_word, replace_word) |
|
|
doc = html5lib.parse( |
|
|
doc = html5lib.parse( |
|
|
html, treebuilder="etree", namespaceHTMLElements=False |
|
|
html, treebuilder="etree", namespaceHTMLElements=False |
|
|
) |
|
|
) |
|
|
# INSERT MAGIC WORDS HIGHLIGHTING STUFF HERE!!! |
|
|
# INSERT MAGIC WORDS HIGHLIGHTING STUFF HERE!!! |
|
|
html5tidy( |
|
|
html5tidy( |
|
|
doc, indent=True, title=padid, scripts=args.script, links=links, |
|
|
doc, |
|
|
|
|
|
indent=True, |
|
|
|
|
|
title=padid, |
|
|
|
|
|
scripts=args.script, |
|
|
|
|
|
links=links, |
|
|
) |
|
|
) |
|
|
async with await trio.open_file(ver["path"], "w") as f: |
|
|
async with await trio.open_file(ver["path"], "w") as f: |
|
|
output = ET.tostring(doc, method="html", encoding="unicode") |
|
|
output = ET.tostring(doc, method="html", encoding="unicode") |
|
|