~sircmpwn/cgi-scripts

7d0483437ff511065eb27d200f44e85d977cd86c — Drew DeVault 4 years ago f26ae9b
implement <pre>
2 files changed, 10 insertions(+), 1 deletions(-)

M hn.py
M web2gmi.js
M hn.py => hn.py +3 -0
@@ 40,6 40,7 @@ if not path or path == "/":
    sys.stdout.write("20 text/gemini\r\n")
    print("# Hacker News")
    print()
    print("Note: the HTML to Gemtext conversion works best with articles")
    for post in posts:
        url = post['url']
        print(f"=> {gemini_url}/view?{quote(url)} {post['title']}")


@@ 47,5 48,7 @@ elif path == "/view":
    sys.stdout.write("20 text/gemini\r\n")
    sys.stdout.flush()
    subprocess.run(["node", "web2gmi.js", query_string])
    print("\n---\n")
    print(f"=> {query_string} View original (http)")
else:
    sys.stdout.write("51 Not found\r\n")

M web2gmi.js => web2gmi.js +7 -1
@@ 12,6 12,10 @@ const sanitize = html => sanitizer(html.replace(/\n/g, ""), {
  allowedTags: [],
  allowedAttributes: {},
}).trim();
const sanitizePre = html => sanitizer(html, {
  allowedTags: [],
  allowedAttributes: {},
}).trim();

const convert = (dom, title) => {
  let output = "";


@@ 69,7 73,9 @@ const convert = (dom, title) => {
        output += `=> ${el.src} ${el.alt ? el.alt : "(image)"}\n\n`
        break;
    case 'pre':
        output += "!!! PRE !!!\n\n";
        output += "```\n";
        output += sanitizePre(el.innerHTML) + "\n\n";
        output += "```\n";
        break;
    case 'blockquote':
        output += `> ${sanitize(el.innerHTML)}\n\n`;