gitea
gitea copied to clipboard
Katex rendering with yaml frontmatter control
Extension to #20571 with the ability to add yaml frontmatter to control recognition of latex/tex code e.g.:
---
math:all
---
$x = 5$
Does this present an alternative to https://github.com/go-gitea/gitea/pull/20571 or replace it?
This is more of an extension to #20571 than replacement or alternative - if it's preferred to have this level of control we can merge it into #20571 or do it as another PR.
I think I need to look at controlling the goldmark parser/renderer a bit closer - it might just be that we should just create new goldmark structs each request instead of reusing but I'm not certain. We currently reuse because we can not because it's proven costly to recreate.
I still don't understand this YAML frontmatter business. How does it apply to Markdown? How is it used?
I still don't understand this YAML frontmatter business. How does it apply to Markdown? How is it used? The simple idea is that users use the yaml frontmatter to control aspects of the markdown renderer, enabling and disabling extensions as needed.
This is similar to how Hugo works.
Yes, but we don't write YAML in markdown content, or do we?
Frontmatter is a common extension that lots of markdown renderers provide:
https://gohugo.io/content-management/front-matter/
https://jekyllrb.com/docs/front-matter/
https://www.gatsbyjs.com/docs/how-to/routing/adding-markdown-pages/#:~:text=When%20you%20create%20a%20Markdown,and%20end%20of%20the%20block.
We've had a very basic front matter parser available in Gitea for quite some time - just essentially undocumented. (this includes a very basic implementation of include_toc functionality.
Ok, I see it's https://docs.gitlab.com/ee/user/markdown.html#front-matter, basically some metadata that can be rendered on top of markdown and that can be used by tools that process the markdown document.
Codecov Report
:exclamation: No coverage uploaded for pull request base (
main@c81b26b). Click here to learn what that means. The diff coverage is38.66%.
@@ Coverage Diff @@
## main #20640 +/- ##
=======================================
Coverage ? 47.04%
=======================================
Files ? 990
Lines ? 136423
Branches ? 0
=======================================
Hits ? 64181
Misses ? 64373
Partials ? 7869
| Impacted Files | Coverage Δ | |
|---|---|---|
| modules/markup/markdown/config/convertyaml.go | 0.00% <0.00%> (ø) |
|
| modules/markup/markdown/extension/ast.go | 0.00% <ø> (ø) |
|
| modules/markup/markdown/extension/toc.go | 0.00% <0.00%> (ø) |
|
| modules/markup/markdown/math/block_node.go | 0.00% <0.00%> (ø) |
|
| modules/markup/markdown/math/inline_node.go | 0.00% <0.00%> (ø) |
|
| modules/setting/setting.go | 48.88% <ø> (ø) |
|
| modules/markup/markdown/math/inline_parser.go | 10.34% <10.34%> (ø) |
|
| modules/markup/markdown/math/inline_renderer.go | 19.04% <19.04%> (ø) |
|
| modules/markup/markdown/math/block_renderer.go | 21.05% <21.05%> (ø) |
|
| modules/markup/markdown/math/block_parser.go | 21.15% <21.15%> (ø) |
|
| ... and 6 more |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.