Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
d81c512cb9 | |||
86042d597c |
@ -45,6 +45,14 @@ function replaceInline(line, result, start, end) {
|
||||
# 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)
|
||||
}
|
||||
# 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>
|
||||
while (match(line, /\[([^\]]+)\]\([^\)]+\)/)) {
|
||||
@ -96,11 +104,11 @@ function closeOne() {
|
||||
env = last()
|
||||
if (env == "ul" ) {
|
||||
# In a unordered list block, print a new item
|
||||
print "<li>" replaceInline(substr($0, 3)) "</li>"
|
||||
print "<li>" substr($0, 3) "</li>"
|
||||
} else {
|
||||
# Otherwise, init the unordered list block
|
||||
push("ul")
|
||||
print "<ul>\n<li>" replaceInline(substr($0, 3)) "</li>"
|
||||
print "<ul>\n<li>" substr($0, 3) "</li>"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,6 +116,9 @@ declare -a tests=(
|
||||
"A link to [wikipedia](https://www.wikipedia.org)"
|
||||
"<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...
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user