fix: markdown embedding
This commit is contained in:
@@ -97,6 +97,23 @@ function read_file(path, out, line, rc) {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function read_file_or_render_md(path, ext, cmd, content, line, rc) {
|
||||||
|
content = ""
|
||||||
|
if (ext == "md") {
|
||||||
|
cmd = "sh \"" script_dir "/markdown.sh\" \"" path "\""
|
||||||
|
while ((cmd | getline line) > 0) {
|
||||||
|
content = content line "\n"
|
||||||
|
}
|
||||||
|
close(cmd)
|
||||||
|
} else {
|
||||||
|
while ((rc = getline line < path) > 0) {
|
||||||
|
content = content line "\n"
|
||||||
|
}
|
||||||
|
close(path)
|
||||||
|
}
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
|
||||||
function escape_html(s, t) {
|
function escape_html(s, t) {
|
||||||
t = s
|
t = s
|
||||||
gsub(/&/, "\\&", t)
|
gsub(/&/, "\\&", t)
|
||||||
@@ -189,7 +206,8 @@ function render_embed(src, alt, has_alt, force_inline, ext, local_path, conte
|
|||||||
if (force_inline && !is_global_url(src)) {
|
if (force_inline && !is_global_url(src)) {
|
||||||
local_path = resolve_local_path(src)
|
local_path = resolve_local_path(src)
|
||||||
if (local_path != "") {
|
if (local_path != "") {
|
||||||
content = read_file(local_path)
|
ext = ext_of(src)
|
||||||
|
content = read_file_or_render_md(local_path, ext)
|
||||||
if (content ~ /\n$/) sub(/\n$/, "", content)
|
if (content ~ /\n$/) sub(/\n$/, "", content)
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
@@ -217,7 +235,7 @@ function render_embed(src, alt, has_alt, force_inline, ext, local_path, conte
|
|||||||
if (is_inline_text_ext(ext)) {
|
if (is_inline_text_ext(ext)) {
|
||||||
local_path = resolve_local_path(src)
|
local_path = resolve_local_path(src)
|
||||||
if (local_path != "") {
|
if (local_path != "") {
|
||||||
content = read_file(local_path)
|
content = read_file_or_render_md(local_path, ext)
|
||||||
if (content ~ /\n$/) sub(/\n$/, "", content)
|
if (content ~ /\n$/) sub(/\n$/, "", content)
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
@@ -238,7 +256,7 @@ function render_typed_embed(etype, src, alt, has_alt, local_path, content) {
|
|||||||
if (!is_global_url(src)) {
|
if (!is_global_url(src)) {
|
||||||
local_path = resolve_local_path(src)
|
local_path = resolve_local_path(src)
|
||||||
if (local_path != "") {
|
if (local_path != "") {
|
||||||
content = read_file(local_path)
|
content = read_file_or_render_md(local_path, ext_of(src))
|
||||||
if (content ~ /\n$/) sub(/\n$/, "", content)
|
if (content ~ /\n$/) sub(/\n$/, "", content)
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,5 +77,5 @@ awk -f "$awk_dir/paragraphs.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_fi
|
|||||||
# Inline styles
|
# Inline styles
|
||||||
awk -f "$awk_dir/emoji.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file"
|
awk -f "$awk_dir/emoji.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file"
|
||||||
awk -f "$awk_dir/markdown_inline.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file"
|
awk -f "$awk_dir/markdown_inline.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file"
|
||||||
awk -v input_file="$1" -v site_root="$MARKDOWN_SITE_ROOT" -v fallback_file="$MARKDOWN_FALLBACK_FILE" -f "$awk_dir/markdown_embed.awk" "$temp_file"
|
awk -v input_file="$1" -v site_root="$MARKDOWN_SITE_ROOT" -v fallback_file="$MARKDOWN_FALLBACK_FILE" -v script_dir="$script_dir" -f "$awk_dir/markdown_embed.awk" "$temp_file"
|
||||||
rm "$temp_file"
|
rm "$temp_file"
|
||||||
|
|||||||
Reference in New Issue
Block a user