update to support fenced code

This commit is contained in:
Luke Boswell 2023-03-08 17:30:30 +11:00
parent a87794e7b2
commit 890f3db10a
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
10 changed files with 828 additions and 724 deletions

View file

@ -2,6 +2,18 @@ use roc_parse::highlight::Token;
use roc_region::all::Loc;
pub fn highlight_roc_code(code: &str) -> String {
let buf = highlight(code);
format!("<pre><samp>{}</samp></pre>", buf.join(""))
}
pub fn highlight_roc_code_inline(code: &str) -> String {
let buf = highlight(code);
format!("<code>{}</code>", buf.join(""))
}
pub fn highlight(code: &str) -> Vec<String> {
let locations: Vec<Loc<Token>> = roc_parse::highlight::highlight(code);
let mut buf: Vec<String> = Vec::new();
let mut offset = 0;
@ -90,7 +102,7 @@ pub fn highlight_roc_code(code: &str) -> String {
offset = location.byte_range().end;
}
format!("<pre><samp>{}</samp></pre>", buf.join(""))
buf
}
fn push_html_span(mut buf: Vec<String>, curr: &str, class: &str) -> Vec<String> {