gitea icon indicating copy to clipboard operation
gitea copied to clipboard

Katex rendering with yaml frontmatter control

Open zeripath opened this issue 3 years ago • 5 comments
trafficstars

Extension to #20571 with the ability to add yaml frontmatter to control recognition of latex/tex code e.g.:

---
math:all
--- 

$x = 5$

zeripath avatar Aug 02 '22 21:08 zeripath

Does this present an alternative to https://github.com/go-gitea/gitea/pull/20571 or replace it?

silverwind avatar Aug 02 '22 22:08 silverwind

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.

zeripath avatar Aug 05 '22 17:08 zeripath

I still don't understand this YAML frontmatter business. How does it apply to Markdown? How is it used?

silverwind avatar Aug 05 '22 18:08 silverwind

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.

zeripath avatar Aug 05 '22 20:08 zeripath

Yes, but we don't write YAML in markdown content, or do we?

silverwind avatar Aug 05 '22 20:08 silverwind

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.

zeripath avatar Aug 07 '22 07:08 zeripath

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.

silverwind avatar Aug 08 '22 19:08 silverwind

Codecov Report

:exclamation: No coverage uploaded for pull request base (main@c81b26b). Click here to learn what that means. The diff coverage is 38.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.

codecov-commenter avatar Aug 11 '22 20:08 codecov-commenter