-
Notifications
You must be signed in to change notification settings - Fork 2
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
How to parse <dl>...</dl> back to markdown #80
Comments
Presumably we need hast-util-to-mdast extension to convert html to md, as suggested in #59. I've wanted to make time to create an extension. |
That would be really great and make DL handling complete in rehype/remark system. |
I've just release hast-util-definition-list, which provides the way to convert hast into mdast. import { defListToMarkdown } from "mdast-util-definition-list";
import { fromHtml as hastFromHtml } from "hast-util-from-html";
import { toMarkdown as mdastToMarkdown } from "mdast-util-to-markdown";
import { toMdast as hastToMdast } from "hast-util-to-mdast";
import { defListHastToMdast } from "hast-util-definition-list";
const html = `
<dl>
<dt>First Term</dt>
<dd>This is the <strong>definition</strong> of the first term.</dd>
<dd>This is another definition of the first term.</dd>
<dt>Second Term</dt>
<dd>This is one definition of the second term.</dd>
<dd>This is another definition of the second term.</dd>
</dl>
`;
const hast = hastFromHtml(html, { fragment: true });
const mdast = hastToMdast(hast, {
handlers: {
...defListHastToMdast,
},
});
const md = mdastToMarkdown(mdast, {
extensions: [defListToMarkdown],
});
console.log(md); Bad news: you possibly cannot use this together with hast-util-definition-list depends on the latest version of hast-util-to-mdast, but |
Not an issue but rather question...
I have
function md2html(md)
below that produces<dl>...</dl>
successfully .But opposite
function html2md(html)
does not understand<dl>...</dl>
as input:seems like I need one more piece to this...
The text was updated successfully, but these errors were encountered: