Giter Site home page Giter Site logo

Comments (8)

ChristianMurphy avatar ChristianMurphy commented on June 15, 2024

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.

ChristianMurphy avatar ChristianMurphy commented on June 15, 2024

Also see #38

from hast-util-to-mdast.

danielepolencic avatar danielepolencic commented on June 15, 2024

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.

ChristianMurphy avatar ChristianMurphy commented on June 15, 2024

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

danielepolencic avatar danielepolencic commented on June 15, 2024

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.

wooorm avatar wooorm commented on June 15, 2024

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

danielepolencic avatar danielepolencic commented on June 15, 2024

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.

wooorm avatar wooorm commented on June 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.