summaryrefslogtreecommitdiff
path: root/buetow.org.sh
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2021-05-07 09:48:23 +0100
committerPaul Buetow <git@mx.buetow.org>2021-05-21 05:11:04 +0100
commitac284d28cdcf7a6d56a612d1612995d5eba05cd4 (patch)
treed05ce413edc3bcea1511662cfa1bfa3de349d1c1 /buetow.org.sh
parent193b0450773d85c4037257f6fca5631868b854d2 (diff)
atom feed now also includes the whole content
Diffstat (limited to 'buetow.org.sh')
-rwxr-xr-xbuetow.org.sh34
1 files changed, 25 insertions, 9 deletions
diff --git a/buetow.org.sh b/buetow.org.sh
index f6a9a95..738dcb4 100755
--- a/buetow.org.sh
+++ b/buetow.org.sh
@@ -124,8 +124,10 @@ ATOMHEADER
<email>$meta_email</email>
</author>
<summary>$meta_summary</summary>
- <content type="text/html">
- $content
+ <content type="xhtml">
+ <div xmlns="http://www.w3.org/1999/xhtml">
+ $content
+ </div>
</content>
</entry>
ATOMENTRY
@@ -148,21 +150,29 @@ ATOMFOOTER
## HTML module
+html::special () {
+ sed '
+ s|\&|\&amp;|g;
+ s|<|\&lt;|g;
+ s|>|\&gt;|g;
+ ' <<< "$@"
+}
+
html::paragraph () {
- local -r text="$1"
- test -n "$text" && echo "<p>$text</p>"
+ local -r text="$1"; shift
+ test -n "$text" && echo "<p>$(html::special "$text")</p>"
}
html::heading () {
- local -r text=$(sed -E 's/^#+ //' <<< "$1")
- local -r level="$2"
+ local -r text=$(sed -E 's/^#+ //' <<< "$1"); shift
+ local -r level="$1"; shift
- echo "<h${level}>$text</h${level}>"
+ echo "<h${level}>$(html::special "$text")</h${level}>"
}
html::quote () {
local -r quote="${1/> }"
- echo "<pre>$quote</pre>"
+ echo "<pre>$(html::special "$quote")</pre>"
}
html::img () {
@@ -192,6 +202,7 @@ html::link () {
descr="$descr $token"
fi
done < <(echo "$line" | tr ' ' '\n')
+ descr=$(html::special "$descr")
if grep -E -q "$IMAGE_PATTERN" <<< "$link"; then
html::img "$link" "$descr"
@@ -226,7 +237,7 @@ html::gemini2html () {
echo "</pre>"
is_plain=0
else
- echo "$line" | sed 's|<|\&lt;|g; s|>|\&gt;|g'
+ html::special "$line"
fi
continue
fi
@@ -270,6 +281,7 @@ html::generate () {
dest=${dest/.gmi/.html}
local dest_dir=$(dirname "$dest")
test ! -d "$dest_dir" && mkdir -p "$dest_dir"
+
cat header.html.part > "$dest.tmp"
html::gemini2html < "$src" >> "$dest.tmp"
cat footer.html.part >> "$dest.tmp"
@@ -282,6 +294,7 @@ html::generate () {
while read -r src; do
local dest=${src/gemtext/html}
local dest_dir=$(dirname "$dest")
+
test ! -d "$dest_dir" && mkdir -p "$dest_dir"
cp -v "$src" "$dest"
git add "$dest"
@@ -308,6 +321,9 @@ html::test () {
line=""
assert::equals "$(html::paragraph "$line")" ""
+ line="Foo &<>& Bar!"
+ assert::equals "$(html::paragraph "$line")" "<p>Foo &amp;&lt;&gt;&amp; Bar!</p>"
+
line="# Header 1"
assert::equals "$(html::heading "$line" 1)" "<h1>Header 1</h1>"