From a27e58ed6acc8e9719bd8ed7c226d2734ff7a654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Fri, 29 Jan 2021 21:09:02 +0000 Subject: Escape &, <, > --- README.html | 6 +++--- aux/emparse | 25 ++++++++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/README.html b/README.html index a96b35c..2dea2c7 100644 --- a/README.html +++ b/README.html @@ -104,7 +104,7 @@ You can download the file here [1]. Preformatted blocks start with a single tab:

-#include 
+	#include <stdio.h>
 	main() { puts("Hello world!\n"); }
 

Paragraphs

@@ -157,8 +157,8 @@ It is available for download [1]. translates into the following HTML:

-

It is available for download (link). -

+<p>It is available for download (<a href="v1.tgz">link</a>). +</p>

The default link text ("link") can be changed by setting diff --git a/aux/emparse b/aux/emparse index 65644e9..38bec54 100755 --- a/aux/emparse +++ b/aux/emparse @@ -2,6 +2,18 @@ # aux/emparse -- parse em source +function escape(s) { + if (s == "") { + gsub("&", "\\&") + gsub("<", "\\<") + gsub(">", "\\>") + } else { + gsub("&", "\\&", s) + gsub("<", "\\<", s) + gsub(">", "\\>", s) + } +} + function beginblock(name) { if (name == "nl") printf "

    \n" else printf "<%s>\n", name @@ -37,6 +49,7 @@ function breakblock() { function heading(level, line) { sub("^=* ", "", line) sub(" =*$", "", line) + escape(line) printf "%s\n", level, line, level # should inline formatting be supported in headings? } @@ -68,10 +81,11 @@ function item(level, type, line) { function term(line, t) { # t is a local variable if (opendef) printf "" opendef = 1 - t = $0; d = $0 + t = $0 sub("^ ", "", t) sub(": .*$", "", t) sub("^ [^:]+: ", "") + escape(t) printf "
    %s
    ", t } @@ -83,6 +97,7 @@ function ref(v) { } function format(line) { + escape(line) n = split(line, w, "[ ]") for (i = 0; i <= n; i++) { if (w[i] == "") continue; @@ -146,16 +161,18 @@ expectblock && /^ - / { newblock("ul") } expectblock && /^ [0-9a-z]+\. / { newblock("ol") } expectblock && /^ \[[0-9a-z]\]+ / { newblock("nl") } expectblock && /^ .*: / { newblock("dl") } -expectblock && /^ / { newblock("pre"); sub("^ ", "") } +expectblock && /^ / { newblock("pre") } expectblock && /^---$/ { expectblock = 0; printf "
    \n"; next } expectblock && /^= .* =$/ { heading(1, $0); next } -expectblock && /^== .* ==$/ { heading(3, $0); next } +expectblock && /^== .* ==$/ { heading(2, $0); next } expectblock && /^=== .* ===$/ { heading(3, $0); next } expectblock && /^==== .* ====$/ { heading(4, $0); next } expectblock && /^===== .* =====$/ { heading(5, $0); next } expectblock && /^====== .* ======$/ { heading(6, $0); next } expectblock { newblock("p") } +block = "pre" { sub("^ ", ""); escape(); printf "%s\n", $0; next } + block = "ul" && /^ - / { item(1, "ul", line) } block = "ol" && /^ [0-9a-z]+\. / { item(1, "ol", line) } block = "nl" && /^ \[[0-9a-z]\]+ [^ ]+$/ { next } # hyperlink reference @@ -173,6 +190,4 @@ block = "ol" && /^ [0-9a-z]+\./ { item(5, "ol", line) } block = "ul" && /^ -/ { item(6, "ul", line) } block = "ol" && /^ [0-9a-z]+\./ { item(6, "ol", line) } -block = "pre" && /^ / { sub("^ ", ""); printf "%s\n", $0; next } - { format($0) } -- cgit v1.2.3