Compare commits

..

2 Commits
master ... dev

Author SHA1 Message Date
d81c512cb9 adding a test for inline code parsing
All checks were successful
continuous-integration/drone/push Build is passing
2024-12-09 15:25:28 +00:00
86042d597c addint backticks for inline code parsing 2024-12-09 15:25:16 +00:00
2 changed files with 13 additions and 2 deletions

View File

@ -45,6 +45,14 @@ function replaceInline(line, result, start, end) {
# Build the result: before match, <em>, content, </em>, after match # Build the result: before match, <em>, content, </em>, after match
line = substr(line, 1, start-1) "<em>" substr(line, start+1, RLENGTH-2) "</em>" substr(line, end+1) line = substr(line, 1, start-1) "<em>" substr(line, start+1, RLENGTH-2) "</em>" substr(line, end+1)
} }
# Replace occurrences of `...` with <code>...</code>
while (match(line, /`([^`]+)`/)) {
start = RSTART
end = RSTART + RLENGTH - 1
# Build the result: before match, <em>, content, </em>, after match
line = substr(line, 1, start-1) "<code>" substr(line, start+1, RLENGTH-2) "</code>" substr(line, end+1)
}
# Replace occurances of [link](url) with <a href="url">link</<a> # Replace occurances of [link](url) with <a href="url">link</<a>
while (match(line, /\[([^\]]+)\]\([^\)]+\)/)) { while (match(line, /\[([^\]]+)\]\([^\)]+\)/)) {
@ -96,11 +104,11 @@ function closeOne() {
env = last() env = last()
if (env == "ul" ) { if (env == "ul" ) {
# In a unordered list block, print a new item # In a unordered list block, print a new item
print "<li>" replaceInline(substr($0, 3)) "</li>" print "<li>" substr($0, 3) "</li>"
} else { } else {
# Otherwise, init the unordered list block # Otherwise, init the unordered list block
push("ul") push("ul")
print "<ul>\n<li>" replaceInline(substr($0, 3)) "</li>" print "<ul>\n<li>" substr($0, 3) "</li>"
} }
} }

View File

@ -116,6 +116,9 @@ declare -a tests=(
"A link to [wikipedia](https://www.wikipedia.org)" "A link to [wikipedia](https://www.wikipedia.org)"
"<p>A link to <a href=\"https://www.wikipedia.org\">wikipedia</a></p>" "<p>A link to <a href=\"https://www.wikipedia.org\">wikipedia</a></p>"
"Inline code"
"A simple function \`printf()\`"
"<p>A simple function <code>printf()</code></p>"
# You can add more test cases following the same format... # You can add more test cases following the same format...
) )