parsing link
This commit is contained in:
parent
95fd30239e
commit
9c703e5afe
@ -29,7 +29,7 @@ function last() {
|
||||
return stack[stack_pointer]
|
||||
}
|
||||
|
||||
function replaceEmAndStrong(line, result, start, end) {
|
||||
function replaceInline(line, result, start, end) {
|
||||
# Replace occurrences of **...** with <strong>...</strong>
|
||||
while (match(line, /\*\*([^*]+)\*\*/)) {
|
||||
start = RSTART
|
||||
@ -46,6 +46,20 @@ function replaceEmAndStrong(line, result, start, end) {
|
||||
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
|
||||
}
|
||||
|
||||
@ -124,7 +138,7 @@ function closeOne() {
|
||||
env = last()
|
||||
if (env == "none") {
|
||||
# If no block, print a paragraph
|
||||
print "<p>" replaceEmAndStrong($0) "</p>"
|
||||
print "<p>" replaceInline($0) "</p>"
|
||||
} else if (env == "blockquote") {
|
||||
print $0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user