Comments (8)
Markdown supports a subset of HTML features.
Classes and tags are part of the information which don't map 1:1 to CommonMark.
mdast-to-hast
adds data.hName
and data.hProperties
as more of a workarounds to allow transform plugins to generate HTML types that don't have a Markdown equivalent.
What is the intended use case for keeping hName
and hProperties
metadata on the Markdown side?
from hast-util-to-mdast.
Also see #38
from hast-util-to-mdast.
I'd like to highlight a code block using prism.js.
The result is an HTML string. I have two choice (afaik):
- parse the string as HTML->hast and include it to the original mdast with hast->mdast. Use remark2rehype to generate the HTML for the full document
- include the HTML as raw html in the mdast directly. Use remark2rehype + rehype-raw to render the raw html
I'm using the latter at the moment because the hast->to->mdast doesn't keep classes or tags for<span>
elements.
The other option I thought of would be to customise the remark2rehype transform. But from what I've seen, no one does that.
from hast-util-to-mdast.
@danielepolencic would https://github.com/mapbox/rehype-prism work for your use case?
Generating the syntax highlights during the HTML render phase?
from hast-util-to-mdast.
I had a look at that package, unfortunately, it doesn't work for me. I need to customise the rendering for Prism (with server-side highlights, etc.).
I found a way to customise the rendering with hast, I think that solves my issue at the moment.
Instead of working on the mdast tree, I do all the manipulations on the hast.
from hast-util-to-mdast.
@danielepolencic retype-prism does support server-side highlighting? 🤔
Anyway, yes, doing things in hast instead of mdast is often the solution ;)
from hast-util-to-mdast.
As far as I know, the line highlight plugin for Prism is only working in the browser.
https://github.com/PrismJS/prism/blob/master/plugins/line-highlight/prism-line-highlight.js#L3
from hast-util-to-mdast.
ahhh, yeah you’re right! Prism plugins interact with the DOM unfortunately... I built refractor to change Prism’s core to use a VDOM, but the plugins are too heavily dependent on the DOM...
It would be interesting to have a rehype version of the plugin though!
from hast-util-to-mdast.
Related Issues (20)
- Should `<select>`, `<datalist>`, `<option>`, and `<optgroup>` render lists? HOT 2
- How should `<dl>`, `<dt>`, and `<dd>` be rendered?
- Straddling
- Allow mapping of elements to raw HTML
- <br /> tag doesn't compile to new line in <code /> HOT 1
- Exception on tables without rows, cells
- <br> in tables breaks table HOT 5
- Handle newlines in headings, table cells
- Fix tables without header row
- Discrepancy in dependency HOT 3
- Support tables with "rowspan" or "colpsan" attributes HOT 4
- "url" package is not listed in package.json, but used in resolve.js HOT 3
- Nested tables creates empty cells HOT 9
- `<p><br /></p>` results `\` due to `wrapText` HOT 11
- Expose `defaultHandlers` to be reused HOT 16
- ignoring non-standard html tags HOT 3
- List item spread calculates spread incorrectly with nested lists. HOT 9
- Tasklists don't work if checkbox is a direct child of a list item HOT 12
- Weird trimming of inline element text causes invalid markdown HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hast-util-to-mdast.