72 lines
2.1 KiB
TypeScript
72 lines
2.1 KiB
TypeScript
import type { Token, TagType, TagCollectionType } from './types';
|
|
export declare function escapeHtml(source: string): string;
|
|
/**
|
|
* A configurable markdown <=> HTML converter.
|
|
*
|
|
* Examples:
|
|
*
|
|
* const hopdown = new HopDown();
|
|
*
|
|
* const html = hopdown.toHTML('**bold**');
|
|
* html === '<p><strong>bold</strong></p>';
|
|
*
|
|
* const markdown = hopdown.toMarkdown(html);
|
|
* markdown === '**bold**';
|
|
*
|
|
* const node = hopdown.toEditorNode('**bold**');
|
|
* (node as HTMLElement).outerHTML === (
|
|
* "<div>" +
|
|
* "<span class='delim strong'>**</span>" +
|
|
* "bold" +
|
|
* "<span class='delim strong'>" +
|
|
* "</div>"
|
|
* );
|
|
*/
|
|
export declare class HopDown {
|
|
tags: TagCollectionType;
|
|
macros: TagType | null;
|
|
private tokenizer;
|
|
constructor(tags?: TagCollectionType | null);
|
|
/**
|
|
* Convert a markdown string to tokens.
|
|
*/
|
|
tokenize(source: string): Token[];
|
|
/**
|
|
* Convert an HTML string or a DocumentFragment to markdown.
|
|
*/
|
|
toMarkdown: (html: string | DocumentFragment) => string;
|
|
/**
|
|
* Convert a markdown string to a DocumentFragment consisting of wysiwyg editor nodes.
|
|
*/
|
|
toEditorNode: (markdown: string) => DocumentFragment;
|
|
toHTML: (markdown: string) => string;
|
|
/**
|
|
* Recursive entrypoint for converting markdown to html.
|
|
*/
|
|
inlineToHTML: (markdown: string) => string;
|
|
/**
|
|
* Recursive entrypoint for converting markdown to editor nodes.
|
|
*/
|
|
private inlineToEditorNodes;
|
|
/**
|
|
* Convert an HTML node to a markdown string. Used by toMarkdown().
|
|
*/
|
|
private nodeToMarkdown;
|
|
/**
|
|
* Convert a token stream to editor nodes.
|
|
*/
|
|
private tokensToEditorNodes;
|
|
/**
|
|
* Convert a token stream to HTML. Matches open/close delimiter
|
|
* pairs and wraps their content in the appropriate HTML tags.
|
|
* Unmatched delimiters are emitted as literal text.
|
|
*/
|
|
private tokensToHTML;
|
|
/**
|
|
* Match open/close delimiter pairs in a token stream. Unmatched
|
|
* openers/closers are converted to text tokens so they render
|
|
* as literal characters.
|
|
*/
|
|
private pairDelimiters;
|
|
}
|