diff options
-rw-r--r-- | code/Cargo.lock | 359 | ||||
-rw-r--r-- | code/Cargo.toml | 4 | ||||
-rw-r--r-- | code/grammar/markdown.pest | 9 | ||||
-rw-r--r-- | code/makefile | 2 | ||||
-rw-r--r-- | code/src/html.rs | 13 | ||||
-rw-r--r-- | code/src/markdown/render.rs | 10 | ||||
-rw-r--r-- | code/src/syntax_highlight/grammar.rs | 67 | ||||
-rw-r--r-- | code/src/syntax_highlight/mod.rs | 44 | ||||
-rw-r--r-- | code/src/syntax_highlight/theme.rs | 13 | ||||
-rw-r--r-- | content/style.css | 4 |
10 files changed, 410 insertions, 115 deletions
diff --git a/code/Cargo.lock b/code/Cargo.lock index 28ef179..b6ca05c 100644 --- a/code/Cargo.lock +++ b/code/Cargo.lock @@ -3,10 +3,16 @@ version = 3 [[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" dependencies = [ "memchr", ] @@ -35,12 +41,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] +name = "block-buffer" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +dependencies = [ + "generic-array", +] + +[[package]] name = "blog-tool" version = "0.1.0" dependencies = [ @@ -49,7 +79,11 @@ dependencies = [ "iso8601", "katex", "laby", + "lazy_static", + "pest", + "pest_derive", "synoptic", + "syntect", ] [[package]] @@ -109,7 +143,35 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e4281031634644843bd2f5aa9c48cf98fc48d6b083bd90bb11becf10deaf8b0" dependencies = [ - "walkdir", + "walkdir 0.1.8", +] + +[[package]] +name = "cpufeatures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", ] [[package]] @@ -179,18 +241,48 @@ dependencies = [ ] [[package]] +name = "digest" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] name = "either" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" [[package]] +name = "flate2" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] +name = "generic-array" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -246,6 +338,12 @@ dependencies = [ ] [[package]] +name = "itoa" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" + +[[package]] name = "itoap" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -308,6 +406,12 @@ dependencies = [ ] [[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] name = "libc" version = "0.2.132" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -324,6 +428,21 @@ dependencies = [ ] [[package]] +name = "line-wrap" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f30344350a2a51da54c1d53be93fade8a237e545dbcc4bdbe635413f2117cab9" +dependencies = [ + "safemem", +] + +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + +[[package]] name = "memchr" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -336,6 +455,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] +name = "miniz_oxide" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" +dependencies = [ + "adler", +] + +[[package]] name = "nom" version = "7.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -346,18 +474,113 @@ dependencies = [ ] [[package]] +name = "num_threads" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" +dependencies = [ + "libc", +] + +[[package]] name = "once_cell" version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e" [[package]] +name = "onig" +version = "6.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c4b31c8722ad9171c6d77d3557db078cab2bd50afcc9d09c8b315c59df8ca4f" +dependencies = [ + "bitflags", + "libc", + "once_cell", + "onig_sys", +] + +[[package]] +name = "onig_sys" +version = "69.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b829e3d7e9cc74c7e315ee8edb185bf4190da5acde74afd7fc59c35b1f086e7" +dependencies = [ + "cc", + "pkg-config", +] + +[[package]] name = "os_str_bytes" version = "6.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" [[package]] +name = "pest" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb779fcf4bb850fbbb0edc96ff6cf34fd90c4b1a112ce042653280d9a7364048" +dependencies = [ + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "502b62a6d0245378b04ffe0a7fb4f4419a4815fce813bd8a0ec89a56e07d67b1" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "451e629bf49b750254da26132f1a5a9d11fd8a95a3df51d15c4abd1ba154cb6c" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcec162c71c45e269dfc3fc2916eaeb97feab22993a21bcce4721d08cd7801a6" +dependencies = [ + "once_cell", + "pest", + "sha1", +] + +[[package]] +name = "pkg-config" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" + +[[package]] +name = "plist" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd39bc6cdc9355ad1dc5eeedefee696bb35c34caf21768741e81826c0bbd7225" +dependencies = [ + "base64", + "indexmap", + "line-wrap", + "serde", + "time", + "xml-rs", +] + +[[package]] name = "proc-macro-error" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -442,6 +665,60 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" [[package]] +name = "safemem" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "serde" +version = "1.0.145" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" + +[[package]] +name = "serde_derive" +version = "1.0.145" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] name = "strsim" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -469,6 +746,29 @@ dependencies = [ ] [[package]] +name = "syntect" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6c454c27d9d7d9a84c7803aaa3c50cd088d2906fe3c6e42da3209aa623576a8" +dependencies = [ + "bincode", + "bitflags", + "flate2", + "fnv", + "lazy_static", + "once_cell", + "onig", + "plist", + "regex-syntax", + "serde", + "serde_derive", + "serde_json", + "thiserror", + "walkdir 2.3.2", + "yaml-rust", +] + +[[package]] name = "termcolor" version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -504,6 +804,29 @@ dependencies = [ ] [[package]] +name = "time" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c3f9a28b618c3a6b9251b6908e9c99e04b9e5c02e6581ccbb67d59c34ef7f9b" +dependencies = [ + "itoa", + "libc", + "num_threads", +] + +[[package]] +name = "typenum" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" + +[[package]] +name = "ucd-trie" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" + +[[package]] name = "unicode-ident" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -511,9 +834,9 @@ checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" [[package]] name = "unicode-width" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] name = "version_check" @@ -532,6 +855,17 @@ dependencies = [ ] [[package]] +name = "walkdir" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +dependencies = [ + "same-file", + "winapi 0.3.9", + "winapi-util", +] + +[[package]] name = "winapi" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -573,3 +907,18 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "xml-rs" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3" + +[[package]] +name = "yaml-rust" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" +dependencies = [ + "linked-hash-map", +] diff --git a/code/Cargo.toml b/code/Cargo.toml index 2155502..0a520aa 100644 --- a/code/Cargo.toml +++ b/code/Cargo.toml @@ -4,9 +4,13 @@ version = "0.1.0" edition = "2021" [dependencies] +lazy_static = "*" laby = "0.2.4" # html generation macros clap = { version = "3.2.17", features = ["derive"] } # bloated argument parser anyhow = "1.0.62" # error stuff iso8601 = "0.5.0" # date parsing synoptic = "1.2.0" # syntax highlighting katex = "0.4.4" +pest = "2.3.1" +pest_derive = "2.3.1" +syntect = "5.0.0" diff --git a/code/grammar/markdown.pest b/code/grammar/markdown.pest new file mode 100644 index 0000000..43c6e7a --- /dev/null +++ b/code/grammar/markdown.pest @@ -0,0 +1,9 @@ + +file = _{SOI ~ block* ~ EOI} +block = { (header | list | span | "") ~ NEWLINE } +header = {"#"+ ~ span} +list = { list_item+ } +list_item = { "-" ~ span } +span = { (!NEWLINE ~ ANY)+ } + + diff --git a/code/makefile b/code/makefile index 45f1de5..1a943b0 100644 --- a/code/makefile +++ b/code/makefile @@ -19,7 +19,7 @@ out/feed.atom: $(TOOL) $(SRC_ARTICLES) out/%: articles/%.md $(TOOL) out/style.css $(TOOLC) render-article $< > $@ -$(TOOL): $(shell find ../code/src -type f) +$(TOOL): $(shell find ../code/src -type f) $(shell find ../code/grammar -type f) sh -c 'cd ../code; cargo build' clean: diff --git a/code/src/html.rs b/code/src/html.rs index d310ad3..23ac6c8 100644 --- a/code/src/html.rs +++ b/code/src/html.rs @@ -1,7 +1,10 @@ use crate::{ - article_metadata, file_history, get_articles, markdown::{render::blocks_to_html, self}, ArticleMeta, + article_metadata, file_history, get_articles, + markdown::{self, render::blocks_to_html}, + ArticleMeta, }; use laby::{frag, html, iter, li, ul, Render}; +use pest::Parser; use std::fs::read_to_string; pub fn scaffold(title: String, body: impl Render) -> impl Render { @@ -25,6 +28,14 @@ pub fn scaffold(title: String, body: impl Render) -> impl Render { } pub fn article(path: String) -> impl Render { + // match parsers::markdown::Grammar::parse( + // parsers::markdown::Rule::file, + // &read_to_string(&path).unwrap(), + // ) { + // Ok(ast) => eprintln!("{ast:#?}"), + // Err(e) => panic!("{e}"), + // } + scaffold( article_metadata(path.clone().into()).title, frag!( diff --git a/code/src/markdown/render.rs b/code/src/markdown/render.rs index f6b7686..7962561 100644 --- a/code/src/markdown/render.rs +++ b/code/src/markdown/render.rs @@ -34,11 +34,11 @@ pub fn blocks_to_html(blocks: Vec<Block>) -> String { Block::Paragraph(p) => format!("<p>{}</p>", span_to_html(p)), Block::Blockquote(q) => format!("<quote>{}</quote>", blocks_to_html(q)), Block::CodeBlock(syntax, content) => { - if let Some(s) = &syntax { - format!("<pre>{}</pre>", syntax_highlight(s, &content)) - } else { - format!("<pre>{}</pre>", escape(&content)) - } + format!( + "<pre>{}</pre>", + syntax_highlight(&syntax.unwrap_or(String::from("")), &content) + .unwrap_or_else(|| escape(&content)) + ) } Block::OrderedList(els) => format!( "<ol>{}</ol>", diff --git a/code/src/syntax_highlight/grammar.rs b/code/src/syntax_highlight/grammar.rs deleted file mode 100644 index 0cecac9..0000000 --- a/code/src/syntax_highlight/grammar.rs +++ /dev/null @@ -1,67 +0,0 @@ -const CONST: &str = "[\\. \\(,=^]([A-Z][A-Z0-9_]*)[\\. ,\\)=$]"; -const TYPE: &str = "[\\. \\(,=^]([A-Z][a-zA-Z0-9_]*)[\\. ,\\)\\(=$]"; -const IDENT: &str = "[\\. \\(,=^]([a-z][a-zA-Z0-9_]*)[\\. ,\\)=$]"; -const FUNC: &str = "[\\. \\(,=^]([a-z][A-Z0-9_]*)\\("; - -pub fn grammar_for(syntax: &str) -> &'static [(&'static str, &'static [&'static str])] { - match syntax { - "rs" | "rust" => &[ - ( - "keyword", - &[ - "fn", "pub", "async", "return", "if", "else", "let", "for", "in", "while", - "loop", "impl", "for", "trait", "struct", "enum", "dyn", - ], - ), - ( - "type", - &[ - TYPE, "bool", "usize", "u8", "u16", "u32", "u64", "u128", "i8", "i16", "i32", - "i64", "i128", "isize", "f32", "f64", - ], - ), - ("constant", &[CONST]), - ("comment", &["(?m)(//.*)$", "(?ms)/\\*.*?\\*/"]), - ("macro", &["[\\. ,=^]([a-z_][A-Za-z0-9_]*!)[\\. ,=$]"]), - ("identifier", &[IDENT]), - ("function", &[FUNC]), - ( - "literal", - &["\".*?\"", "(0x|0o|0b)[0-9a-f]+", "\\d+", "true", "false"], - ), - ], - "py" | "python" => &[ - ("type", &["bytes", "bool", "int", "str", "float"]), - ( - "keyword", - &[ - "from", "for", "def", "if", "else", "elif", "while", "with", "in", "assert", - "global", "nonlocal", "as", "import", - ], - ), - ("comment", &["(?m)(#.*)$"]), - ("constant", &[CONST]), - ("identifier", &[IDENT]), - ( - "literal", - &[ - "b?f?\".*?\"", - "b?f?'.*?'", - "(0x|0o|0b)[0-9a-f]+", - "\\d+", - "true", - "false", - ], - ), - ], - "tree" => &[("keyword", &["[├─└│]+"])], - // makefile doesnt really match the token-kinds, i'll just use something that looks goo - "makefile" | "mk" => &[ - ("comment", &["(?m)(#.*)$"]), - ("literal", &[".+: "]), - ("macro", &["\\$\\(\\w+\\)"]), - ("type", &["\\$@", "\\$<"]), - ], - _ => &[], - } -} diff --git a/code/src/syntax_highlight/mod.rs b/code/src/syntax_highlight/mod.rs index 62a2536..86b689a 100644 --- a/code/src/syntax_highlight/mod.rs +++ b/code/src/syntax_highlight/mod.rs @@ -1,27 +1,29 @@ -pub mod grammar; -pub mod theme; -use crate::{markdown::render::escape, syntax_highlight::theme::theme}; -use grammar::grammar_for; -use synoptic::{Highlighter, Token}; +use crate::markdown::render::escape; +use lazy_static::lazy_static; +use syntect::easy::HighlightLines; +use syntect::highlighting::{Style, ThemeSet}; +use syntect::parsing::SyntaxSet; +use syntect::util::{as_24_bit_terminal_escaped, LinesWithEndings}; -pub fn syntax_highlight(lang: &str, source: &str) -> String { - let mut h = Highlighter::new(); - for (kind, regex) in grammar_for(lang) { - h.join(regex, kind).unwrap(); - } - let highlighting = h.run(source); - let mut out = String::new(); +lazy_static! { + static ref PS: SyntaxSet = SyntaxSet::load_defaults_newlines(); + static ref TS: ThemeSet = ThemeSet::load_defaults(); +} + +pub fn syntax_highlight(lang: &str, source: &str) -> Option<String> { + let syntax = PS.find_syntax_by_extension(lang)?; + let mut h = HighlightLines::new(syntax, &TS.themes["Solarized (dark)"]); - for (_c, row) in highlighting.iter().enumerate() { - for tok in row { - match tok { - Token::Start(kind) => out += &format!("<span style=\"color:{}\">", theme(kind)), - Token::Text(text) => out += &escape(text), - Token::End(_kind) => out += "</span>", - } + let mut o = String::new(); + for line in LinesWithEndings::from(source) { + let ranges: Vec<(Style, &str)> = h.highlight_line(line, &PS).unwrap(); + for (style, span) in ranges { + o += &format!( + "<span style=\"color: #{:02x}{:02x}{:02x}\">{}</span>", + style.foreground.r, style.foreground.g, style.foreground.b, span + ); } - out += "\n" } - out + return Some(o); } diff --git a/code/src/syntax_highlight/theme.rs b/code/src/syntax_highlight/theme.rs deleted file mode 100644 index 2dfd10d..0000000 --- a/code/src/syntax_highlight/theme.rs +++ /dev/null @@ -1,13 +0,0 @@ -pub fn theme(kind: &str) -> &'static str { - match kind { - "keyword" => "#9999ff", - "macro" => "#ff2863", - "literal" => "#26a6ff", - "function" => "#26ffbc", - "types" => "#26ff34", - "identifier" => "#ccff26", - "constant" => "#ff7c26", - "comment" => "#6e6e6e", - _ => "#ff00ff", - } -} diff --git a/content/style.css b/content/style.css index 15ea9b8..3e19951 100644 --- a/content/style.css +++ b/content/style.css @@ -1,8 +1,8 @@ @import url("https://s.metamuffin.org/static/font-ubuntu/include.css"); :root { - --bg2: #202020; - --bg1: #101010; + --bg2: #141414; + --bg1: #060606; } body { |