Skip to content

htmlToMarkdown

Official

Converts HTML to a Markdown string.

Import:

import { htmlToMarkdown } from 'obsidian';

Example:

console.log(htmlToMarkdown('<h1>foo</h1>')); // # foo
const el = createDiv();
el.createEl('h2', { text: 'bar' });
console.log(htmlToMarkdown(el)); // ## bar
const fragment = createFragment();
fragment.createEl('h3', { text: 'baz' });
console.log(htmlToMarkdown(fragment)); // ### baz

Signature:

function htmlToMarkdown(html: string | Document | DocumentFragment | HTMLElement): string

Parameters:

ParameterTypeDescription
htmlstring | Document | DocumentFragment | HTMLElement

Returns: string

Example:

console.log(htmlToMarkdown('<h1>foo</h1>')); // # foo
const el = createDiv();
el.createEl('h2', { text: 'bar' });
console.log(htmlToMarkdown(el)); // ## bar
const fragment = createFragment();
fragment.createEl('h3', { text: 'baz' });
console.log(htmlToMarkdown(fragment)); // ### baz