#Trying to highlight some code in a `leptos` application - can't get errors as HTML tags?!

12 messages · Page 1 of 1 (latest)

lyric goblet
#

Hey there!

I am doing this right now:

    use typst::syntax::highlight_html;
    use typst::syntax::parse;

    let sn = parse(&code);
    let html = highlight_html(&sn);

My problem: if the typst code contains errors, the html doesn't contain any errors.

My assumption, that's because ```rust
fn highlight_html_impl(html: &mut String, node: &LinkedNode) {
let mut span = false;
if let Some(tag) = highlight(node) {
if tag != Tag::Error {
span = true;
html.push_str("<span class="");
html.push_str(tag.css_class());
html.push_str("">");
}
}
...

Error explicitly doesn't return any html-tag.

So, how can I get the error like in `typst.app`?
#

Trying to highlight some code in a leptos application - can't get errors as HTML tags?!

oblique trout
lyric goblet
lyric goblet
#

is not it though, because that's what I am using... I mean, it gives you the error, but then when you translate it to HTML, it's ignored

#

Maybe I'll have to write my own syntax-highlighting, although that would be a shame and wasted energy

oblique trout
#

Mh, I think I understand the problem now

#

You probably don't get around writing your own highlighter then
But it shouldn't be too hard to just copy the existing one and editing it to handle errors, right? Maybe it would even be nice to upstream these changes to Typst itself

#

I must say I find it especially weird/funny that a CSS class for an error is explicitly defined but then not used 😅

lyric goblet
tranquil moat