From 75fa01d9724ce0377808884a2161b1dd3055bbca Mon Sep 17 00:00:00 2001 From: simonpetit Date: Wed, 29 Jan 2025 11:04:02 +0000 Subject: [PATCH] adding inline code processing --- lib/markdown.awk | 9 ++++++++- test/parser/test_md_parser.sh | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/markdown.awk b/lib/markdown.awk index e66a068..ac66d06 100755 --- a/lib/markdown.awk +++ b/lib/markdown.awk @@ -61,6 +61,13 @@ function replaceInline(line, result, start, end) { line = substr(line, 1, start-1) "" matched_link "" substr(line, end+1) } + # Replace occurences of `...` with ... + while (match(line, /`(.+)`/)) { + start = RSTART + end = RSTART + RLENGTH - 1 + line = substr(line, 1, start-1) "" substr(line, start+1, RLENGTH-2) "" substr(line, end+1) + } + return line } @@ -135,7 +142,7 @@ function closeOne() { # Matching a simple paragraph -!/^(#|\*|-|\+|>|`|$|\t| )/ { +!/^(#|\*|-|\+|>|$|\t| )/ { env = last() if (env == "none") { # If no block, print a paragraph diff --git a/test/parser/test_md_parser.sh b/test/parser/test_md_parser.sh index 18873a7..c4d6430 100755 --- a/test/parser/test_md_parser.sh +++ b/test/parser/test_md_parser.sh @@ -116,6 +116,10 @@ declare -a tests=( "A link to [wikipedia](https://www.wikipedia.org)" "

A link to wikipedia

" + "Inline code" + $'`a code block`' + "

a code block

" + # You can add more test cases following the same format... )