Summary Files Commits Branches @commit @diff @stats
path: root / single.awk
diff options
context:
space:
mode:
1 files changed, 21 insertions, 6 deletions
-rw-r--r--single.awk27
diff --git a/single.awk b/single.awk
index f24808c..708158f 100644
--- a/single.awk
+++ b/single.awk
@@ -15,7 +15,9 @@
# [ ] Reference
# [x] Emphasis
# [x] Code
-# [ ] Images
+# [.] Images
+# [x] Inline
+# [ ] Reference
# [ ] Other
# [ ] Autolinks
# [ ] Escapes
@@ -242,8 +244,14 @@ blankline {
}
# Links
-/\[[^\]]*\]\([^)]*\)/ {
- while (match($0, /\[[^\]]*\]\(/)) {
+/!?\[[^\]]*\]\([^)]*\)/ {
+ isimg = 0
+ while (match($0, /!?\[[^\]]*\]\(/)) {
+ if (substr($0, RSTART, 1) == "!") {
+ isimg = 1
+ RSTART++
+ RLENGTH--
+ }
astart = RSTART ## astart = indexof("[")
inner_anchor = substr($0, RSTART + 1, RLENGTH - 3) ## ...[xxxxx](...)...
@@ -251,14 +259,21 @@ blankline {
match(substr($0, astart), /\]\([^)]*\)/)
aend += RLENGTH - 2 ## aend = indexof(")")
href = substr($0, astart + RSTART + 1, RLENGTH - 3) ## ...[...](xxxxx)...
+ sub(/[ \t]+/, "", href)
- title = ""
if (match(href, /"[^"]*"[ \t]*$/)) {
- title = " title=" substr(href, RSTART, RLENGTH)
+ title = substr(href, RSTART, RLENGTH)
href = substr(href, 1, RSTART - 1)
}
+ else {
+ title = "\"\""
+ }
+
+ if (isimg) elem = "<img src=\"" href "\" alt=\"" inner_anchor "\" title=" title ">"
+ else elem = "<a href=\"" href "\" title=" title ">" inner_anchor "</a>"
- $0 = substr($0, 1, astart - 1) "<a href=\"" href "\"" title ">" inner_anchor "</a>" substr($0, aend + 1)
+ $0 = substr($0, 1, astart - 1 - isimg) elem substr($0, aend + 1)
+ isimg = 0
}
}