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

Bug in latex example in tokenizer extension docs #1948

Closed
UlisseMini opened this issue Feb 18, 2021 · 3 comments
Closed

Bug in latex example in tokenizer extension docs #1948

UlisseMini opened this issue Feb 18, 2021 · 3 comments
Labels
category: docs Documentation changes

Comments

@UlisseMini
Copy link
Contributor

The latex example in the docs is broken, it doesn't handle foo $tex$ bar (foo disappears). This should be mentioned, or the docs should be fixed.

I spent a while trying to get latex like $this$ working without success,
I read #1538 but solution 1 was a hack putting math inside code blocks,
and solution 2 was complex and stateful.

IMO this is the kind of thing that should be easy. I like the example in the docs except it doesn't work ):

I read #1653 but the solution seems overly complicated, I can do something like that but IMO modifying inlineText shouldn't be necessary for this.
I don't understand the codebase though so maybe this is unavoidable because of how lexing is done.

I'd be happy to contribute a fix if I figure it out, or someone explains to me :)

@UziTech
Copy link
Member

UziTech commented Feb 18, 2021

Ya the example in the docs is to show how to extend the tokenizer not necessarily how to implement latex. It also doesn't handle multiple $'s.

modifying inlineText shouldn't be necessary for this.

Ya we have been talking about ways to make that easier. Currently to make marked faster inlineText consumes everything up until it sees the potential start of a new token so when extending the tokenizer we need to extend inlineText to know what the new token start would be.

I'd be happy to contribute a fix if I figure it out

That would be great!

@UlisseMini
Copy link
Contributor Author

I ended up using this workaround (for latex `$like this`)

marked.use({
  renderer: {
    codespan: (code) => {
      if (code[0] == '$') {
        return katex.renderToString(code.slice(1), {throwOnError: false})
      }

      return false
    }
  }
})

I mentioned the hole in the docs in #1949, haven't fixed it though ): reworking the lexer is a bit more than I'm willing to take on right now. though #1872 looks promising.

@UziTech
Copy link
Member

UziTech commented Feb 19, 2021

fixed by #1949

@UziTech UziTech closed this as completed Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: docs Documentation changes
Projects
None yet
Development

No branches or pull requests

3 participants
@UziTech @UlisseMini and others