diff options
| Commit | 3e59aced00958cc7d7b7f6b582ed46e91b01bfca (patch) | |
|---|---|---|
| Author | 2024-12-31 19:10:22 +0200 | |
| Committer | 2024-12-31 19:10:51 +0200 | |
| Files | 4c4f5c832f09109b9625c1dbb5ce565283b4a56a | |
| csg-3e59aced00958cc7d7b7f6b582ed46e91b01bfca.tar csg-3e59aced00958cc7d7b7f6b582ed46e91b01bfca.tar.gz csg-3e59aced00958cc7d7b7f6b582ed46e91b01bfca.zip | ||
| Parent | fba9f8e29140547ebefaed7bec15173cb8c7d800 (diff) | |
feat(single): Implement autolinks
1 files changed, 35 insertions, 2 deletions
| -rw-r--r-- | single.awk | 37 |
@@ -18,8 +18,8 @@ # [x] Images # [x] Inline # [x] Reference -# [ ] Other -# [ ] Autolinks +# [.] Other +# [x] Autolinks # [ ] Escapes # # [ ] Non-standard features @@ -72,6 +72,15 @@ function restore_match() { RLENGTH = backup_rlength } +BEGIN { + ## This is used to convert email autolinks into a series of hex values + ## Escaped output of: awk 'BEGIN {for (i = 32; i <= 126; ++i){ printf("%c", i) } }' + ascii = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" + for (i = 1; i < 97; ++i) { + char_to_dec[char(ascii, i)] = 31 + i + } +} + { not_paragraph_p1 = not_paragraph not_paragraph = 0 @@ -95,6 +104,30 @@ function restore_match() { next } +# Automatic links +/<[^ \t<>]+>/ { + ## URL: <uri_scheme:...> + while (match($0, /<[A-Za-z][-A-Za-z0-9+.]*:[^ \t<>]+>/)) { + href = substr($0, RSTART + 1, RLENGTH - 2) + sub_match("<a href=\"" href "\">" href "</a>") + } + + ## Email addresses, with support for quoted local part "..."@... + ## and ip address literal ...@[...] + while (match($0, /<([^ \t<>]+|".+")@([-A-Za-z0-9]+\.[^ \t<>]+|\[[0-9A-Fa-f.:]+\])>/)) { + href = substr($0, RSTART + 1, RLENGTH - 2) + href_masked = "" + ## The original markdown blogpost calls for convertions of all + ## email characters into their hex values. Allegedly, this fools + ## many autoharvesting spam bots. + for (i = length(href); i > 0; --i) { + href_masked = sprintf("&#x%X;", char_to_dec[char(href, i)]) href_masked + } + ## href="mailto:..." + sub_match("<a href=\"mailto:" href_masked "\">" href_masked "</a>") + } +} + # Blockquotes blockquote_level > 0 && empty0 { for (P1 = P1 ORS; blockquote_level > 0; --blockquote_level) { |
