Skip to content

Help converting an HTML span to a Markdown directive #240

Answered by wooorm
dmca-glasgow asked this question in Q&A
Discussion options

You must be logged in to vote

Hey!

The h* fields are indeed also a good way to do this, the other way around, mdast -> hast.
Such a thing does not exist hast -> mdast.

But, what is also possible, is to hook into the place where the conversion between the ASTs happens. remark-rehype and rehype-remark.

They both support handlers:

handlers (Record<string, Handle>, optional) — object mapping tag names to functions handling the corresponding elements; merged into the defaults; see Handle in hast-util-to-mdast

There you would use span as a key, and write a handler that generates a text directive: https://github.com/syntax-tree/mdast-util-directive#textdirective.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@dmca-glasgow
Comment options

@wooorm
Comment options

@dmca-glasgow
Comment options

Answer selected by dmca-glasgow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants