Feature Request: Allow to render to any virtual dom implementation using hyperscript
See original GitHub issueThe point of this feature request is to allow better integration of KaTeX inside virtual dom libraries like : React, Preact, Vue.js, Hast, Inferno, Snabbdom… (many more)
Each of these lib basically support an hyperscript implementation to create their flavour of virtual dom :
- React.createElement
- preact.h
- createElement inside a vue render()
- hastscript
- Inferno.h
- snabbdom/h
- ivi
This feature would be a new method taking an hyperscript implementation like :
/**
* @param {string} expr - the expression to render
* @param {object} options - katex rendering options
* @param {function} h - an hyperscript implementation
* @return {object} - a (virtual) dom tree
*/
katex.renderToVTree(expr, options, h);
Without this integration, there are many known issues :
- Right now a library like rehype-katex has to render katex nodes to strings and to reparse them to integrate in their virtual dom implementation (HAST).
- Many markdown editors that support KaTeX are unable to render the preview with the minimal amount of DOM modification needed, which usually results in preview content being discarded/recreated at each keystroke in the editor.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:8 (4 by maintainers)
Top Results From Across the Web
hyperscript documentation - ///_hyperscript
Hyperscript is a scripting language for doing front end web development. It is designed to make it very easy to respond to events...
Read more >What does the 'h' stand for in Vue's render method? - CSS-Tricks
The h stands for hyperscript. It's a riff of HTML, which means Hypertext Markup Language: since we're dealing with a script, it's become ......
Read more >render(element, vnodes) - Mithril.js
Documentation on m.render(), which Mithril.js uses to efficiently patch real DOM trees with virtual DOM nodes.
Read more >Million.js: A Fast Compiler-Augmented Virtual DOM for the Web
allow developers to choose a JavaScript UI library that fits their project [17] through the virtual DOM at the cost of load time...
Read more >Differences to React - Preact
The reason Preact does not attempt to include every single feature of React is in order to remain small and focused - otherwise...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

There was a similar request to have
buildHTMLoutputHAST, see #800. I think havingbuildHTMLoutput something that is easily consumable by other tools would be good to have. I don’t think that KaTeX needs to define its own DOM representation. As long asstyleis an object I think we’re okay. In terms of adding a new representation, that feels like a short term solution. Long term, if we’re outputting some version ofHASTwe may as well use it internally as well. It’s probably easier adding it as a new additional format first and then migrating to use it internally as a separate PR.@spontaliku-softaria : thank you for this pertinent remark ! You’re mostly right : there are some importants variations to consider in the implementation of the hyperscript DSL.
Some flavours of hyperscript support the extended (Emmet-like) tagname syntax, like in the following example :
Some of them identify the SVG tags while some other offer a specific hyperscript variant for SVG or support a special
namespaceattribute :And finally, some implementations allow for a varying signature where arguments are recognized by their type, when not on their expected position :
However, i have found that there is some valid ground for a common form that is accepted by almost every implementations and it is the following one :
Where
classNameandclassshould be both set as a string property that accepts a space separated list of class namesnamespace="http://www.w3.org/2000/svg"should be added to the properties object to create a SVG node.It’s not perfect (there are still problems occuring on the attributes of the
styleproperty as to whether they should be camelCased or kebab-cased) but it allready gives us a good 80/20 ratio : 20% of efforts for ~ 80% support on every hyperscript library.Now… that could be the moment to propose a Level 1 and Level 2 specification for hyperscript along with a test suite, and see the implementations converge, but it is another story… 😃