showdown
showdown copied to clipboard
No documentation on makeMarkdown function
The description of this converter reads "A bidirectional Markdown to HTML to Markdown converter written in Javascript". This was my main reason for using this package as I need to convert both ways.
However, I can't find any examples or documentation on how convert HTML to markdown using makeMarkdown()
.
Same. I'm trying:
const converter = new Showdown.Converter();
const markdown = converter.makeMarkdown(html);
And I get ReferenceError: window is not defined
same error.
@SARAsBooks I got it.
the correct way is:
import showdown from 'showdown';
import { JSDOM } from 'jsdom';
const converter = new showdown.Converter();
const text = `<h1 id="hellomarkdown">hello, markdown!</h1>`;
const doc = new JSDOM(text);
const html = converter.makeMarkdown(text, doc.window.document);
console.log('html', html);
here is the type:
/**
* Converts an HTML string into a markdown string.
*
* @param src - The input text (HTML)
* @param [HTMLParser] A WHATWG DOM and HTML parser, such as JSDOM. If none is supplied, window.document will be used.
* @returns The output markdown.
*/
makeMarkdown(src: string, HTMLParser?: HTMLDocument): string;
If the code is used in Nodejs, you must provide a virtual document, otherwise the code will use window.document by default, and then it will report an error: ReferenceError: window is not defined