diff --git a/awk/markdown_embed.awk b/awk/markdown_embed.awk index 75cc2a5..67189f9 100644 --- a/awk/markdown_embed.awk +++ b/awk/markdown_embed.awk @@ -97,6 +97,23 @@ function read_file(path, out, line, rc) { 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) { t = s 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)) { local_path = resolve_local_path(src) 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) 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)) { local_path = resolve_local_path(src) if (local_path != "") { - content = read_file(local_path) + content = read_file_or_render_md(local_path, ext) if (content ~ /\n$/) sub(/\n$/, "", content) return content } @@ -238,7 +256,7 @@ function render_typed_embed(etype, src, alt, has_alt, local_path, content) { if (!is_global_url(src)) { local_path = resolve_local_path(src) 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) return content } diff --git a/markdown.sh b/markdown.sh index 9848105..1303db2 100755 --- a/markdown.sh +++ b/markdown.sh @@ -77,5 +77,5 @@ awk -f "$awk_dir/paragraphs.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_fi # Inline styles 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 -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"