Compare commits
3 Commits
95fd30239e
...
dc591b29bb
Author | SHA1 | Date | |
---|---|---|---|
dc591b29bb | |||
6441bfdc78 | |||
9c703e5afe |
2
bob
2
bob
@ -79,10 +79,10 @@ update_index()
|
|||||||
|
|
||||||
publish()
|
publish()
|
||||||
{
|
{
|
||||||
|
|
||||||
post=$(awk -f ${BOB_LIB}/markdown.awk ./drafts/$1.md)
|
post=$(awk -f ${BOB_LIB}/markdown.awk ./drafts/$1.md)
|
||||||
template="${BOB_LIB}/template/post.html"
|
template="${BOB_LIB}/template/post.html"
|
||||||
escaped_post=$(echo "$post" | sed 's/&/\\&/g')
|
escaped_post=$(echo "$post" | sed 's/&/\\&/g')
|
||||||
# awk -v content="$post" '{gsub(/{{article}}/, content); print}' "$template" > "./posts/$1.html"
|
|
||||||
awk -v content="$escaped_post" '{gsub(/\{\{article\}\}/, content); print}' "$template" > "./posts/$1.html"
|
awk -v content="$escaped_post" '{gsub(/\{\{article\}\}/, content); print}' "$template" > "./posts/$1.html"
|
||||||
mv ./drafts/$1.md ./drafts/published/$1.md
|
mv ./drafts/$1.md ./drafts/published/$1.md
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ function last() {
|
|||||||
return stack[stack_pointer]
|
return stack[stack_pointer]
|
||||||
}
|
}
|
||||||
|
|
||||||
function replaceEmAndStrong(line, result, start, end) {
|
function replaceInline(line, result, start, end) {
|
||||||
# Replace occurrences of **...** with <strong>...</strong>
|
# Replace occurrences of **...** with <strong>...</strong>
|
||||||
while (match(line, /\*\*([^*]+)\*\*/)) {
|
while (match(line, /\*\*([^*]+)\*\*/)) {
|
||||||
start = RSTART
|
start = RSTART
|
||||||
@ -45,6 +45,20 @@ function replaceEmAndStrong(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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (match(line, /\[([^\]]+)\]\([^\)]+\)/)) {
|
||||||
|
start = RSTART
|
||||||
|
end = RSTART + RLENGTH - 1
|
||||||
|
matched = substr($0, RSTART, RLENGTH)
|
||||||
|
if (match(matched, /\[([^\]]+)\]/)) {
|
||||||
|
matched_link = substr(matched, RSTART+1, RLENGTH-2)
|
||||||
|
}
|
||||||
|
if (match(matched, /\([^\)]+\)/)) {
|
||||||
|
matched_url = substr(matched, RSTART+1, RLENGTH-2)
|
||||||
|
}
|
||||||
|
# Build the result: before match, <a href="url">, content, </a>, after match
|
||||||
|
line = substr(line, 1, start-1) "<a href=\"" matched_url "\">" matched_link "</a>" substr(line, end+1)
|
||||||
|
}
|
||||||
|
|
||||||
return line
|
return line
|
||||||
}
|
}
|
||||||
@ -124,7 +138,7 @@ function closeOne() {
|
|||||||
env = last()
|
env = last()
|
||||||
if (env == "none") {
|
if (env == "none") {
|
||||||
# If no block, print a paragraph
|
# If no block, print a paragraph
|
||||||
print "<p>" replaceEmAndStrong($0) "</p>"
|
print "<p>" replaceInline($0) "</p>"
|
||||||
} else if (env == "blockquote") {
|
} else if (env == "blockquote") {
|
||||||
print $0
|
print $0
|
||||||
}
|
}
|
||||||
@ -147,4 +161,4 @@ END {
|
|||||||
print "</" env ">"
|
print "</" env ">"
|
||||||
env = last()
|
env = last()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,11 @@ declare -a tests=(
|
|||||||
$'First paragraph\n\n code1\n code2\n\nSecond paragraph'
|
$'First paragraph\n\n code1\n code2\n\nSecond paragraph'
|
||||||
"<p>First paragraph</p><pre><code>code1code2</code></pre><p>Second paragraph</p>"
|
"<p>First paragraph</p><pre><code>code1code2</code></pre><p>Second paragraph</p>"
|
||||||
|
|
||||||
|
"Link 1"
|
||||||
|
"This is a [link](https://www.google.com) to google"
|
||||||
|
"<p>This is a <a href=\"https://www.google.com\">link</a> to google</p>"
|
||||||
|
|
||||||
|
|
||||||
# You can add more test cases following the same format...
|
# You can add more test cases following the same format...
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -154,4 +159,4 @@ for ((i = 0; i < num_tests; i++)); do
|
|||||||
STATUS=$((STATUS+STATUS_i))
|
STATUS=$((STATUS+STATUS_i))
|
||||||
done
|
done
|
||||||
|
|
||||||
exit $STATUS
|
exit $STATUS
|
||||||
|
Loading…
Reference in New Issue
Block a user