From 1fe56d26aebf6213e9a0a6f964b6068397a9bcb5 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 28 Apr 2023 10:10:27 +0300 Subject: [styles] Reworked colors for syntax highlighting --- src/darkmode.css | 45 +++++++++++++++++---------- src/styles.css | 95 ++++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 96 insertions(+), 44 deletions(-) diff --git a/src/darkmode.css b/src/darkmode.css index 7a8ad3a..59aaffc 100644 --- a/src/darkmode.css +++ b/src/darkmode.css @@ -2,23 +2,34 @@ --bg-color: #262626; --fg-color: #ffeede; - --a-color: #cd81a7; - --a-hover-color: #eeaacd; - --accent-line-color: #d47408; - --alternating-row-color: #353535; - --bg-selection-color: #81949f; - --blockquote-color: #919191; - --blockquote-border-color: #919191; - --body-bg: #000000; - --border-color: #777; - --code-bg-color: #414141; - --em-color: #e17b08; - --fg-selection-color: #001121; - --header-color: #d49408; - --pre-bg-color: #414141; - --strong-color: #c35b5b; - --table-border-color: #777; - --tr-bg-color: #262626; + --a-color: #cd81a7; + --a-hover-color: #eeaacd; + --accent-line-color: #d47408; + --alternating-row-color: #353535; + --bg-selection-color: #81949f; + --blockquote-color: #919191; + --blockquote-border-color: var(--blockquote-color); + --body-bg: #000000; + --border-color: #777; + --code-bg-color: #414141; + --em-color: #e17b08; + --fg-selection-color: #001121; + --header-color: #d49408; + --pre-bg-color: #414141; + --strong-color: #c35b5b; + --table-border-color: var(--border-color); + --tr-bg-color: var(--bg-color); + + /* https://github.com/morhetz/gruvbox/blob/master/autoload/gruvbox.vim */ + --hi-fg: #fbf1c7; + --hi-bg: #1d2021; + --hic-gray: #928374; + --hic-red: #fb4934; + --hic-green: #b8bb26; + --hic-yellow: #fabd2f; + --hic-purple: #d3869b; + --hic-aqua: #8ec07c; + --hic-orange: #fe8019; } /* This selects the link images, next to headings */ diff --git a/src/styles.css b/src/styles.css index b24a355..fd6feea 100644 --- a/src/styles.css +++ b/src/styles.css @@ -55,23 +55,54 @@ --bg-color: white; --fg-color: black; - --a-color: #336700; - --a-hover-color: #3ea100; - --accent-line-color: #004080; - --alternating-row-color: #eef0f2; - --bg-selection-color: #338fff; - --blockquote-color: #6a737d; + --a-color: #336700; + --a-hover-color: #3ea100; + --accent-line-color: #004080; + --alternating-row-color: #eef0f2; + --bg-selection-color: #338fff; + --blockquote-color: #6a737d; --blockquote-border-color: #dfe2e5; - --body-bg: #dbdbdb; - --border-color: black; - --code-bg-color: #e2e4e6; - --em-color: black; - --fg-selection-color: white; - --header-color: #006b8f; - --pre-bg-color: #f6f8fa; - --strong-color: black; - --table-border-color: black; - --tr-bg-color: #fff; + --body-bg: #dbdbdb; + --border-color: black; + --code-bg-color: #e2e4e6; + --em-color: black; + --fg-selection-color: white; + --header-color: #006b8f; + --pre-bg-color: #f6f8fa; + --strong-color: black; + --table-border-color: black; + --tr-bg-color: white; + + /* https://github.com/morhetz/gruvbox/blob/master/autoload/gruvbox.vim */ + --hi-fg: #282828; + --hi-bg: #f9f5d7; + --hic-gray: #928374; + --hic-red: #fb4934; + --hic-green: #79740e; + --hic-yellow: #b57614; + --hic-purple: #8f3f71; + --hic-aqua: #427b58; + --hic-orange: #af3a03; + + --hi-comment: var(--hic-gray); + --hi-const: var(--hic-purple); + --hi-string: var(--hic-green); + --hi-char: var(--hic-purple); + --hi-number: var(--hic-purple); + --hi-bool: var(--hic-purple); + --hi-float: var(--hic-purple); + --hi-function: var(--hic-green); + --hi-statement: var(--hic-red); + --hi-conditional: var(--hic-red); + --hi-repeat: var(--hic-red); + --hi-operator: var(--hi-fg); + --hi-keyword: var(--hic-red); /* Label and Exception are keywords */ + --hi-preproc: var(--hic-aqua); + --hi-type: var(--hic-yellow); + --hi-storageclass: var(--hic-orange); + --hi-structure: var(--hic-aqua); + --hi-typedef: var(--hic-aqua); + --hi-ignore: var(--hi-fg); } /* Global */ @@ -471,14 +502,24 @@ dt { font-size: 1.2em; } padding: 0.2em 0 0.2em 0.2em !important; } -/* Syntax highlighting (colours are inspired from gruvbox) */ - -/* Constant, Chars */ .SH-cst, .SH-chr { color: #d787af; } -/* Comment */ .SH-com { color: #8a8a8a; } -/* Keyword */ .SH-kwd { color: #d75f5f; } -/* Second keyword color */ .SH-kwd2 { color: #ff8700; } -/* Third keyword color */ .SH-kwd3 { color: #87af87; } -/* Type */ .SH-typ { color: #ffaf00; } -/* Class */ .SH-cls { color: #87afaf; } -/* Function names, Strings */ :not(.SH-cls) > .SH-fnc, .SH-str { color: #afaf00; } -.SH-none { color: var(--fg-color); } +/* Syntax highlighting */ + +.HI-comment { color: var(--hic-gray); } +.HI-const { color: var(--hic-purple); } +.HI-string { color: var(--hic-green); } +.HI-char { color: var(--hic-purple); } +.HI-number { color: var(--hic-purple); } +.HI-bool { color: var(--hic-purple); } +.HI-float { color: var(--hic-purple); } +.HI-function { color: var(--hic-green); } +.HI-statement { color: var(--hic-red); } +.HI-conditional { color: var(--hic-red); } +.HI-repeat { color: var(--hic-red); } +.HI-operator { color: var(--fg-color); } +.HI-keyword { color: var(--hic-red); /* Label and Exception are keywords */ } +.HI-preproc { color: var(--hic-aqua); } +.HI-type { color: var(--hic-yellow); } +.HI-storageclass { color: var(--hic-orange); } +.HI-structure { color: var(--hic-aqua); } +.HI-typedef { color: var(--hic-aqua); } +.HI-ignore { color: var(--fg-color); } -- cgit v1.3.1-26-gb76a From 0dc8cafa2f8c32d2ad9dd0da4edd5b23b9114dbf Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 28 Apr 2023 10:20:34 +0300 Subject: [Syntax-highlighting] Ported grammars and regexes to new colors --- awk-edits/Syntax-highlighting.awk | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/awk-edits/Syntax-highlighting.awk b/awk-edits/Syntax-highlighting.awk index e3a9be2..0a0a0d4 100644 --- a/awk-edits/Syntax-highlighting.awk +++ b/awk-edits/Syntax-highlighting.awk @@ -17,6 +17,13 @@ BEGIN { syntaxhighlighting=0; } +function hi(pat, class) { + gsub(pat, "&"); +} +function hie(pat, epat, class) { + return gesub(pat, epat, "&"); +} + # # -- Grammars -- # @@ -58,10 +65,10 @@ syntaxhighlighting == 1 { } for (i = 1; i <= grammarNamesI; i++) { - $0 = gesub(grammarNames[i], "]*>[^<]*]*>", "&"); + $0 = hie(grammarNames[i], "]*>[^<]*]*>", "function"); } - gsub(/[[:blank:]]*[^-\\]->/, "&"); - gsub(/\|/, "&"); + hi("->", "statement"); + hi("\\|", "statement"); } # @@ -76,11 +83,11 @@ syntaxhighlighting == 0 && /class="language-regex"/ { syntaxhighlighting == 2 { syntaxhighlighting = 2; - gsub(/[\*]/, "&"); - gsub(/[\(\)\|]/, "&"); + hi("\\*", "repeat"); + hi("[\\(\\)\\|]", "statement"); } -# +# # -- Bash # # Supports "bash" @@ -97,11 +104,12 @@ syntaxhighlighting == 2 { } syntaxhighlighting == 3 { - gsub(/("[^"]*"|'[^']*')/, "&"); - gsub(/\$(\(|\(\(|{).+(\)|\)\)|})/, "&"); - gsub(/\$[^[:blank:]]+/, "&"); + hi("(\"[^\"]*\"|'[^']*')", "string"); + hi("\\$(\\(|\\(\\(|{).+(\\)|\\)\\)|})", "structure"); + hi("\\$[^[:blank:]]+", "structure"); gsub(/[[:blank:]]+-[-_[:alnum:]]+/, "&"); - gsub(/(^|[[:blank:]]+)(function|if|fi|then|case|esac|in|disown|==|!=|-eq|-ne|-gt|-ge|-lt|-le|;|\|\||&&)($|[[:blank:]])/, "&"); + hi("(^|[[:blank:]]+)(if|fi|then|case|esac|==|!=|-eq|-ne|-gt|-ge|-lt|-le|;|\\|\\||&&)($|[[:blank:]])", "conditional"); + hi("(^|[[:blank:]]+)(for|while|until|in|do|done)($|[[:blank:]])", "repeat"); gsub(/^[[:blank:]]*[[:alnum:]]+=/, "&"); gsub(/[-_[:alnum:]]+[[:blank:]]*\([^\)]*\)/, "&"); gsub(/[\{\}]/, "&"); -- cgit v1.3.1-26-gb76a From 62b4b87aa877119f22c600bdbae5197effd37ad7 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 28 Apr 2023 16:12:07 +0300 Subject: [Syntax-highlighting] Replaced some string regexes to strong regexp constants --- awk-edits/Syntax-highlighting.awk | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/awk-edits/Syntax-highlighting.awk b/awk-edits/Syntax-highlighting.awk index 0a0a0d4..0c96eef 100644 --- a/awk-edits/Syntax-highlighting.awk +++ b/awk-edits/Syntax-highlighting.awk @@ -104,12 +104,12 @@ syntaxhighlighting == 2 { } syntaxhighlighting == 3 { - hi("(\"[^\"]*\"|'[^']*')", "string"); - hi("\\$(\\(|\\(\\(|{).+(\\)|\\)\\)|})", "structure"); - hi("\\$[^[:blank:]]+", "structure"); + hi(@/("[^"]*"|'[^']*')/, "string"); + hi(@/\$(\(|\(\(|{).+(\)|\)\)|})/, "structure"); + hi(@/\$[^[:blank:]]+/, "structure"); gsub(/[[:blank:]]+-[-_[:alnum:]]+/, "&"); - hi("(^|[[:blank:]]+)(if|fi|then|case|esac|==|!=|-eq|-ne|-gt|-ge|-lt|-le|;|\\|\\||&&)($|[[:blank:]])", "conditional"); - hi("(^|[[:blank:]]+)(for|while|until|in|do|done)($|[[:blank:]])", "repeat"); + hi(@/(^|[[:blank:]]+)(if|fi|then|case|esac|==|!=|-eq|-ne|-gt|-ge|-lt|-le|;|\|\||&&)($|[[:blank:]])/, "conditional"); + hi(@/(^|[[:blank:]]+)(for|while|until|in|do|done)($|[[:blank:]])/, "repeat"); gsub(/^[[:blank:]]*[[:alnum:]]+=/, "&"); gsub(/[-_[:alnum:]]+[[:blank:]]*\([^\)]*\)/, "&"); gsub(/[\{\}]/, "&"); -- cgit v1.3.1-26-gb76a From 973c5dcaaa0273a4050cff5e81b2ef14262bc39d Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 28 Apr 2023 23:24:20 +0300 Subject: [styles] Added hi-identifier and hic-blue, fixed .HI classes being hardcoded with colors, rather than the appropriate varaibles --- src/darkmode.css | 1 + src/styles.css | 41 ++++++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/darkmode.css b/src/darkmode.css index 59aaffc..11eadf7 100644 --- a/src/darkmode.css +++ b/src/darkmode.css @@ -26,6 +26,7 @@ --hic-gray: #928374; --hic-red: #fb4934; --hic-green: #b8bb26; + --hic-blue: #83a598; --hic-yellow: #fabd2f; --hic-purple: #d3869b; --hic-aqua: #8ec07c; diff --git a/src/styles.css b/src/styles.css index fd6feea..3674502 100644 --- a/src/styles.css +++ b/src/styles.css @@ -79,6 +79,7 @@ --hic-gray: #928374; --hic-red: #fb4934; --hic-green: #79740e; + --hic-blue: #076678; --hic-yellow: #b57614; --hic-purple: #8f3f71; --hic-aqua: #427b58; @@ -91,6 +92,7 @@ --hi-number: var(--hic-purple); --hi-bool: var(--hic-purple); --hi-float: var(--hic-purple); + --hi-identifier: var(--hic-blue); --hi-function: var(--hic-green); --hi-statement: var(--hic-red); --hi-conditional: var(--hic-red); @@ -504,22 +506,23 @@ dt { font-size: 1.2em; } /* Syntax highlighting */ -.HI-comment { color: var(--hic-gray); } -.HI-const { color: var(--hic-purple); } -.HI-string { color: var(--hic-green); } -.HI-char { color: var(--hic-purple); } -.HI-number { color: var(--hic-purple); } -.HI-bool { color: var(--hic-purple); } -.HI-float { color: var(--hic-purple); } -.HI-function { color: var(--hic-green); } -.HI-statement { color: var(--hic-red); } -.HI-conditional { color: var(--hic-red); } -.HI-repeat { color: var(--hic-red); } -.HI-operator { color: var(--fg-color); } -.HI-keyword { color: var(--hic-red); /* Label and Exception are keywords */ } -.HI-preproc { color: var(--hic-aqua); } -.HI-type { color: var(--hic-yellow); } -.HI-storageclass { color: var(--hic-orange); } -.HI-structure { color: var(--hic-aqua); } -.HI-typedef { color: var(--hic-aqua); } -.HI-ignore { color: var(--fg-color); } +.HI-comment { color: var(--hi-comment); } +.HI-const { color: var(--hi-const); } +.HI-string { color: var(--hi-string); } +.HI-char { color: var(--hi-char); } +.HI-number { color: var(--hi-number); } +.HI-bool { color: var(--hi-bool); } +.HI-float { color: var(--hi-float); } +.HI-identifier { color: var(--hi-identifier); } +.HI-function { color: var(--hi-function); } +.HI-statement { color: var(--hi-statement); } +.HI-conditional { color: var(--hi-conditional); } +.HI-repeat { color: var(--hi-repeat); } +.HI-operator { color: var(--hi-operator); } +.HI-keyword { color: var(--hi-keyword); /* Label and Exception are keywords */ } +.HI-preproc { color: var(--hi-preproc); } +.HI-type { color: var(--hi-type); } +.HI-storageclass { color: var(--hi-storageclass); } +.HI-structure { color: var(--hi-structure); } +.HI-typedef { color: var(--hi-typedef); } +.HI-ignore { color: var(--hi-ignore); } -- cgit v1.3.1-26-gb76a From eff5393a6c45a02cd0c703c62fac52b6c7733307 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 28 Apr 2023 23:24:59 +0300 Subject: [Syntax-highlighting] Added UNFINISHED support for lookaround --- awk-edits/#strings.awk | 32 ++++++++++++++++++++++++++++++++ awk-edits/Syntax-highlighting.awk | 26 ++++++++++++++------------ 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/awk-edits/#strings.awk b/awk-edits/#strings.awk index a34757e..cc469e8 100644 --- a/awk-edits/#strings.awk +++ b/awk-edits/#strings.awk @@ -43,3 +43,35 @@ function gesub(regexp, exregexp, replacement, target) { return result target; } + +# glsub(lbregexp, regexp, largexp, replacement [, empt, target]) +# Aka global sub with non-capturing look-around (lookbehind and lookahead) +function glsub(lbregexp, regexp, laregexp, replacement, empt, target) { + if (!length(target)) { + target = $0; + } + if (empt >= 2) { + RSTART = 1; + RLENGTH = 0; + empt -= 2; + } + + result = ""; + subst = ""; + while ((RSTART == 1 && RLENGTH == 0 && length(result) == 0) || match(target, lbregexp)) { + result = result substr(target, 1, RSTART + RLENGTH - 1); + target = substr(target, RSTART + RLENGTH); + match(target, regexp); + if (RSTART == 1) { + subst = substr(target, RSTART, RLENGTH); + target = substr(target, RSTART + RLENGTH); + match(target, laregexp); + if ((empt == 1 && length(target) == 0) || RSTART == 1) { + sub(/.*/, replacement, subst); + } + result = result subst; + } + } + + return result target; +} diff --git a/awk-edits/Syntax-highlighting.awk b/awk-edits/Syntax-highlighting.awk index 0c96eef..1655e8e 100644 --- a/awk-edits/Syntax-highlighting.awk +++ b/awk-edits/Syntax-highlighting.awk @@ -23,6 +23,9 @@ function hi(pat, class) { function hie(pat, epat, class) { return gesub(pat, epat, "&"); } +function hil(lbpat, pat, lrpat, empt, class) { + return glsub(lbpat, pat, lrpat, "&", empt); +} # # -- Grammars -- @@ -65,10 +68,10 @@ syntaxhighlighting == 1 { } for (i = 1; i <= grammarNamesI; i++) { - $0 = hie(grammarNames[i], "]*>[^<]*]*>", "function"); + $0 = hie(grammarNames[i], @/]*>[^<]*<\/[^>]*>/, "function"); } - hi("->", "statement"); - hi("\\|", "statement"); + hi(@/->/, "statement"); + hi(@/\|/, "statement"); } # @@ -83,8 +86,8 @@ syntaxhighlighting == 0 && /class="language-regex"/ { syntaxhighlighting == 2 { syntaxhighlighting = 2; - hi("\\*", "repeat"); - hi("[\\(\\)\\|]", "statement"); + hi(@/\*/, "repeat"); + hi(@/[\(\)\|]/, "statement"); } # @@ -107,14 +110,13 @@ syntaxhighlighting == 3 { hi(@/("[^"]*"|'[^']*')/, "string"); hi(@/\$(\(|\(\(|{).+(\)|\)\)|})/, "structure"); hi(@/\$[^[:blank:]]+/, "structure"); - gsub(/[[:blank:]]+-[-_[:alnum:]]+/, "&"); - hi(@/(^|[[:blank:]]+)(if|fi|then|case|esac|==|!=|-eq|-ne|-gt|-ge|-lt|-le|;|\|\||&&)($|[[:blank:]])/, "conditional"); + # gsub(/[[:blank:]]+-[-_[:alnum:]]+/, "&"); + $0 = hil(@/[^[:alnum:]]/, @/(if|fi|then|case|esac|==|!=|-eq|-ne|-gt|-ge|-lt|-le|;;|;|\|\||&&)/, @/[^[:alnum:]]/, 3, "conditional"); hi(@/(^|[[:blank:]]+)(for|while|until|in|do|done)($|[[:blank:]])/, "repeat"); - gsub(/^[[:blank:]]*[[:alnum:]]+=/, "&"); - gsub(/[-_[:alnum:]]+[[:blank:]]*\([^\)]*\)/, "&"); - gsub(/[\{\}]/, "&"); - gsub(/[[:blank:]]#.*$/, "&"); - gsub(/(\|)/, "&"); + $0 = hil(@/[[:blank:]]*/, @/[[:alnum:]]+/, @/=/, 0, "identifier"); + # $0 = hil("", @/[-_[:alnum:]]+[[:blank:]]*/, @/\([^\)]*\)/, 0, "function"); + hi(@/[\{\}]/, "function"); + # $0 = hil(@/[^\>]/, @/#.*$/, "", 0, "comment"); } # -- cgit v1.3.1-26-gb76a From 0d04ad2871d29dc0c733b0454e3ec44133850c83 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 29 Apr 2023 11:20:01 +0300 Subject: [#strings] Made glsub work --- awk-edits/#strings.awk | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/awk-edits/#strings.awk b/awk-edits/#strings.awk index cc469e8..6972105 100644 --- a/awk-edits/#strings.awk +++ b/awk-edits/#strings.awk @@ -46,32 +46,33 @@ function gesub(regexp, exregexp, replacement, target) { # glsub(lbregexp, regexp, largexp, replacement [, empt, target]) # Aka global sub with non-capturing look-around (lookbehind and lookahead) -function glsub(lbregexp, regexp, laregexp, replacement, empt, target) { +function glsub(lbregexp, regexp, laregexp, replacement, target) { if (!length(target)) { target = $0; } - if (empt >= 2) { - RSTART = 1; - RLENGTH = 0; - empt -= 2; - } - result = ""; - subst = ""; - while ((RSTART == 1 && RLENGTH == 0 && length(result) == 0) || match(target, lbregexp)) { - result = result substr(target, 1, RSTART + RLENGTH - 1); - target = substr(target, RSTART + RLENGTH); - match(target, regexp); - if (RSTART == 1) { - subst = substr(target, RSTART, RLENGTH); - target = substr(target, RSTART + RLENGTH); - match(target, laregexp); - if ((empt == 1 && length(target) == 0) || RSTART == 1) { - sub(/.*/, replacement, subst); - } - result = result subst; + surlen = split(target, surrounds, lbregexp regexp laregexp); + result = surrounds[1]; + # POSIX compliance, seps parameter in split isn't available + target = substr(target, length(surrounds[1]) + 1); + for (i = 2; i <= surlen; i++) { + if (surrounds[i] == "") { + si = length(target) + 1; + } + else { + si = index(target, surrounds[i]); } + csep = substr(target, 1, si - 1); + target = substr(target, length(surrounds[i]) + si); + + match(csep, regexp); + behind = substr(csep, 1, RSTART - 1); + ahead = substr(csep, RSTART + RLENGTH); + csep = substr(csep, RSTART, RLENGTH); + + sub(/.*/, replacement, csep); + result = result behind csep ahead surrounds[i]; } - return result target; + return result; } -- cgit v1.3.1-26-gb76a From 256745e04194ec60d3d3069909afdef85e060d35 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 29 Apr 2023 11:20:30 +0300 Subject: [Syntax-highlighting] Ported all of bash regexes --- awk-edits/Syntax-highlighting.awk | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/awk-edits/Syntax-highlighting.awk b/awk-edits/Syntax-highlighting.awk index 1655e8e..caec9cf 100644 --- a/awk-edits/Syntax-highlighting.awk +++ b/awk-edits/Syntax-highlighting.awk @@ -23,8 +23,8 @@ function hi(pat, class) { function hie(pat, epat, class) { return gesub(pat, epat, "&"); } -function hil(lbpat, pat, lrpat, empt, class) { - return glsub(lbpat, pat, lrpat, "&", empt); +function hil(lbpat, pat, lrpat, class) { + return glsub(lbpat, pat, lrpat, "&"); } # @@ -107,16 +107,33 @@ syntaxhighlighting == 2 { } syntaxhighlighting == 3 { + $0 = gesub(@/=/, "<[^>]*>", "\\="); hi(@/("[^"]*"|'[^']*')/, "string"); + $0 = hil(@/[^\>&]/, + @/#.*$/, + "", + "comment"); + $0 = hil(@/[^[:alpha:]#]/, + @/[[:digit:]]+/, + @/([^[:alpha:];]|$)/, + "number"); hi(@/\$(\(|\(\(|{).+(\)|\)\)|})/, "structure"); hi(@/\$[^[:blank:]]+/, "structure"); - # gsub(/[[:blank:]]+-[-_[:alnum:]]+/, "&"); - $0 = hil(@/[^[:alnum:]]/, @/(if|fi|then|case|esac|==|!=|-eq|-ne|-gt|-ge|-lt|-le|;;|;|\|\||&&)/, @/[^[:alnum:]]/, 3, "conditional"); + $0 = hil(@/[[:blank:]]+/, @/-[-_[:alnum:]]+/, "", "operator"); + $0 = hil(@/(^|[^[:alnum:]])/, + @/(if|fi|then|case|esac|==|!=|-eq|-ne|-gt|-ge|-lt|-le|;;|;|\|\||&&)/, + @/([^[:alnum:]]|$)/, + "conditional"); hi(@/(^|[[:blank:]]+)(for|while|until|in|do|done)($|[[:blank:]])/, "repeat"); - $0 = hil(@/[[:blank:]]*/, @/[[:alnum:]]+/, @/=/, 0, "identifier"); - # $0 = hil("", @/[-_[:alnum:]]+[[:blank:]]*/, @/\([^\)]*\)/, 0, "function"); + $0 = hil(@/(^|[[:blank:]]+)/, + @/[[:alnum:]]+/, + @/(|\+|-)=/, + "identifier"); + $0 = hil("", + @/[-_[:alnum:]]+[[:blank:]]*/, + @/\([^\)]*\)/, + "function"); hi(@/[\{\}]/, "function"); - # $0 = hil(@/[^\>]/, @/#.*$/, "", 0, "comment"); } # -- cgit v1.3.1-26-gb76a From 2e39a9a44f11e6989565fc0d832f67c335c67873 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 29 Apr 2023 11:40:10 +0300 Subject: [#strings/glsub] Fixed bad behaviour when regexp matches next to each other (and lbregexp regexp largexep doesn't match longer) --- awk-edits/#strings.awk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/awk-edits/#strings.awk b/awk-edits/#strings.awk index 6972105..074e42a 100644 --- a/awk-edits/#strings.awk +++ b/awk-edits/#strings.awk @@ -57,7 +57,8 @@ function glsub(lbregexp, regexp, laregexp, replacement, target) { target = substr(target, length(surrounds[1]) + 1); for (i = 2; i <= surlen; i++) { if (surrounds[i] == "") { - si = length(target) + 1; + match(target, lbregexp regexp laregxep); + si = RLENGTH + 1; } else { si = index(target, surrounds[i]); -- cgit v1.3.1-26-gb76a From 1b3a0d2e11c8d317bb474e02cb2a8cd5534060a9 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 29 Apr 2023 11:41:30 +0300 Subject: [Syntax-highlighting/bash] Fixed floating point number and added a default highlighting for arbitrary commands --- awk-edits/Syntax-highlighting.awk | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/awk-edits/Syntax-highlighting.awk b/awk-edits/Syntax-highlighting.awk index caec9cf..2cd63f3 100644 --- a/awk-edits/Syntax-highlighting.awk +++ b/awk-edits/Syntax-highlighting.awk @@ -113,12 +113,12 @@ syntaxhighlighting == 3 { @/#.*$/, "", "comment"); - $0 = hil(@/[^[:alpha:]#]/, - @/[[:digit:]]+/, + hi(@/\$(\(|\(\(|{).+(\)|\)\)|})/, "structure"); + hi(@/\$[[:alnum:]]+/, "structure"); + $0 = hil(@/[^[:alpha:]#\$]/, + @/[[:digit:]]+(|\.[[:digit:]]+)/, @/([^[:alpha:];]|$)/, "number"); - hi(@/\$(\(|\(\(|{).+(\)|\)\)|})/, "structure"); - hi(@/\$[^[:blank:]]+/, "structure"); $0 = hil(@/[[:blank:]]+/, @/-[-_[:alnum:]]+/, "", "operator"); $0 = hil(@/(^|[^[:alnum:]])/, @/(if|fi|then|case|esac|==|!=|-eq|-ne|-gt|-ge|-lt|-le|;;|;|\|\||&&)/, @@ -134,6 +134,7 @@ syntaxhighlighting == 3 { @/\([^\)]*\)/, "function"); hi(@/[\{\}]/, "function"); + hi(@/^[[:blank:]]*[[:alnum:]]+/, "statement"); } # -- cgit v1.3.1-26-gb76a From a269cf3861e0f45c814348bb2223bb4054630c5c Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 29 Apr 2023 12:36:30 +0300 Subject: [styles] Fixed horizontal scrolling in code blocks not having a padding to the right --- src/styles.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/styles.css b/src/styles.css index 3674502..2781999 100644 --- a/src/styles.css +++ b/src/styles.css @@ -235,7 +235,7 @@ code, pre { } pre code { border: 0; - display: inline; + display: inline-block; overflow: visible; padding: 0; word-wrap: normal; -- cgit v1.3.1-26-gb76a From 719ee10187ec83183fb24ed85470ab3ee4d9b32c Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 29 Apr 2023 12:41:34 +0300 Subject: [styles] Fixed line height inconsistency in code blocks --- src/styles.css | 1 - 1 file changed, 1 deletion(-) diff --git a/src/styles.css b/src/styles.css index 2781999..6173c5e 100644 --- a/src/styles.css +++ b/src/styles.css @@ -220,7 +220,6 @@ h1, h2, h3, h4, h5, h6, b { code, pre { background-color: var(--pre-bg-color); font-family: monospace; - line-height: 1em; } pre { overflow: auto; -- cgit v1.3.1-26-gb76a From d56a29ed6dffe6ba047ddbb8b36c909357b2a8a8 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 29 Apr 2023 14:03:27 +0300 Subject: [Syntax-highlighting] Mostly implemented C and C++ --- awk-edits/Syntax-highlighting.awk | 101 ++++++++++++++++++++++++++++---------- 1 file changed, 76 insertions(+), 25 deletions(-) diff --git a/awk-edits/Syntax-highlighting.awk b/awk-edits/Syntax-highlighting.awk index 2cd63f3..35fd1f3 100644 --- a/awk-edits/Syntax-highlighting.awk +++ b/awk-edits/Syntax-highlighting.awk @@ -27,6 +27,14 @@ function hil(lbpat, pat, lrpat, class) { return glsub(lbpat, pat, lrpat, "&"); } +# +# -- Global -- +# + +syntaxhighlighting > 0 || /class="language-/ { + $0 = gesub(@/=/, "<[^>]*>", "\\="); +} + # # -- Grammars -- # @@ -107,24 +115,30 @@ syntaxhighlighting == 2 { } syntaxhighlighting == 3 { - $0 = gesub(@/=/, "<[^>]*>", "\\="); - hi(@/("[^"]*"|'[^']*')/, "string"); + $0 = hie(@/"[^"]*"/, "<[^>]*>", "string"); $0 = hil(@/[^\>&]/, @/#.*$/, "", "comment"); hi(@/\$(\(|\(\(|{).+(\)|\)\)|})/, "structure"); hi(@/\$[[:alnum:]]+/, "structure"); - $0 = hil(@/[^[:alpha:]#\$]/, - @/[[:digit:]]+(|\.[[:digit:]]+)/, - @/([^[:alpha:];]|$)/, + $0 = hil(@/[^[:alnum:]#\$]/, + @/[[:digit:]]+/, + @/[^[:alnum:]]/, "number"); + $0 = hil(@/[^[:alnum:]#\$]/, + @/[[:digit:]]+\.[[:digit:]]+/, + @/[^[:alnum:]]/, + "float"); $0 = hil(@/[[:blank:]]+/, @/-[-_[:alnum:]]+/, "", "operator"); $0 = hil(@/(^|[^[:alnum:]])/, @/(if|fi|then|case|esac|==|!=|-eq|-ne|-gt|-ge|-lt|-le|;;|;|\|\||&&)/, @/([^[:alnum:]]|$)/, "conditional"); - hi(@/(^|[[:blank:]]+)(for|while|until|in|do|done)($|[[:blank:]])/, "repeat"); + $0 = hil(@/(^|[^[:alnum:]])/, + @/(for|while|until|in|do|done)/, + @/([^[:alnum:]]|$)/, + "repeat"); $0 = hil(@/(^|[[:blank:]]+)/, @/[[:alnum:]]+/, @/(|\+|-)=/, @@ -137,26 +151,10 @@ syntaxhighlighting == 3 { hi(@/^[[:blank:]]*[[:alnum:]]+/, "statement"); } + # -# -- C -- +# -- C-like programming languages -- # -# Supports "c" and is used in C-like programming languages - -/class="language-c"/ { - syntaxhighlighting = 100; -} - -syntaxhighlighting >= 100 { - gsub(/([[:alnum:]]|[-_])+(<[[:alnum:]]+>)?\(/, "&"); - gsub(/(//.*|/*.*/)/, "&"); - gsub(/[\(,\.]/, "&"); - gsub(/(public|protected|private|override|new|if|else|while|for|return|struct|typedef|extern|const)[[:blank:]]/, "&"); - gsub(/(&&|\|\||==|!=)/, "&"); - gsub(/#(include|if|ifndef|endif|define)/, "&"); - gsub(/(true|false)[[:blank:]]/, "&"); - gsub(/(int|void|double|bool|char)[[:blank:]]/, "&"); - $0 = gesub("(\"[^\"]*\"|'[^']*')", "<[^>]*>", "&"); -} # # -- C++ -- @@ -168,7 +166,10 @@ syntaxhighlighting >= 100 { } syntaxhighlighting == 101 { - gsub(/([[:blank:]]|\()*[[:upper:]]([[:upper:]]|[-_])*([[:blank:]]|\)|,|;)+/, "&"); + $0 = hil(@/(^|[^[:alnum:]])/, + @/(string)/, + @/([^[:alnum:]]|$)/, + "type"); } # @@ -213,6 +214,56 @@ syntaxhighlighting == 104 { gsub(/%[^[:blank:]]+/, "&"); } +# +# -- C -- +# +# Supports "c" and is used in C-like programming languages + +/class="language-c"/ { + syntaxhighlighting = 100; +} + +syntaxhighlighting >= 100 { + $0 = hie(@/"[^"]*"/, "<[^>]*>", "string"); + hi(@/(//.*$|/\*.*$|^.*\*/)/, "comment"); + $0 = hil(@/[^[:alnum:]#\$]/, + @/[[:digit:]]+/, + @/[^[:alnum:]]/, + "number"); + $0 = hil(@/[^[:alnum:]#\$]/, + @/[[:digit:]]+\.[[:digit:]]+/, + @/[^[:alnum:]]/, + "float"); + $0 = hil("", + @/[-_[:alnum:]]+/, + @/[[:blank:]]*(|\+|-|\*|/|%|<<|>>|&|\^|\|)=/, + "identifier"); + $0 = hil("", + @/[-_[:alnum:]]+[[:blank:]]*/, + @/\(/, + "function"); + hi(@/(==|!=|<|>|<=|>=|&&|\|\||!)/, "conditional"); + $0 = hil(@/(^|[^[:alnum:]])/, + @/(break|continue|do|for|goto|while)/, + @/([^[:alnum:]]|$)/, + "repeat"); + $0 = hil(@/(^|[^[:alnum:]])/, + @/(case|const|default|else|extern|if|return|sizeof|switch|typedef)/, + @/([^[:alnum:]]|$)/, + "keyword"); + hi(@/^[[:blank:]]*#[[:alpha:]]+/, "preproc"); + $0 = hil(@/(^|[^[:alnum:]])/, + @/(auto|char|double|float|int|long|short|signed|unsigned|bool)/, + @/([^[:alnum:]]|$)/, + "type"); + hi(@/'[\\]?[ -~]'/, "char"); + hi(@/(true|false)/, "bool"); + $0 = hil(@/(^|[^[:alnum:]])/, + @/(enum|struct|union)/, + @/([^[:alnum:]]|$)/, + "storageclass"); +} + tagend != 0 { $0 = prestart $0; tagend = 0; -- cgit v1.3.1-26-gb76a From e3655a70a6b2ccaabb0a8a531f0c5d7aa3de0adf Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 29 Apr 2023 15:06:24 +0300 Subject: [#strings/glsub] Fixed typo --- awk-edits/#strings.awk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awk-edits/#strings.awk b/awk-edits/#strings.awk index 074e42a..5e486bb 100644 --- a/awk-edits/#strings.awk +++ b/awk-edits/#strings.awk @@ -57,7 +57,7 @@ function glsub(lbregexp, regexp, laregexp, replacement, target) { target = substr(target, length(surrounds[1]) + 1); for (i = 2; i <= surlen; i++) { if (surrounds[i] == "") { - match(target, lbregexp regexp laregxep); + match(target, lbregexp regexp laregexp); si = RLENGTH + 1; } else { -- cgit v1.3.1-26-gb76a From e5be7ac510d900ee81a55d4c71eec228872d5457 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 29 Apr 2023 15:06:42 +0300 Subject: [Syntax-highlighting] Ported lex and yacc, tweaked C --- awk-edits/Syntax-highlighting.awk | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/awk-edits/Syntax-highlighting.awk b/awk-edits/Syntax-highlighting.awk index 35fd1f3..0e5250e 100644 --- a/awk-edits/Syntax-highlighting.awk +++ b/awk-edits/Syntax-highlighting.awk @@ -182,10 +182,12 @@ syntaxhighlighting == 101 { } syntaxhighlighting == 102 { - gsub(/new ([[:alnum:]]|[-_])+[\(\.]/, "&"); - gsub(/(<[[:alnum:]]+>)/, "&"); - gsub(/([[:blank:]]|\()*([[:upper:]]|[-_])+([[:blank:]]|\)|,|;)+/, "&"); - gsub(/(=>)/, "&"); + $0 = hil(@/(^|[^[:alnum:]])/, + @/(new|public|protected|private|override)/, + @/([^[:alnum:]]|$)/, + "keyword"); + hi(@/<[-_[:alpha:]]+>/, "typedef"); + $0 = hie(@/[_[:upper:]][_[:upper:]][_[:upper:]][_[:upper:]]+/, @/<[^>]*>/, "const"); } # @@ -198,7 +200,7 @@ syntaxhighlighting == 102 { } syntaxhighlighting == 103 { - gsub(/%[^[:blank:]]+/, "&"); + hi(@/%[^[:blank:]]+/, "storageclass"); } # @@ -211,7 +213,7 @@ syntaxhighlighting == 103 { } syntaxhighlighting == 104 { - gsub(/%[^[:blank:]]+/, "&"); + hi(@/%[^[:blank:]]+/, "storageclass"); } # @@ -225,7 +227,7 @@ syntaxhighlighting == 104 { syntaxhighlighting >= 100 { $0 = hie(@/"[^"]*"/, "<[^>]*>", "string"); - hi(@/(//.*$|/\*.*$|^.*\*/)/, "comment"); + hi(@/(//.*$|/\*.*$|^[^\*]*\*/)/, "comment"); $0 = hil(@/[^[:alnum:]#\$]/, @/[[:digit:]]+/, @/[^[:alnum:]]/, @@ -242,18 +244,21 @@ syntaxhighlighting >= 100 { @/[-_[:alnum:]]+[[:blank:]]*/, @/\(/, "function"); - hi(@/(==|!=|<|>|<=|>=|&&|\|\||!)/, "conditional"); - $0 = hil(@/(^|[^[:alnum:]])/, + hi(@/(==|!=|<=|>=|&&|\|\||!)/, "conditional"); + $0 = hil(@/(^|[^-[:alnum:]])/, @/(break|continue|do|for|goto|while)/, @/([^[:alnum:]]|$)/, "repeat"); - $0 = hil(@/(^|[^[:alnum:]])/, + $0 = hil(@/(^|[^-[:alnum:]])/, @/(case|const|default|else|extern|if|return|sizeof|switch|typedef)/, @/([^[:alnum:]]|$)/, "keyword"); - hi(@/^[[:blank:]]*#[[:alpha:]]+/, "preproc"); - $0 = hil(@/(^|[^[:alnum:]])/, - @/(auto|char|double|float|int|long|short|signed|unsigned|bool)/, + $0 = hil(@/(^|<.*>)[[:blank:]]*/, + @/#[[:alpha:]]+/, + "", + "preproc"); + $0 = hil(@/(^|[^-[:alnum:]])/, + @/(auto|char|double|float|int|long|short|signed|unsigned|bool|void)/, @/([^[:alnum:]]|$)/, "type"); hi(@/'[\\]?[ -~]'/, "char"); -- cgit v1.3.1-26-gb76a From a9f641a6ec9d70ab4d78f6280ede0d5e64c3d50c Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 29 Apr 2023 15:21:32 +0300 Subject: [#strings/glsub] Added documentation --- awk-edits/#strings.awk | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/awk-edits/#strings.awk b/awk-edits/#strings.awk index 5e486bb..3365df2 100644 --- a/awk-edits/#strings.awk +++ b/awk-edits/#strings.awk @@ -44,8 +44,14 @@ function gesub(regexp, exregexp, replacement, target) { return result target; } -# glsub(lbregexp, regexp, largexp, replacement [, empt, target]) +# glsub(lbregexp, regexp, largexp, replacement [, target]) # Aka global sub with non-capturing look-around (lookbehind and lookahead) +# Behaves kind of like gsub, however substitution of regexp with replacement +# only happens, when regexp is preceded by lbregexp and succeeded by laregexp. +# Only regexp get's replaced, the matches of lbregexp and laregexp are left +# as-is. Overlapping of any form isn't supported. +# This function is quite slow, try to use as little as possible. +# Returns the result string, rather than doing it inplace. function glsub(lbregexp, regexp, laregexp, replacement, target) { if (!length(target)) { target = $0; -- cgit v1.3.1-26-gb76a