aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rwxr-xr-xutils/parse-article-content.sh62
-rwxr-xr-xutils/parse-article.sh4
2 files changed, 64 insertions, 2 deletions
diff --git a/utils/parse-article-content.sh b/utils/parse-article-content.sh
new file mode 100755
index 0000000..40593c5
--- /dev/null
+++ b/utils/parse-article-content.sh
@@ -0,0 +1,62 @@
+#!/bin/bash
+
+# Skip file metadata, first 3 lines
+
+sanitize-html-entities () {
+ echo "$1" |
+ sed 's/</\&lt;/g' |
+ sed 's/>/\&gt;/g'
+}
+
+parse-article-content-file () {
+ local PRE_TAG=
+ local IGNORE_NEXT_PRE_TAG=
+ local INSIDE_PRE_TAG=
+ local CONTENT
+ local TLINE=
+
+ while IFS= read -r line; do
+ TLINE="$line"
+
+ if [ -z "$INSIDE_PRE_TAG" ]; then
+ echo "$line" | grep '<pre role="code"' > /dev/null
+ if [ $? -eq 0 ]; then
+ PRE_TAG=$line
+ INSIDE_PRE_TAG=1
+ TLINE="$line <!-- code-start -->"
+ fi
+ else
+ echo "$line" | grep '<pre' > /dev/null
+ if [ "$?" -eq 0 ]; then
+ IGNORE_NEXT_PRE_TAG=1
+ TLINE="<code>$(sanitize-html-entities "$line")</code>"
+ fi
+
+ echo "$line" | grep '</pre>' > /dev/null
+ if [ $? -eq 0 ]; then
+ if [ -n "$IGNORE_NEXT_PRE_TAG" ]; then
+ IGNORE_NEXT_PRE_TAG=""
+ TLINE="<code>$(sanitize-html-entities "$line")</code>"
+ else
+ INSIDE_PRE_TAG=""
+ PRE_TAG=""
+ TLINE="$line<!-- code-end -->"
+ fi
+ else
+ TLINE="<code>$(sanitize-html-entities "$line")</code>"
+ fi
+
+ fi
+
+ CONTENT="${CONTENT}
+$TLINE"
+ done <<< $(echo "$ARTICLE_FILE_CONTENT" | tail -n +3)
+
+ echo "$CONTENT"
+}
+
+if [ "$DO_NOT_PROCESS_HTML" = "true" ]; then
+ ARTICLE_CONTENT=$(echo "$ARTICLE_FILE_CONTENT" | tail -n +3)
+else
+ ARTICLE_CONTENT=$(parse-article-content-file)
+fi
diff --git a/utils/parse-article.sh b/utils/parse-article.sh
index c3e540a..b64c0ff 100755
--- a/utils/parse-article.sh
+++ b/utils/parse-article.sh
@@ -1,6 +1,7 @@
#!/bin/bash
ARTICLE_TITLE=$(basename "$ARTICLE_FILE")
+ARTICLE_FILE_SANITIZED="$(sanitize-filename "$ARTICLE_FILE")"
# Pick all file content
ARTICLE_FILE_CONTENT=$(cat "$ARTICLE_FILE")
@@ -8,8 +9,7 @@ ARTICLE_FILE_CONTENT=$(cat "$ARTICLE_FILE")
# The first 3 lines of the file are metadata information
ARTICLE_METADATA=$(echo "$ARTICLE_FILE_CONTENT" | head -n 3)
-# Skip file metadata, first 3 lines
-ARTICLE_CONTENT=$(echo "$ARTICLE_FILE_CONTENT" | tail -n +3)
+source $SCRIPT_DIR/utils/parse-article-content.sh
# Tags are placed on the first line of the file, delimited by commas
IFS=',' read -ra ARTICLE_TAGS <<< "$(echo "$ARTICLE_METADATA" | head -n 1)"