| 1 |
|
| #ifndef ESHU_HL_H |
| 2 |
|
| #define ESHU_HL_H |
| 3 |
|
| |
| 4 |
|
| #include "eshu_hl_util.h" |
| 5 |
|
| #include "eshu_c.h" |
| 6 |
|
| #include "eshu_pod.h" |
| 7 |
|
| #include "eshu_pl.h" |
| 8 |
|
| #include "eshu_xs.h" |
| 9 |
|
| #include "eshu_js.h" |
| 10 |
|
| #include "eshu_xml.h" |
| 11 |
|
| #include "eshu_css.h" |
| 12 |
|
| #include "eshu_diff.h" |
| 13 |
|
| #include "eshu_bash.h" |
| 14 |
|
| #include "eshu_go.h" |
| 15 |
|
| #include "eshu_py.h" |
| 16 |
|
| #include "eshu_json.h" |
| 17 |
|
| #include "eshu_java.h" |
| 18 |
|
| #include "eshu_lua.h" |
| 19 |
|
| #include "eshu_rust.h" |
| 20 |
|
| #include "eshu_php.h" |
| 21 |
|
| #include "eshu_ruby.h" |
| 22 |
|
| #include "eshu_ts.h" |
| 23 |
|
| #include "eshu_sql.h" |
| 24 |
|
| #include "eshu_yaml.h" |
| 25 |
|
| |
| 26 |
|
| /* ══════════════════════════════════════════════════════════════════ |
| 27 |
|
| * Dispatch: eshu_highlight(src, src_len, lang, out_len) |
| 28 |
|
| * ══════════════════════════════════════════════════════════════════ */ |
| 29 |
|
| |
| 30 |
498 |
| static char *eshu_highlight(const char *src, size_t src_len, |
| 31 |
|
| const char *lang, size_t *out_len) { |
| 32 |
498 |
▶ | if (!src || !src_len) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!src || !src_len) { |
498 |
0 |
498 |
| if (!src || !src_len) { |
0 |
498 |
498 |
|
| 33 |
0 |
| char *empty = (char *)malloc(1); |
| 34 |
0 |
▶ | if (empty) empty[0] = '\0'; |
Branch: 1 branch
| Branch | True | False | Total |
| if (empty) empty[0] = '\0'; |
0 |
0 |
0 |
|
| 35 |
0 |
| *out_len = 0; |
| 36 |
0 |
| return empty; |
| 37 |
|
| } |
| 38 |
|
| |
| 39 |
498 |
▶ | if (!lang || strcmp(lang, "c") == 0 || strcmp(lang, "h") == 0) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!lang || strcmp(lang, "c") == 0 || strcmp(lang, "h") == 0) |
498 |
0 |
498 |
| if (!lang || strcmp(lang, "c") == 0 || strcmp(lang, "h") == 0) |
442 |
56 |
498 |
| if (!lang || strcmp(lang, "c") == 0 || strcmp(lang, "h") == 0) |
1 |
441 |
442 |
|
| 40 |
57 |
| return eshu_highlight_c(src, src_len, out_len); |
| 41 |
|
| |
| 42 |
441 |
▶ | if (strcmp(lang, "xs") == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (strcmp(lang, "xs") == 0) |
0 |
441 |
441 |
|
| 43 |
0 |
| return eshu_highlight_c(src, src_len, out_len); /* XS is C-like */ |
| 44 |
|
| |
| 45 |
441 |
▶ | if (strcmp(lang, "perl") == 0 || strcmp(lang, "pl") == 0 || |
Branch: 2 branches
| Branch | True | False | Total |
| if (strcmp(lang, "perl") == 0 || strcmp(lang, "pl") == 0 || |
373 |
68 |
441 |
| if (strcmp(lang, "perl") == 0 || strcmp(lang, "pl") == 0 || |
373 |
0 |
373 |
|
| 46 |
373 |
▶ | strcmp(lang, "pm") == 0 || strcmp(lang, "t") == 0) |
Branch: 2 branches
| Branch | True | False | Total |
| strcmp(lang, "pm") == 0 || strcmp(lang, "t") == 0) |
373 |
0 |
373 |
| strcmp(lang, "pm") == 0 || strcmp(lang, "t") == 0) |
0 |
373 |
373 |
|
| 47 |
68 |
| return eshu_highlight_pl(src, src_len, out_len); |
| 48 |
|
| |
| 49 |
373 |
▶ | if (strcmp(lang, "js") == 0 || strcmp(lang, "javascript") == 0 || |
Branch: 2 branches
| Branch | True | False | Total |
| if (strcmp(lang, "js") == 0 || strcmp(lang, "javascript") == 0 || |
320 |
53 |
373 |
| if (strcmp(lang, "js") == 0 || strcmp(lang, "javascript") == 0 || |
319 |
1 |
320 |
|
| 50 |
319 |
▶ | strcmp(lang, "jsx") == 0 || strcmp(lang, "mjs") == 0 || |
Branch: 2 branches
| Branch | True | False | Total |
| strcmp(lang, "jsx") == 0 || strcmp(lang, "mjs") == 0 || |
318 |
1 |
319 |
| strcmp(lang, "jsx") == 0 || strcmp(lang, "mjs") == 0 || |
318 |
0 |
318 |
|
| 51 |
318 |
▶ | strcmp(lang, "cjs") == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| strcmp(lang, "cjs") == 0) |
0 |
318 |
318 |
|
| 52 |
55 |
| return eshu_highlight_js(src, src_len, out_len); |
| 53 |
|
| |
| 54 |
318 |
▶ | if (strcmp(lang, "ts") == 0 || strcmp(lang, "typescript") == 0 || |
Branch: 2 branches
| Branch | True | False | Total |
| if (strcmp(lang, "ts") == 0 || strcmp(lang, "typescript") == 0 || |
318 |
0 |
318 |
| if (strcmp(lang, "ts") == 0 || strcmp(lang, "typescript") == 0 || |
317 |
1 |
318 |
|
| 55 |
317 |
▶ | strcmp(lang, "tsx") == 0 || strcmp(lang, "mts") == 0) |
Branch: 2 branches
| Branch | True | False | Total |
| strcmp(lang, "tsx") == 0 || strcmp(lang, "mts") == 0) |
316 |
1 |
317 |
| strcmp(lang, "tsx") == 0 || strcmp(lang, "mts") == 0) |
1 |
315 |
316 |
|
| 56 |
3 |
| return eshu_highlight_ts(src, src_len, out_len); |
| 57 |
|
| |
| 58 |
315 |
▶ | if (strcmp(lang, "css") == 0 || strcmp(lang, "scss") == 0 || |
Branch: 2 branches
| Branch | True | False | Total |
| if (strcmp(lang, "css") == 0 || strcmp(lang, "scss") == 0 || |
275 |
40 |
315 |
| if (strcmp(lang, "css") == 0 || strcmp(lang, "scss") == 0 || |
274 |
1 |
275 |
|
| 59 |
274 |
▶ | strcmp(lang, "less") == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| strcmp(lang, "less") == 0) |
1 |
273 |
274 |
|
| 60 |
42 |
| return eshu_highlight_css(src, src_len, out_len); |
| 61 |
|
| |
| 62 |
273 |
▶ | if (strcmp(lang, "xml") == 0 || strcmp(lang, "html") == 0 || |
Branch: 2 branches
| Branch | True | False | Total |
| if (strcmp(lang, "xml") == 0 || strcmp(lang, "html") == 0 || |
247 |
26 |
273 |
| if (strcmp(lang, "xml") == 0 || strcmp(lang, "html") == 0 || |
236 |
11 |
247 |
|
| 63 |
236 |
▶ | strcmp(lang, "htm") == 0 || strcmp(lang, "svg") == 0 || |
Branch: 2 branches
| Branch | True | False | Total |
| strcmp(lang, "htm") == 0 || strcmp(lang, "svg") == 0 || |
235 |
1 |
236 |
| strcmp(lang, "htm") == 0 || strcmp(lang, "svg") == 0 || |
234 |
1 |
235 |
|
| 64 |
234 |
▶ | strcmp(lang, "xhtml") == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| strcmp(lang, "xhtml") == 0) |
1 |
233 |
234 |
|
| 65 |
40 |
| return eshu_highlight_xml(src, src_len, out_len); |
| 66 |
|
| |
| 67 |
233 |
▶ | if (strcmp(lang, "pod") == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (strcmp(lang, "pod") == 0) |
36 |
197 |
233 |
|
| 68 |
36 |
| return eshu_highlight_pod(src, src_len, out_len); |
| 69 |
|
| |
| 70 |
197 |
▶ | if (strcmp(lang, "python") == 0 || strcmp(lang, "py") == 0) |
Branch: 2 branches
| Branch | True | False | Total |
| if (strcmp(lang, "python") == 0 || strcmp(lang, "py") == 0) |
135 |
62 |
197 |
| if (strcmp(lang, "python") == 0 || strcmp(lang, "py") == 0) |
1 |
134 |
135 |
|
| 71 |
63 |
| return eshu_highlight_py(src, src_len, out_len); |
| 72 |
|
| |
| 73 |
134 |
▶ | if (strcmp(lang, "json") == 0 || strcmp(lang, "jsonc") == 0) |
Branch: 2 branches
| Branch | True | False | Total |
| if (strcmp(lang, "json") == 0 || strcmp(lang, "jsonc") == 0) |
105 |
29 |
134 |
| if (strcmp(lang, "json") == 0 || strcmp(lang, "jsonc") == 0) |
6 |
99 |
105 |
|
| 74 |
35 |
| return eshu_highlight_json(src, src_len, out_len); |
| 75 |
|
| |
| 76 |
99 |
▶ | if (strcmp(lang, "bash") == 0 || strcmp(lang, "sh") == 0 || |
Branch: 2 branches
| Branch | True | False | Total |
| if (strcmp(lang, "bash") == 0 || strcmp(lang, "sh") == 0 || |
98 |
1 |
99 |
| if (strcmp(lang, "bash") == 0 || strcmp(lang, "sh") == 0 || |
97 |
1 |
98 |
|
| 77 |
97 |
▶ | strcmp(lang, "shell") == 0 || strcmp(lang, "zsh") == 0 || |
Branch: 2 branches
| Branch | True | False | Total |
| strcmp(lang, "shell") == 0 || strcmp(lang, "zsh") == 0 || |
96 |
1 |
97 |
| strcmp(lang, "shell") == 0 || strcmp(lang, "zsh") == 0 || |
95 |
1 |
96 |
|
| 78 |
95 |
▶ | strcmp(lang, "ksh") == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| strcmp(lang, "ksh") == 0) |
0 |
95 |
95 |
|
| 79 |
4 |
| return eshu_highlight_bash(src, src_len, out_len); |
| 80 |
|
| |
| 81 |
95 |
▶ | if (strcmp(lang, "go") == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (strcmp(lang, "go") == 0) |
1 |
94 |
95 |
|
| 82 |
1 |
| return eshu_highlight_go(src, src_len, out_len); |
| 83 |
|
| |
| 84 |
94 |
▶ | if (strcmp(lang, "rust") == 0 || strcmp(lang, "rs") == 0) |
Branch: 2 branches
| Branch | True | False | Total |
| if (strcmp(lang, "rust") == 0 || strcmp(lang, "rs") == 0) |
94 |
0 |
94 |
| if (strcmp(lang, "rust") == 0 || strcmp(lang, "rs") == 0) |
0 |
94 |
94 |
|
| 85 |
0 |
| return eshu_highlight_rust(src, src_len, out_len); |
| 86 |
|
| |
| 87 |
94 |
▶ | if (strcmp(lang, "java") == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (strcmp(lang, "java") == 0) |
52 |
42 |
94 |
|
| 88 |
52 |
| return eshu_highlight_java(src, src_len, out_len); |
| 89 |
|
| |
| 90 |
42 |
▶ | if (strcmp(lang, "lua") == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (strcmp(lang, "lua") == 0) |
41 |
1 |
42 |
|
| 91 |
41 |
| return eshu_highlight_lua(src, src_len, out_len); |
| 92 |
|
| |
| 93 |
1 |
▶ | if (strcmp(lang, "php") == 0 || strcmp(lang, "phtml") == 0 || |
Branch: 2 branches
| Branch | True | False | Total |
| if (strcmp(lang, "php") == 0 || strcmp(lang, "phtml") == 0 || |
0 |
1 |
1 |
| if (strcmp(lang, "php") == 0 || strcmp(lang, "phtml") == 0 || |
0 |
0 |
0 |
|
| 94 |
0 |
▶ | strcmp(lang, "php3") == 0 || strcmp(lang, "php4") == 0 || |
Branch: 2 branches
| Branch | True | False | Total |
| strcmp(lang, "php3") == 0 || strcmp(lang, "php4") == 0 || |
0 |
0 |
0 |
| strcmp(lang, "php3") == 0 || strcmp(lang, "php4") == 0 || |
0 |
0 |
0 |
|
| 95 |
0 |
▶ | strcmp(lang, "php5") == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| strcmp(lang, "php5") == 0) |
0 |
0 |
0 |
|
| 96 |
1 |
| return eshu_highlight_php(src, src_len, out_len); |
| 97 |
|
| |
| 98 |
0 |
▶ | if (strcmp(lang, "ruby") == 0 || strcmp(lang, "rb") == 0 || |
Branch: 2 branches
| Branch | True | False | Total |
| if (strcmp(lang, "ruby") == 0 || strcmp(lang, "rb") == 0 || |
0 |
0 |
0 |
| if (strcmp(lang, "ruby") == 0 || strcmp(lang, "rb") == 0 || |
0 |
0 |
0 |
|
| 99 |
0 |
▶ | strcmp(lang, "rake") == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| strcmp(lang, "rake") == 0) |
0 |
0 |
0 |
|
| 100 |
0 |
| return eshu_highlight_ruby(src, src_len, out_len); |
| 101 |
|
| |
| 102 |
0 |
▶ | if (strcmp(lang, "sql") == 0 || strcmp(lang, "psql") == 0 || |
Branch: 2 branches
| Branch | True | False | Total |
| if (strcmp(lang, "sql") == 0 || strcmp(lang, "psql") == 0 || |
0 |
0 |
0 |
| if (strcmp(lang, "sql") == 0 || strcmp(lang, "psql") == 0 || |
0 |
0 |
0 |
|
| 103 |
0 |
▶ | strcmp(lang, "ddl") == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| strcmp(lang, "ddl") == 0) |
0 |
0 |
0 |
|
| 104 |
0 |
| return eshu_highlight_sql(src, src_len, out_len); |
| 105 |
|
| |
| 106 |
0 |
▶ | if (strcmp(lang, "yaml") == 0 || strcmp(lang, "yml") == 0) |
Branch: 2 branches
| Branch | True | False | Total |
| if (strcmp(lang, "yaml") == 0 || strcmp(lang, "yml") == 0) |
0 |
0 |
0 |
| if (strcmp(lang, "yaml") == 0 || strcmp(lang, "yml") == 0) |
0 |
0 |
0 |
|
| 107 |
0 |
| return eshu_highlight_yaml(src, src_len, out_len); |
| 108 |
|
| |
| 109 |
|
| /* unknown language: HTML-escape only, no spans */ |
| 110 |
|
| { |
| 111 |
|
| eshu_buf_t out; |
| 112 |
0 |
| eshu_buf_init(&out, src_len + 16); |
| 113 |
0 |
| eshu_hl_write_html(&out, src, src_len); |
| 114 |
0 |
| eshu_buf_putc(&out, '\0'); |
| 115 |
0 |
| *out_len = out.len - 1; |
| 116 |
0 |
| return out.data; |
| 117 |
|
| } |
| 118 |
|
| } |
| 119 |
|
| |
| 120 |
|
| #endif /* ESHU_HL_H */ |