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

WIP: Katex rendering with yaml frontmatter control #20640

Closed
wants to merge 8 commits into from

Conversation

zeripath
Copy link
Contributor

@zeripath zeripath commented Aug 2, 2022

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

---
math:all
--- 

$x = 5$

zeripath added 4 commits July 31, 2022 18:12
This PR adds mathematical rendering with KaTeX.

The first step is to add a Goldmark extension that detects the latex
(and tex) mathematics delimiters.

The second step to make this extension only run if math support is
enabled.

The second step is to then add KaTeX CSS and JS to the head which will
load after the dom is rendered.

Fix go-gitea#3445

Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath zeripath added the pr/wip This PR is not ready for review label Aug 2, 2022
@zeripath zeripath changed the title Katex rendering with yaml Katex rendering with yaml frontmatter control Aug 2, 2022
Signed-off-by: Andrew Thornton <art27@cantab.net>
…th should

be enabled.

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath zeripath force-pushed the katex-rendering-with-yaml branch from 7ec69e2 to 3f868fc Compare August 2, 2022 21:24
@silverwind
Copy link
Member

Does this present an alternative to #20571 or replace it?

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Aug 2, 2022
@zeripath
Copy link
Contributor Author

zeripath commented Aug 5, 2022

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.

@silverwind
Copy link
Member

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

@zeripath
Copy link
Contributor Author

zeripath commented Aug 5, 2022

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.

@silverwind
Copy link
Member

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

@zeripath
Copy link
Contributor Author

zeripath commented Aug 7, 2022

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.

@silverwind
Copy link
Member

silverwind commented Aug 8, 2022

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.

Signed-off-by: Andrew Thornton <art27@cantab.net>
@codecov-commenter
Copy link

Codecov Report

❗ 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.

@zeripath zeripath changed the title Katex rendering with yaml frontmatter control WIP: Katex rendering with yaml frontmatter control Aug 14, 2022
@zeripath zeripath closed this Oct 5, 2022
@zeripath zeripath deleted the katex-rendering-with-yaml branch October 5, 2022 19:07
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. pr/wip This PR is not ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants