UNPKG

extra-markdown-text

Version:
225 lines (223 loc) 7.78 kB
/** * Code block match function. * [📘](https://github.com/nodef/extra-markdown-text/wiki/CodeBlockMatchFunction) * @param full full code block * @param language code block language * @param body code block body */ type CodeBlockMatchFunction = (full: string, language: string, body: string) => void; /** * Match code blocks in markdown text. * [📘](https://github.com/nodef/extra-markdown-text/wiki/forEachCodeBlock) * @param txt markdown text * @param fn match function */ declare function forEachCodeBlock(txt: string, fn: CodeBlockMatchFunction): void; /** * Code block. * [📘](https://github.com/nodef/extra-markdown-text/wiki/CodeBlock) */ interface CodeBlock { /** Full code block. */ full: string; /** Code block language. */ language: string; /** Code block body. */ body: string; } /** * Get code blocks in markdown text. * [📘](https://github.com/nodef/extra-markdown-text/wiki/codeBlocks) * @param txt markdown text * @returns code blocks */ declare function codeBlocks(txt: string): CodeBlock[]; /** * Code block replace function. * [📘](https://github.com/nodef/extra-markdown-text/wiki/CodeBlockReplaceFunction) * @param full full code block * @param language code block language * @param body code block body * @returns updated code block */ type CodeBlockReplaceFunction = (full: string, language: string, body: string) => string; /** * Replace code blocks in markdown text. * [📘](https://github.com/nodef/extra-markdown-text/wiki/replaceCodeBlocks) * @param txt markdown text * @param fn replace function * @returns updated markdown text */ declare function replaceCodeBlocks(txt: string, fn: CodeBlockReplaceFunction): string; /** * Tag code blocks in markdown text and remove them. * [📘](https://github.com/nodef/extra-markdown-text/wiki/tagCodeBlocks) * @param txt markdown text * @returns [updated markdown text, tags] */ declare function tagCodeBlocks(txt: string): [string, Map<string, string>]; /** * Untag code blocks in markdown text by adding them back. * [📘](https://github.com/nodef/extra-markdown-text/wiki/untagCodeBlocks) * @param txt markdown text * @param tags tags * @returns updated markdown text */ declare function untagCodeBlocks(txt: string, tags: Map<string, string>): string; /** * Link match function. * [📘](https://github.com/nodef/extra-markdown-text/wiki/LinkMatchFunction) * @param full full link * @param name link name * @param reference link reference * @param url link url */ type LinkMatchFunction = (full: string, name: string, reference: string, url: string) => void; /** * Match links in markdown text. * [📘](https://github.com/nodef/extra-markdown-text/wiki/forEachLink) * @param txt markdown text * @param fn match function */ declare function forEachLink(txt: string, fn: LinkMatchFunction): void; /** * Link. * [📘](https://github.com/nodef/extra-markdown-text/wiki/Link) */ interface Link { /** Full link. */ full: string; /** Link name. */ name: string; /** Link reference. */ reference: string; /** Link URL. */ url: string; } /** * Get links in markdown text. * [📘](https://github.com/nodef/extra-markdown-text/wiki/links) * @param txt markdown text * @returns links */ declare function links(txt: string): Link[]; /** * Link replace function. * [📘](https://github.com/nodef/extra-markdown-text/wiki/LinkReplaceFunction) * @param full full link * @param name link name * @param ref link reference * @param url link url * @returns updated link */ type LinkReplaceFunction = (full: string, name: string, reference: string, url: string) => string; /** * Replace links in markdown text. * [📘](https://github.com/nodef/extra-markdown-text/wiki/replaceLinks) * @param txt markdown text * @param fn replace function * @returns updated markdown text */ declare function replaceLinks(txt: string, fn: LinkReplaceFunction): string; /** * Link reference match function. * [📘](https://github.com/nodef/extra-markdown-text/wiki/LinkReferenceMatchFunction) * @param full full link reference * @param name link reference name * @param url link reference url * @param title link reference title */ type LinkReferenceMatchFunction = (full: string, name: string, url: string, title: string) => void; /** * Match link references in markdown text. * [📘](https://github.com/nodef/extra-markdown-text/wiki/forEachLinkReference) * @param txt markdown text * @param fn match function */ declare function forEachLinkReference(txt: string, fn: LinkReferenceMatchFunction): void; /** * Link reference. * [📘](https://github.com/nodef/extra-markdown-text/wiki/LinkReference) */ interface LinkReference { /** Full link reference. */ full: string; /** Link reference name. */ name: string; /** Link reference URL. */ url: string; /** Link reference title. */ title: string; } /** * Get link references in markdown text. * [📘](https://github.com/nodef/extra-markdown-text/wiki/linkReferences) * @param txt markdown text * @returns links */ declare function linkReferences(txt: string): LinkReference[]; /** * Link reference replace function. * [📘](https://github.com/nodef/extra-markdown-text/wiki/LinkReferenceReplaceFunction) * @param full full link reference * @param name link reference name * @param url link reference url * @param title link reference title * @returns updated link reference */ type LinkReferenceReplaceFunction = (full: string, name: string, url: string, title: string) => string; /** * Replace link references in markdown text. * [📘](https://github.com/nodef/extra-markdown-text/wiki/replaceLinkReferences) * @param txt markdown text * @param fn replace function * @returns updated markdown text */ declare function replaceLinkReferences(txt: string, fn: LinkReferenceReplaceFunction): string; /** * Table match function. * [📘](https://github.com/nodef/extra-markdown-text/wiki/TableMatchFunction) * @param full full table * @param rows all rows of table */ type TableMatchFunction = (full: string, rows: string[][]) => void; /** * Match tables in markdown text. * [📘](https://github.com/nodef/extra-markdown-text/wiki/forEachTable) * @param txt markdown text * @param fn match function */ declare function forEachTable(txt: string, fn: TableMatchFunction): void; /** * Table. * [📘](https://github.com/nodef/extra-markdown-text/wiki/Table) */ interface Table { /** Full table. */ full: string; /** Rows of table. */ rows: string[][]; } /** * Get tables in markdown text. * [📘](https://github.com/nodef/extra-markdown-text/wiki/tables) * @param txt markdown text * @returns tables */ declare function tables(txt: string): Table[]; /** * Table replace function. * [📘](https://github.com/nodef/extra-markdown-text/wiki/TableReplaceFunction) * @param full full table * @param rows all rows of table */ type TableReplaceFunction = (full: string, rows: string[][]) => string; /** * Replace tables in markdown text. * [📘](https://github.com/nodef/extra-markdown-text/wiki/replaceTables) * @param txt markdown text * @param fn replace function * @returns updated markdown text */ declare function replaceTables(txt: string, fn: TableReplaceFunction): string; export { CodeBlock, CodeBlockMatchFunction, CodeBlockReplaceFunction, Link, LinkMatchFunction, LinkReference, LinkReferenceMatchFunction, LinkReferenceReplaceFunction, LinkReplaceFunction, Table, TableMatchFunction, TableReplaceFunction, codeBlocks, forEachCodeBlock, forEachLink, forEachLinkReference, forEachTable, linkReferences, links, replaceCodeBlocks, replaceLinkReferences, replaceLinks, replaceTables, tables, tagCodeBlocks, untagCodeBlocks };