diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2025-05-31 19:42:16 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2025-05-31 19:42:16 +0530 |
commit | 2afd85294fcbbca71118e9f870e56b53d6af9954 (patch) | |
tree | 5855d619fa11a6185eb4e677efe8e6e9216285ac |
-rw-r--r-- | README.md | 56 | ||||
-rw-r--r-- | cgit.css | 1041 | ||||
-rw-r--r-- | md2html | 317 | ||||
-rw-r--r-- | syntax-highlighting.py | 62 |
4 files changed, 1476 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..5329062 --- /dev/null +++ b/README.md @@ -0,0 +1,56 @@ +# Catppuccin theme for cgit + +This theme brings the Catppuccin color palette to cgit. It also makes some very +slight UI changes to cgit itself. The theme can be seen in action on this +website itself, and can be easily ported to other colorschemes too. + +Syntax highlighting (with pygments) and markdown styling (with syntax +highlighting inside the code blocks) is also supported. + +# Usage + +## Website styling + +Move `cgit.css` to `/usr/share/cgit/cgit.css` on your server. Also make sure +your `/etc/cgitrc` has this: + +``` fish +css=/cgit.css +``` + +Uncomment one of the theme variants at the top of the `cgit.css` file, and +set `--accent-color` to your preferred accent color. + +## Syntax highlighting + +Install `catppuccin[pygments]` from pip (along with other dependencies as +defined in cgit's manual). Place `syntax-highlighting.py` at +`/usr/lib/cgit/filters/syntax-highlighting.py` + +Find these lines in `syntax-highlighting.py`: + +``` py +from catppuccin.extras.pygments import MochaStyle + +# ... + +formatter = HtmlFormatter(style=MochaStyle, nobackground=True) +``` + +And optionally replace `MochaStyle` with `LatteStyle`, `FrappeStyle` or +`MacchiatoStyle` + +## Markdown styling + +Move `md2html` to `/usr/lib/cgit/filters/html-converters/md2html` and optionally +edit these lines: + +``` py +from catppuccin.extras.pygments import MochaStyle + +# ... + +sys.stdout.write(HtmlFormatter(style=MochaStyle).get_style_defs('.highlight')) +``` + +And replace `MochaStyle` with `LatteStyle`, `FrappeStyle` or `MacchiatoStyle` diff --git a/cgit.css b/cgit.css new file mode 100644 index 0000000..35704a2 --- /dev/null +++ b/cgit.css @@ -0,0 +1,1041 @@ +/* catppuccin-latte theme */ +/* :root { + --crust: #dce0e8; + --mantle: #e6e9ef; + --base: #eff1f5; + --surface-0: #ccd0da; + --surface-1: #bcc0cc; + --surface-2: #acb0be; + --overlay-0: #9ca0b0; + --overlay-1: #8c8fa1; + --overlay-2: #7c7f93; + --subtext-0: #6c6f85; + --subtext-1: #5c5f77; + --text: #4c4f69; + --lavender: #7287fd; + --blue: #1e66f5; + --sapphire: #209fb5; + --sky: #04a5e5; + --teal: #179299; + --green: #40a02b; + --yellow: #df8e1d; + --peach: #fe640b; + --maroon: #e64553; + --red: #d20f39; + --mauve: #8839ef; + --pink: #ea76cb; + --flamingo: #dd7878; + --rosewater: #dc8a78; + + --accent-color: var(--green); +} */ + +/* catppuccin-frappe theme */ +/* :root { + --crust: #232634; + --mantle: #292c3c; + --base: #303446; + --surface-0: #414559; + --surface-1: #51576d; + --surface-2: #626880; + --overlay-0: #737994; + --overlay-1: #838ba7; + --overlay-2: #949cbb; + --subtext-0: #a5adce; + --subtext-1: #b5bfe2; + --text: #c6d0f5; + --lavender: #babbf1; + --blue: #8caaee; + --sapphire: #85c1dc; + --sky: #99d1db; + --teal: #81c8be; + --green: #a6d189; + --yellow: #e5c890; + --peach: #ef9f76; + --maroon: #ea999c; + --red: #e78284; + --mauve: #ca9ee6; + --pink: #f4b8e4; + --flamingo: #eebebe; + --rosewater: #f2d5cf; + + --accent-color: var(--green); +} */ + +/* catppuccin-macchiato theme */ +/* :root { + --crust: #181926; + --mantle: #1e2030; + --base: #24273a; + --surface-0: #363a4f; + --surface-1: #494d64; + --surface-2: #5b6078; + --overlay-0: #6e738d; + --overlay-1: #8087a2; + --overlay-2: #939ab7; + --subtext-0: #a5adcb; + --subtext-1: #b8c0e0; + --text: #cad3f5; + --lavender: #b7bdf8; + --blue: #8aadf4; + --sapphire: #7dc4e4; + --sky: #91d7e3; + --teal: #8bd5ca; + --green: #a6da95; + --yellow: #eed49f; + --peach: #f5a97f; + --maroon: #ee99a0; + --red: #ed8796; + --mauve: #c6a0f6; + --pink: #f5bde6; + --flamingo: #f0c6c6; + --rosewater: #f4dbd6; + + --accent-color: var(--green); +} */ + +/* catppuccin-mocha theme */ +:root { + --crust: #11111b; + --mantle: #181825; + --base: #1e1e2e; + --surface-0: #313244; + --surface-1: #45475a; + --surface-2: #585b70; + --overlay-0: #6c7086; + --overlay-1: #7f849c; + --overlay-2: #9399b2; + --subtext-0: #a6adc8; + --subtext-1: #bac2de; + --text: #cdd6f4; + --lavender: #b4befe; + --blue: #89b4fa; + --sapphire: #74c7ec; + --sky: #89dceb; + --teal: #94e2d5; + --green: #a6e3a1; + --yellow: #f9e2af; + --peach: #fab387; + --maroon: #eba0ac; + --red: #f38ba8; + --mauve: #cba6f7; + --pink: #f5c2e7; + --flamingo: #f2cdcd; + --rosewater: #f5e0dc; + + --accent-color: var(--green); +} + +::-moz-selection { + background: var(--accent-color); + color: var(--mantle); +} + +::selection { + background: var(--accent-color); + color: var(--mantle); +} + +body { + background-color: var(--mantle); +} + +div#cgit input, div#cgit select { + border: 1px solid var(--accent-color); + background-color: var(--crust); + color: var(--text); +} + +div#cgit { + padding: 0em; + margin: 2em 1em; + font-family: sans-serif; + font-size: 10pt; + color: var(--text); + background: var(--mantle); + padding: 4px; +} + +div#cgit a { + color: var(--accent-color); + text-decoration: none; +} + +div#cgit a:hover { + text-decoration: underline; +} + +div#cgit table { + border-collapse: collapse; +} + +div#cgit table#header { + width: 100%; + margin-bottom: 1em; +} + +div#cgit table#header td.logo { + width: 96px; + vertical-align: top; +} + +div#cgit table#header td.main { + font-size: 250%; + padding-left: 10px; + white-space: nowrap; +} + +div#cgit table#header td.main a { + color: var(--text); +} + +div#cgit table#header td.form { + text-align: right; + vertical-align: bottom; + padding-right: 1em; + padding-bottom: 2px; + white-space: nowrap; +} + +div#cgit table#header td.form form, +div#cgit table#header td.form input, +div#cgit table#header td.form select { + font-size: 90%; +} + +div#cgit table#header td.sub { + color: var(--subtext-1); + padding-left: 10px; +} + +div#cgit table.tabs { + border-bottom: solid 3px var(--accent-color); + border-collapse: collapse; + margin-top: 2em; + margin-bottom: 0px; + width: 100%; +} + +div#cgit table.tabs td { + padding: 0px 1em; + vertical-align: bottom; +} + +div#cgit table.tabs td a { + padding: 2px 0.75em; + color: var(--text); + font-size: 110%; +} + +div#cgit table.tabs td a.active { + color: var(--mantle); + background-color: var(--accent-color); +} + +div#cgit table.tabs td.form { + text-align: right; +} + +div#cgit table.tabs td.form form { + padding-bottom: 2px; + font-size: 90%; + white-space: nowrap; +} + +div#cgit table.tabs td.form input, +div#cgit table.tabs td.form select { + font-size: 90%; +} + +div#cgit div.path { + margin: 0px; + padding: 5px 2em 2px 2em; + color: var(--text); + background-color: var(--mantle); +} + +div#cgit div.content { + margin: 0px 0px 16px 0px; + padding: 2em 0em; + border-bottom: solid 2px var(--accent-color); +} + +div#cgit table.list { + width: 100%; + border: none; + border-collapse: collapse; +} + +div#cgit table.list tr { + background: var(--mantle); +} + +div#cgit table.list tr.logheader { + background: var(--mantle); +} + +div#cgit table.list tr:nth-child(even) { + background: var(--base); +} + +div#cgit table.list tr:nth-child(odd) { + background: var(--mantle); +} + +div#cgit table.list tr:hover { + background: var(--surface-0); +} + +div#cgit table.list tr.nohover { + background: var(--mantle); +} + +div#cgit table.list tr.nohover:hover { + background: var(--mantle); +} + +div#cgit table.list tr.nohover-highlight:hover:nth-child(even) { + background: var(--surface-0); +} + +kiv#cgit table.list tr.nohover-highlight:hover:nth-child(odd) { + background: var(--surface-0); +} + +div#cgit table.list th { + font-weight: bold; + background-color: var(--surface-0); + padding: 0.5em 0.5em 0.5em 0.7em; + vertical-align: baseline; +} + +div#cgit table.list td { + border: none; + padding: 0.1em 0.5em 0.1em 0.5em; +} + +div#cgit table.list td.commitgraph { + font-family: monospace; + white-space: pre; +} + +div#cgit table.list td.commitgraph .column1 { + color: var(--red); +} + +div#cgit table.list td.commitgraph .column2 { + color: var(--green); +} + +div#cgit table.list td.commitgraph .column3 { + color: var(--yellow); +} + +div#cgit table.list td.commitgraph .column4 { + color: var(--sapphire); +} + +div#cgit table.list td.commitgraph .column5 { + color: var(--pink); +} + +div#cgit table.list td.commitgraph .column6 { + color: var(--sky); +} + +div#cgit table.list td.logsubject { + font-family: monospace; + font-weight: bold; +} + +div#cgit table.list td.logmsg { + font-family: monospace; + white-space: pre; + padding: 0 0.5em; +} + +div#cgit table.list td a { + color: var(--text); +} + +div#cgit table.list td a.ls-dir { + font-weight: bold; + color: var(--text); +} + +div#cgit table.list td a:hover { + color: var(--accent-color); +} + +div#cgit img { + border: none; +} + +div#cgit input#switch-btn { + margin: 2px 0px 0px 0px; +} + +div#cgit td#sidebar input.txt { + width: 100%; + margin: 2px 0px 0px 0px; +} + +div#cgit table#grid { + margin: 0px; +} + +div#cgit td#content { + vertical-align: top; + padding: 1em 2em 1em 1em; + border: none; +} + +div#cgit div#summary { + vertical-align: top; + margin-bottom: 1em; +} + +div#cgit table#downloads { + float: right; + border-collapse: collapse; + border: solid 1px var(--accent-color); + margin-left: 0.5em; + margin-bottom: 0.5em; +} + +div#cgit table#downloads th { + background-color: var(--mantle); +} + +div#cgit div#blob { + border: solid 1px var(--overlay-1); +} + +div#cgit div.error { + color: var(--red); + font-weight: bold; + margin: 1em 2em; +} + +div#cgit a.ls-blob, div#cgit a.ls-dir, div#cgit .ls-mod { + font-family: monospace; +} + +div#cgit td.ls-size { + text-align: right; + font-family: monospace; + width: 10em; +} + +div#cgit td.ls-mode { + font-family: monospace; + width: 10em; +} + +div#cgit table.blob { + margin-top: 0.5em; + border-top: solid 1px var(--overlay-1); +} + +div#cgit table.blob td.hashes, +div#cgit table.blob td.lines { + margin: 0; padding: 0 0 0 0.5em; + vertical-align: top; + color: var(--text); +} + +div#cgit table.blob td.linenumbers { + margin: 0; padding: 0 0.5em 0 0.5em; + vertical-align: top; + text-align: right; + border-right: 1px solid var(--overlay-1); +} + +div#cgit table.blob pre { + padding: 0; margin: 0; +} + +div#cgit table.blob td.linenumbers a, +div#cgit table.ssdiff td.lineno a { + color: var(--subtext-0); + text-align: right; + text-decoration: none; +} + +div#cgit table.blob td.linenumbers a:hover, +div#cgit table.ssdiff td.lineno a:hover { + color: var(--accent-color); +} + +div#cgit table.blame td.hashes, +div#cgit table.blame td.lines, +div#cgit table.blame td.linenumbers { + padding: 0; +} + +div#cgit table.blame td.hashes div.alt, +div#cgit table.blame td.lines div.alt { + padding: 0 0.5em 0 0.5em; +} + +div#cgit table.blame td.linenumbers div.alt { + padding: 0 0.5em 0 0; +} + +div#cgit table.blame div.alt:nth-child(even) { + background: var(--crust); +} + +div#cgit table.blame div.alt:nth-child(odd) { + background: var(--mantle); +} + +div#cgit table.blame td.lines > div { + position: relative; +} + +div#cgit table.blame td.lines > div > pre { + padding: 0 0 0 0.5em; + position: absolute; + top: 0; +} + +div#cgit table.blame .oid { + font-size: 100%; +} + +div#cgit table.bin-blob { + margin-top: 0.5em; + border: solid 1px var(--overlay-0); +} + +div#cgit table.bin-blob th { + font-family: monospace; + white-space: pre; + border: solid 1px var(--overlay-0); + padding: 0.5em 1em; +} + +div#cgit table.bin-blob td { + font-family: monospace; + white-space: pre; + border-left: solid 1px var(--overlay-0); + padding: 0em 1em; +} + +div#cgit table.nowrap td { + white-space: nowrap; +} + +div#cgit table.commit-info { + border-collapse: collapse; + margin-top: 1.5em; +} + +div#cgit div.cgit-panel { + float: right; + margin-top: 1.5em; +} + +div#cgit div.cgit-panel table { + border-collapse: collapse; + border: solid 1px var(--accent-color); + background-color: var(--crust); +} + +div#cgit div.cgit-panel th { + text-align: center; +} + +div#cgit div.cgit-panel td { + padding: 0.25em 0.5em; +} + +div#cgit div.cgit-panel td.label { + padding-right: 0.5em; +} + +div#cgit div.cgit-panel td.ctrl { + padding-left: 0.5em; +} + +div#cgit table.commit-info th { + text-align: left; + font-weight: normal; + padding: 0.1em 1em 0.1em 0.1em; + vertical-align: top; +} + +div#cgit table.commit-info td { + font-weight: normal; + padding: 0.1em 1em 0.1em 0.1em; +} + +div#cgit div.commit-subject { + font-weight: bold; + font-size: 125%; + margin: 1.5em 0em 0.5em 0em; + padding: 0em; +} + +div#cgit div.commit-msg { + white-space: pre; + font-family: monospace; +} + +div#cgit div.notes-header { + font-weight: bold; + padding-top: 1.5em; +} + +div#cgit div.notes { + white-space: pre; + font-family: monospace; + border: solid 1px var(--peach); + background-color: var(--yellow); + padding: 0.3em 2em 0.3em 1em; + float: left; +} + +div#cgit div.notes-footer { + clear: left; +} + +div#cgit div.diffstat-header { + font-weight: bold; + padding-top: 1.5em; +} + +div#cgit table.diffstat { + border-collapse: collapse; + border: solid 1px var(--accent-color); + background-color: var(--crust); +} + +div#cgit table.diffstat th { + font-weight: normal; + text-align: left; + text-decoration: underline; + padding: 0.1em 1em 0.1em 0.1em; + font-size: 100%; +} + +div#cgit table.diffstat td { + padding: 0.2em 0.2em 0.1em 0.1em; + font-size: 100%; + border: none; +} + +div#cgit table.diffstat td.mode { + white-space: nowrap; +} + +div#cgit table.diffstat td span.modechange { + padding-left: 1em; + color: var(--red); +} + +div#cgit table.diffstat td.add a { + color: var(--green); +} + +div#cgit table.diffstat td.del a { + color: var(--red); +} + +div#cgit table.diffstat td.upd a { + color: var(--accent-color); +} + +div#cgit table.diffstat td.graph { + width: 500px; + vertical-align: middle; +} + +div#cgit table.diffstat td.graph table { + border: none; +} + +div#cgit table.diffstat td.graph td { + padding: 0px; + border: 0px; + height: 7pt; +} + +div#cgit table.diffstat td.graph td.add { + background-color: var(--green); +} + +div#cgit table.diffstat td.graph td.rem { + background-color: var(--maroon); +} + +div#cgit div.diffstat-summary { + color: var(--subtext-1); + padding-top: 0.5em; +} + +div#cgit table.diff { + width: 100%; +} + +div#cgit table.diff td { + font-family: monospace; + white-space: pre; +} + +div#cgit table.diff td div.head { + font-weight: bold; + margin-top: 1em; + color: var(--subtext-0); +} + +div#cgit table.diff td div.hunk { + color: var(--sapphire); +} + +div#cgit table.diff td div.add { + color: var(--green); +} + +div#cgit table.diff td div.del { + color: var(--red); +} + +div#cgit .oid { + font-family: monospace; + font-size: 90%; +} + +div#cgit .left { + text-align: left; +} + +div#cgit .right { + text-align: right; +} + +div#cgit table.list td.reposection { + font-style: italic; + color: var(--accent-color); +} + +div#cgit a.button { + font-size: 80%; + padding: 0em 0.5em; +} + +div#cgit a.primary { + font-size: 100%; +} + +div#cgit a.secondary { + font-size: 90%; +} + +div#cgit table.list td.sublevel-repo { + color: var(--text); + padding-left: 1.5em; +} + +div#cgit ul.pager { + list-style-type: none; + text-align: center; + margin: 1em 0em 0em 0em; + padding: 0; +} + +div#cgit ul.pager li { + display: inline-block; + margin: 0.25em 0.5em; +} + +div#cgit ul.pager a { + color: var(--subtext-0); +} + +div#cgit ul.pager .current { + font-weight: bold; +} + +div#cgit span.age-mins { + font-weight: bold; + color: var(--teal); +} + +div#cgit span.age-hours { + color: var(--sky); +} + +div#cgit span.age-days { + color: var(--teal); +} + +div#cgit span.age-weeks { + color: var(--green); +} + +div#cgit span.age-months { + color: var(--overlay-1); +} + +div#cgit span.age-years { + color: var(--overlay-2); +} + +div#cgit span.insertions { + color: var(--teal); +} + +div#cgit span.deletions { + color: var(--maroon); +} + +div#cgit div.footer { + margin-top: 0.5em; + text-align: center; + font-size: 80%; + color: var(--text); +} + +div#cgit div.footer a { + color: var(--accent-color); + text-decoration: none; +} + +div#cgit div.footer a:hover { + text-decoration: underline; +} + +div#cgit span.msg-avail { + color: var(--mantle); + margin: 0px 0.5em; + padding: 0px 0.25em; + background-color: var(--overlay-2); + border: solid 1px var(--overlay-0); +} + +div#cgit a.branch-deco { + color: var(--mantle) !important; + margin: 0px 0.5em; + padding: 0px 0.25em; + background-color: var(--green); + border: solid 1px var(--teal); +} + +div#cgit a.tag-deco { + color: var(--mantle) !important; + margin: 0px 0.5em; + padding: 0px 0.25em; + background-color: var(--yellow); + border: solid 1px var(--peach); +} + +div#cgit a.tag-annotated-deco { + color: var(--mantle) !important; + margin: 0px 0.5em; + padding: 0px 0.25em; + background-color: var(--peach); + border: solid 1px var(--rosewater); +} + +div#cgit a.remote-deco { + color: var(--mantle) !important; + margin: 0px 0.5em; + padding: 0px 0.25em; + background-color: var(--lavender); + border: solid 1px var(--mauve); +} + +div#cgit a.deco { + color: var(--mantle) !important; + margin: 0px 0.5em; + padding: 0px 0.25em; + background-color: var(--red); + border: solid 1px var(--maroon); +} + +div#cgit div.commit-subject a.branch-deco, +div#cgit div.commit-subject a.tag-deco, +div#cgit div.commit-subject a.tag-annotated-deco, +div#cgit div.commit-subject a.remote-deco, +div#cgit div.commit-subject a.deco { + margin-left: 1em; + font-size: 75%; +} + +div#cgit table.stats { + border: solid 1px var(--accent-color); + border-collapse: collapse; +} + +div#cgit table.stats th { + text-align: left; + padding: 1px 0.5em; + background-color: var(--mantle); + border: solid 1px var(--accent-color); +} + +div#cgit table.stats td { + text-align: right; + padding: 1px 0.5em; + border: solid 1px var(--accent-color); +} + +div#cgit table.stats td.total { + font-weight: bold; + text-align: left; +} + +div#cgit table.stats td.sum { + color: var(--red); + font-weight: bold; + background-color: var(--mantle); +} + +div#cgit table.stats td.left { + text-align: left; +} + +div#cgit table.vgraph { + border-collapse: separate; + border: solid 1px var(--accent-color); + height: 200px; +} + +div#cgit table.vgraph th { + background-color: var(--mantle); + font-weight: bold; + border: solid 1px var(--accent-color); + padding: 1px 0.5em; +} + +div#cgit table.vgraph td { + vertical-align: bottom; + padding: 0px 10px; +} + +div#cgit table.vgraph div.bar { + background-color: var(--mantle); +} + +div#cgit table.hgraph { + border: solid 1px var(--accent-color); + width: 800px; +} + +div#cgit table.hgraph th { + background-color: var(--mantle); + font-weight: bold; + border: solid 1px var(--accent-color); + padding: 1px 0.5em; +} + +div#cgit table.hgraph td { + vertical-align: middle; + padding: 2px 2px; +} + +div#cgit table.hgraph div.bar { + background-color: var(--mantle); + height: 1em; +} + +div#cgit table.ssdiff { + width: 100%; +} + +div#cgit table.ssdiff td { + font-size: 75%; + font-family: monospace; + white-space: pre; + padding: 1px 4px 1px 4px; + border-left: solid 1px var(--accent-color); + border-right: solid 1px var(--accent-color); +} + +div#cgit table.ssdiff td.add { + color: var(--mantle); + background: var(--sky); + min-width: 50%; +} + +div#cgit table.ssdiff td.add_dark { + color: var(--mantle); + background: var(--teal); + min-width: 50%; +} + +div#cgit table.ssdiff span.add { + background: var(--green); + font-weight: bold; +} + +div#cgit table.ssdiff td.del { + color: var(--mantle); + background: var(--maroon); + min-width: 50%; +} + +div#cgit table.ssdiff td.del_dark { + color: var(--mantle); + background: var(--red); + min-width: 50%; +} + +div#cgit table.ssdiff span.del { + background: var(--maroon); + font-weight: bold; +} + +div#cgit table.ssdiff td.changed { + color: var(--mantle); + background: var(--yellow); + min-width: 50%; +} + +div#cgit table.ssdiff td.changed_dark { + color: var(--mantle); + background: var(--rosewater); + min-width: 50%; +} + +div#cgit table.ssdiff td.lineno { + color: var(--subtext-0); + background: var(--surface-0); + text-align: right; + width: 3em; + min-width: 3em; +} + +div#cgit table.ssdiff td.hunk { + color: var(--mantle); + background: var(--lavender); + border-top: solid 1px var(--accent-color); + border-bottom: solid 1px var(--accent-color); +} + +div#cgit table.ssdiff td.head { + border-top: solid 1px var(--accent-color); + border-bottom: solid 1px var(--accent-color); +} + +div#cgit table.ssdiff td.head div.head { + font-weight: bold; + color: var(--text); +} + +div#cgit table.ssdiff td.foot { + border-top: solid 1px var(--accent-color); + border-left: none; + border-right: none; + border-bottom: none; +} + +div#cgit table.ssdiff td.space { + border: none; +} + +div#cgit table.ssdiff td.space div { + min-height: 3em; +} @@ -0,0 +1,317 @@ +#!/usr/bin/env python3 + +# /usr/lib/cgit/filters/html-converters/md2html +# make sure to also install catppuccin[pygments] with pip + +import markdown +import sys +import io +from pygments.formatters import HtmlFormatter +from markdown.extensions.toc import TocExtension +from catppuccin.extras.pygments import MochaStyle + +sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8') +sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') +sys.stdout.write(''' +<style> +.markdown-body { + font-size: 14px; + line-height: 1.6; + overflow: hidden; + max-width: 600px; + margin: 0 1rem; +} +.markdown-body>*:first-child { + margin-top: 0 !important; +} +.markdown-body>*:last-child { + margin-bottom: 0 !important; +} +.markdown-body a.absent { + color: var(--red); +} +.markdown-body a.anchor { + display: block; + padding-left: 30px; + margin-left: -30px; + cursor: pointer; + position: absolute; + top: 0; + left: 0; + bottom: 0; +} +.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4, .markdown-body h5, .markdown-body h6 { + margin: 20px 0 10px; + padding: 0; + font-weight: bold; + -webkit-font-smoothing: antialiased; + cursor: text; + position: relative; +} +.markdown-body h1 .mini-icon-link, .markdown-body h2 .mini-icon-link, .markdown-body h3 .mini-icon-link, .markdown-body h4 .mini-icon-link, .markdown-body h5 .mini-icon-link, .markdown-body h6 .mini-icon-link { + display: none; + color: var(--text); +} +.markdown-body h1:hover a.anchor, .markdown-body h2:hover a.anchor, .markdown-body h3:hover a.anchor, .markdown-body h4:hover a.anchor, .markdown-body h5:hover a.anchor, .markdown-body h6:hover a.anchor { + text-decoration: none; + line-height: 1; + padding-left: 0; + margin-left: -22px; + top: 15%; +} +.markdown-body h1:hover a.anchor .mini-icon-link, .markdown-body h2:hover a.anchor .mini-icon-link, .markdown-body h3:hover a.anchor .mini-icon-link, .markdown-body h4:hover a.anchor .mini-icon-link, .markdown-body h5:hover a.anchor .mini-icon-link, .markdown-body h6:hover a.anchor .mini-icon-link { + display: inline-block; +} +div#cgit .markdown-body h1 a.toclink, div#cgit .markdown-body h2 a.toclink, div#cgit .markdown-body h3 a.toclink, div#cgit .markdown-body h4 a.toclink, div#cgit .markdown-body h5 a.toclink, div#cgit .markdown-body h6 a.toclink { + color: var(--text); +} +.markdown-body h1 tt, .markdown-body h1 code, .markdown-body h2 tt, .markdown-body h2 code, .markdown-body h3 tt, .markdown-body h3 code, .markdown-body h4 tt, .markdown-body h4 code, .markdown-body h5 tt, .markdown-body h5 code, .markdown-body h6 tt, .markdown-body h6 code { + font-size: inherit; +} +.markdown-body h1 { + font-size: 28px; + color: var(--text); +} +.markdown-body h2 { + font-size: 24px; + border-bottom: 1px solid var(--accent-color); + color: var(--text); +} +.markdown-body h3 { + font-size: 18px; +} +.markdown-body h4 { + font-size: 16px; +} +.markdown-body h5 { + font-size: 14px; +} +.markdown-body h6 { + color: var(--text); + font-size: 14px; +} +.markdown-body p, .markdown-body blockquote, .markdown-body ul, .markdown-body ol, .markdown-body dl, .markdown-body table, .markdown-body pre { + margin: 15px 0; + color: var(--text); +} +.markdown-body hr { + background: transparent url("/dirty-shade.png") repeat-x 0 0; + border: 0 none; + color: var(--accent-color); + height: 4px; + padding: 0; +} +.markdown-body>h2:first-child, .markdown-body>h1:first-child, .markdown-body>h1:first-child+h2, .markdown-body>h3:first-child, .markdown-body>h4:first-child, .markdown-body>h5:first-child, .markdown-body>h6:first-child { + margin-top: 0; + padding-top: 0; +} +.markdown-body a:first-child h1, .markdown-body a:first-child h2, .markdown-body a:first-child h3, .markdown-body a:first-child h4, .markdown-body a:first-child h5, .markdown-body a:first-child h6 { + margin-top: 0; + padding-top: 0; +} +.markdown-body h1+p, .markdown-body h2+p, .markdown-body h3+p, .markdown-body h4+p, .markdown-body h5+p, .markdown-body h6+p { + margin-top: 0; +} +.markdown-body li p.first { + display: inline-block; +} +.markdown-body ul, .markdown-body ol { + padding-left: 30px; +} +.markdown-body ul.no-list, .markdown-body ol.no-list { + list-style-type: none; + padding: 0; +} +.markdown-body ul li>:first-child, .markdown-body ul li ul:first-of-type, .markdown-body ul li ol:first-of-type, .markdown-body ol li>:first-child, .markdown-body ol li ul:first-of-type, .markdown-body ol li ol:first-of-type { + margin-top: 0px; +} +.markdown-body ul li p:last-of-type, .markdown-body ol li p:last-of-type { + margin-bottom: 0; +} +.markdown-body ul ul, .markdown-body ul ol, .markdown-body ol ol, .markdown-body ol ul { + margin-bottom: 0; +} +.markdown-body dl { + padding: 0; +} +.markdown-body dl dt { + font-size: 14px; + font-weight: bold; + font-style: italic; + padding: 0; + margin: 15px 0 5px; +} +.markdown-body dl dt:first-child { + padding: 0; +} +.markdown-body dl dt>:first-child { + margin-top: 0px; +} +.markdown-body dl dt>:last-child { + margin-bottom: 0px; +} +.markdown-body dl dd { + margin: 0 0 15px; + padding: 0 15px; +} +.markdown-body dl dd>:first-child { + margin-top: 0px; +} +.markdown-body dl dd>:last-child { + margin-bottom: 0px; +} +.markdown-body blockquote { + border-left: 4px solid var(--accent-color); + padding: 0 15px; + color: var(--accent-color); +} +.markdown-body blockquote>:first-child { + margin-top: 0px; +} +.markdown-body blockquote>:last-child { + margin-bottom: 0px; +} +.markdown-body table th { + font-weight: bold; + background-color: var(--surface-1); +} +.markdown-body table th, .markdown-body table td { + border: 1px solid var(--text); + padding: 6px 13px; +} +.markdown-body table tr { + border-top: 1px solid var(--text); + background-color: var(--mantle); +} +.markdown-body table tr:nth-child(2n) { + background-color: var(--base); +} +.markdown-body img { + max-width: 100%; + -moz-box-sizing: border-box; + box-sizing: border-box; +} +.markdown-body span.frame { + display: block; + overflow: hidden; +} +.markdown-body span.frame>span { + border: 1px solid var(--text); + display: block; + float: left; + overflow: hidden; + margin: 13px 0 0; + padding: 7px; + width: auto; +} +.markdown-body span.frame span img { + display: block; + float: left; +} +.markdown-body span.frame span span { + clear: both; + color: var(--text); + display: block; + padding: 5px 0 0; +} +.markdown-body span.align-center { + display: block; + overflow: hidden; + clear: both; +} +.markdown-body span.align-center>span { + display: block; + overflow: hidden; + margin: 13px auto 0; + text-align: center; +} +.markdown-body span.align-center span img { + margin: 0 auto; + text-align: center; +} +.markdown-body span.align-right { + display: block; + overflow: hidden; + clear: both; +} +.markdown-body span.align-right>span { + display: block; + overflow: hidden; + margin: 13px 0 0; + text-align: right; +} +.markdown-body span.align-right span img { + margin: 0; + text-align: right; +} +.markdown-body span.float-left { + display: block; + margin-right: 13px; + overflow: hidden; + float: left; +} +.markdown-body span.float-left span { + margin: 13px 0 0; +} +.markdown-body span.float-right { + display: block; + margin-left: 13px; + overflow: hidden; + float: right; +} +.markdown-body span.float-right>span { + display: block; + overflow: hidden; + margin: 13px auto 0; + text-align: right; +} +.markdown-body code, .markdown-body tt { + margin: 0 2px; + padding: 0px 5px; + border: 1px solid var(--accent-color); + background-color: var(--mantle); + border-radius: 3px; +} +.markdown-body code { + white-space: nowrap; +} +.markdown-body pre>code { + margin: 0; + padding: 0; + white-space: pre; + border: none; + background: transparent; +} +.markdown-body .highlight pre, .markdown-body pre { + background-color: var(--mantle); + border: 1px solid var(--accent-color); + font-size: 13px; + line-height: 19px; + overflow: auto; + padding: 6px 10px; + border-radius: 3px; +} +.markdown-body pre code, .markdown-body pre tt { + margin: 0; + padding: 0; + background-color: transparent; + border: none; +} +''') +sys.stdout.write(HtmlFormatter(style=MochaStyle).get_style_defs('.highlight')) +sys.stdout.write(''' +</style> +''') +sys.stdout.write("<div class='markdown-body'>") +sys.stdout.flush() +# Note: you may want to run this through bleach for sanitization +markdown.markdownFromFile( + output_format="html5", + extensions=[ + "markdown.extensions.fenced_code", + "markdown.extensions.codehilite", + "markdown.extensions.tables", + TocExtension(anchorlink=True)], + extension_configs={ + "markdown.extensions.codehilite":{"css_class":"highlight"}}) +sys.stdout.write("</div>") diff --git a/syntax-highlighting.py b/syntax-highlighting.py new file mode 100644 index 0000000..b85b2c8 --- /dev/null +++ b/syntax-highlighting.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 + +# /usr/lib/cgit/filters/syntax-highlighting.py +# make sure to also install catppuccin[pygments] with pip + +# This script uses Pygments and Python3. You must have both installed +# for this to work. +# +# http://pygments.org/ +# http://python.org/ +# +# It may be used with the source-filter or repo.source-filter settings +# in cgitrc. +# +# The following environment variables can be used to retrieve the +# configuration of the repository for which this script is called: +# CGIT_REPO_URL ( = repo.url setting ) +# CGIT_REPO_NAME ( = repo.name setting ) +# CGIT_REPO_PATH ( = repo.path setting ) +# CGIT_REPO_OWNER ( = repo.owner setting ) +# CGIT_REPO_DEFBRANCH ( = repo.defbranch setting ) +# CGIT_REPO_SECTION ( = section setting ) +# CGIT_REPO_CLONE_URL ( = repo.clone-url setting ) + + +import sys +import io +from pygments import highlight +from pygments.util import ClassNotFound +from pygments.lexers import TextLexer +from pygments.lexers import guess_lexer +from pygments.lexers import guess_lexer_for_filename +from pygments.formatters import HtmlFormatter +from catppuccin.extras.pygments import MochaStyle + + +sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8', errors='replace') +sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace') +data = sys.stdin.read() +filename = sys.argv[1] +formatter = HtmlFormatter(style=MochaStyle, nobackground=True) + +try: + lexer = guess_lexer_for_filename(filename, data) +except ClassNotFound: + # check if there is any shebang + if data[0:2] == '#!': + try: + lexer = guess_lexer(data) + except ClassNotFound: + lexer = TextLexer() + else: + lexer = TextLexer() +except TypeError: + lexer = TextLexer() + +# highlight! :-) +# printout pygments' css definitions as well +sys.stdout.write('<style>') +sys.stdout.write(formatter.get_style_defs('.highlight')) +sys.stdout.write('</style>') +sys.stdout.write(highlight(data, lexer, formatter, outfile=None)) |