Commit 911eca71 authored by Lauren N. Liberda's avatar Lauren N. Liberda
Browse files

html_encode: support for data from stdin

parent c73b8910
Pipeline #423 failed with stage
in 51 seconds
......@@ -39,7 +39,11 @@ function post_dump() {
# html_encode(string)
function html_encode() {
if [[ "$1" == "" ]]; then
sed 's/\&/\&amp;/g;s/</\&#60;/g;s/>/\&#62;/g;s/%/\&#37;/g;s/\//\&#47;/g;s/\\/\&#92;/g;s/'"'"'/\&#39;/g;s/"/\&#34;/g;s/`/\&#96;/g;s/?/\&#63;/g;'
else
sed 's/\&/\&amp;/g;s/</\&#60;/g;s/>/\&#62;/g;s/%/\&#37;/g;s/\//\&#47;/g;s/\\/\&#92;/g;s/'"'"'/\&#39;/g;s/"/\&#34;/g;s/`/\&#96;/g;s/?/\&#63;/g;' <<< "$1"
fi
}
# url_encode(string)
......
......@@ -7,8 +7,12 @@ function render() {
local -n ref=$1
local tmp=$(mktemp)
for key in ${!ref[@]}; do
if [[ "${ref[$key]}" != "" ]]; then
local value="$(html_encode "${ref[$key]}" | sed -E 's/\&/�UwU�/g')"
echo 's/\{\{\.'"$key"'\}\}/'"$value"'/g' >> "$tmp"
else
echo 's/\{\{\.'"$key"'\}\}//g' >> "$tmp"
fi
done
template="$(sed -E -f "$tmp" <<< "$template")"
sed -E 's/�UwU�/\&/g' <<< "$template"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment