diff options
| author | katalx | 2026-02-02 05:27:17 -0500 |
|---|---|---|
| committer | katalx | 2026-02-02 05:27:17 -0500 |
| commit | 9737033c1a2fccc8a4c0b031e27f7514e49e8d4b (patch) | |
| tree | 89e79f9645f0d10adbc8d550fc2e3d812254f145 | |
| parent | 0079fba20988051a99f552f99efea06705932489 (diff) | |
try to detect URLs in plaintext documents
| -rw-r--r-- | main.c | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -277,7 +277,19 @@ parse_linewise(Doc *d, int (*fn)(Doc *, Str)) { int parse_text_line(Doc *d, Str s) { - doc_push_line(d, s); + DocLine *l = doc_push_line(d, s); + Str f = str_find(s, S("://")); + if (f.n > 0) { + int i = f.s - s.s; + while (i > 0 && !is_space(s.s[i])) + i--; + while (i < s.n && is_space(s.s[i])) + i++; + int j = i; + while (i < s.n && !is_space(s.s[j])) + j++; + doc_link(d, l, (Str) { s.s + i, j - i }); + } return 0; } |
