macdown icon indicating copy to clipboard operation
macdown copied to clipboard

Support for GitLab flavored markdown math syntax

Open analog-cbarber opened this issue 8 years ago • 11 comments

GitLab now supports embedded KaTeX rendering but uses a different syntax:

Inline:

$`x^2`$

Block:

```math
x^2
```

It would be nice if there was an option to enable this syntax variant so that I can use MacDown to edit my GitLab-hosted markdown documents.

See https://docs.gitlab.com/ee/user/markdown.html#math

analog-cbarber avatar Jan 06 '17 19:01 analog-cbarber

Hmm, really odd syntax…

FranklinYu avatar Jan 06 '17 21:01 FranklinYu

Yup.

analog-cbarber avatar Jan 06 '17 21:01 analog-cbarber

I really hate the triple tick + name syntax here. I mentioned this in #625#issuecomment-238119135, but this is more pervasive than I thought.

Anyway I think this is currently not structurally possible because we can’t route block syntax to two (or more) different semantics. The code block rendering feature needs a rewrite anyway, but I can’t find time (and energy) to do it… :(

uranusjr avatar Jan 07 '17 14:01 uranusjr

Would it be feasible to just support the inline syntax?

analog-cbarber avatar Jan 07 '17 15:01 analog-cbarber

@analog-cbarber That seems possible. Could you provide some insights on how edge cases should be rendered? Some examples from the top of my head:

  • $` math `$ (also variants with only space on one side, or multiple spaces on one of both sides)
  • $``math`$
  • $`math``$ (also more unmatched ticks)
  • $``math``$ (matching multiple ticks)

uranusjr avatar Jan 07 '17 16:01 uranusjr

I don't know if this is documented anywhere but here is what I can observe experimentally:

It appears that any number of backticks may be used as long as they are matched and there is no space between the ticks and the $.

Spaces between the ticks and the math expression are thrown away when rendered.

analog-cbarber avatar Jan 07 '17 18:01 analog-cbarber

Cool, thanks! It seems GitLab use the same rules for inline code and math backticks (yes, inline code has the same behaviour; not many people know this). I’ll try and see what I can come up with this rule.

uranusjr avatar Jan 08 '17 04:01 uranusjr

It is not be hard to extend hoedown to support both the backtick syntax and the fenced syntax, but you probably don't want to depend on a forked version, so I guess I should see if I can get this into hoedown?

analog-cbarber avatar Mar 10 '17 21:03 analog-cbarber

I forked hoedown and implemented this feature, but it doesn't look like the original project is actively maintained anymore. I doubt they will accept a pull request.

see analog-cbarber/hoedown@d97e1938

analog-cbarber avatar Mar 11 '17 00:03 analog-cbarber

The best option is probably to officially (@MacDownApp) maintain a fork for now, and prepare to move to another Markdown parser in the future (see #704). I’m doing that now so you can submit a pull request there.

uranusjr avatar Mar 11 '17 05:03 uranusjr

Any chance this will move forward anytime soon? AFAICT GitLab is the only service which supports rendering of LaTeX in any form (at least, in .md files, I think through GitHub you can view Jupyter notebooks with Latex in them but that's a bit of a bother).

For now it seems the only reasonable workflow is to use the online GitLab editor to modify a raw .md file and switch to the preview to check the math rendering.

It would be great if there was a way to do this offline. Interested in any workarounds that people are using..

pbouffard avatar Apr 11 '21 00:04 pbouffard