Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax-Highlighting to HTML should give a span with css class typ-error for errors #3993

Open
nerdachse opened this issue Apr 24, 2024 · 2 comments
Labels
crate Issues with using Typst as a library for other apps feature request New feature or request syntax About syntax, parsing, etc.

Comments

@nerdachse
Copy link

Description

Hey there!

I am experimenting with leptos and typst and in the middle of writing a simple code editor.

Now I wanted to have syntax-highlighting and fair enough, that's trivial...

fn highlight_code(code: &str) -> String {
    use typst_syntax::highlight_html;
    use typst_syntax::parse;

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

The problem? https://github.com/typst/typst/blob/main/crates/typst-syntax/src/highlight.rs#L376-L385

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("\">");
        }
    }
...

An error-tag is not getting a css-span!

The most trivial fix is here: nerdachse@5749284

But of course that's probably not what you want, hence this issue, so we can find a solution that fits into everyone's plans!

Use Case

Highlighting typst to html with support for errors.

screenshot_24 04 2024-11 58 43

@nerdachse nerdachse added the feature request New feature or request label Apr 24, 2024
@laurmaedje
Copy link
Member

Not sure what my thinking there was. Maybe I disabled it because I wanted to frequently highlight half-wrong things like .foo(..) in the docs and everything turned red all the time. I'll need to try what happens to the docs if the if is removed.

@laurmaedje laurmaedje added syntax About syntax, parsing, etc. crate Issues with using Typst as a library for other apps labels Apr 29, 2024
@nerdachse
Copy link
Author

Anything I can help with here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate Issues with using Typst as a library for other apps feature request New feature or request syntax About syntax, parsing, etc.
Projects
None yet
Development

No branches or pull requests

2 participants