v1 checkpoint
This commit is the initial checkpoint for a functioning converter with all tests passing.
This commit is contained in:
1 parent
158c71bce6
commit
965fc09d99
58 files changed
+2921
-3224
No files matched your search
Vendored
+70
@@ -0,0 +1,70 @@
|
||||
import type { Token, 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;
|
||||
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;
|
||||
}
|
||||
Reference in new issue
Block a user