diff options
| Commit | c67dd619cc887371a989105d517ab5715049cf9c (patch) | |
|---|---|---|
| Author | 2024-07-23 17:45:47 +0300 | |
| Committer | 2024-07-23 17:45:47 +0300 | |
| Files | 72d308415eef3a112fadf72ce5b64daee1e15023 /single.awk | |
| csg-c67dd619cc887371a989105d517ab5715049cf9c.tar csg-c67dd619cc887371a989105d517ab5715049cf9c.tar.gz csg-c67dd619cc887371a989105d517ab5715049cf9c.zip | ||
| Parent | 0c33b774ae37c9aaf64cdd6aa85b26c526a14192 (diff) | |
(single) Implemented inline images
1 files changed, 21 insertions, 6 deletions
| -rw-r--r-- | single.awk | 27 |
@@ -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 } } |
