From a7c8e1f0e171506cce114ebef3ab6a04e351554e Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 10 Jul 2023 17:12:12 +0200 Subject: [PATCH] Change to expose function --- lib/index.js | 36 +++++++++++++++++++----------------- readme.md | 27 ++++++++++++++++----------- test.js | 12 ++++++------ 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/lib/index.js b/lib/index.js index a669033..11e5115 100644 --- a/lib/index.js +++ b/lib/index.js @@ -33,26 +33,28 @@ import {ok as assert} from 'devlop' import {markdownTable} from 'markdown-table' import {defaultHandlers} from 'mdast-util-to-markdown' -// To do: next major: expose functions. - /** - * Extension for `mdast-util-from-markdown` to enable GFM tables. + * Create an extension for `mdast-util-from-markdown` to enable GFM tables in + * markdown. * - * @type {FromMarkdownExtension} + * @returns {FromMarkdownExtension} + * Extension for `mdast-util-from-markdown` to enable GFM tables. */ -export const gfmTableFromMarkdown = { - enter: { - table: enterTable, - tableData: enterCell, - tableHeader: enterCell, - tableRow: enterRow - }, - exit: { - codeText: exitCodeText, - table: exitTable, - tableData: exit, - tableHeader: exit, - tableRow: exit +export function gfmTableFromMarkdown() { + return { + enter: { + table: enterTable, + tableData: enterCell, + tableHeader: enterCell, + tableRow: enterRow + }, + exit: { + codeText: exitCodeText, + table: exitTable, + tableData: exit, + tableHeader: exit, + tableRow: exit + } } } diff --git a/readme.md b/readme.md index 67a8d4c..186a5de 100644 --- a/readme.md +++ b/readme.md @@ -112,7 +112,7 @@ const doc = await fs.readFile('example.md') const tree = fromMarkdown(doc, { extensions: [gfmTable()], - mdastExtensions: [gfmTableFromMarkdown] + mdastExtensions: [gfmTableFromMarkdown()] }) console.log(tree) @@ -174,14 +174,19 @@ console.log(out) ## API This package exports the identifiers -[`gfmTableFromMarkdown`][api-gfmtablefrommarkdown] and -[`gfmTableToMarkdown`][api-gfmtabletomarkdown]. +[`gfmTableFromMarkdown`][api-gfm-table-from-markdown] and +[`gfmTableToMarkdown`][api-gfm-table-to-markdown]. There is no default export. ### `gfmTableFromMarkdown` -Extension for [`mdast-util-from-markdown`][mdast-util-from-markdown] to enable -GFM tables ([`FromMarkdownExtension`][frommarkdownextension]). +Create an extension for [`mdast-util-from-markdown`][mdast-util-from-markdown] +to enable GFM tables in markdown. + +###### Returns + +Extension for `mdast-util-from-markdown` to enable GFM tables +([`FromMarkdownExtension`][from-markdown-extension]). ### `gfmTableToMarkdown(options?)` @@ -196,7 +201,7 @@ enable GFM tables in markdown. ###### Returns Extension for `mdast-util-to-markdown` to enable GFM tables -([`ToMarkdownExtension`][tomarkdownextension]). +([`ToMarkdownExtension`][to-markdown-extension]). ### `Options` @@ -302,7 +307,7 @@ The following interfaces are added to **[mdast][]** by this utility. ```idl interface Table <: Parent { - type: "table" + type: 'table' align: [alignType]? children: [TableContent] } @@ -579,13 +584,13 @@ abide by its terms. [dfn-break]: https://github.com/syntax-tree/mdast#break -[frommarkdownextension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension +[from-markdown-extension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension -[tomarkdownextension]: https://github.com/syntax-tree/mdast-util-to-markdown#options +[to-markdown-extension]: https://github.com/syntax-tree/mdast-util-to-markdown#options -[api-gfmtablefrommarkdown]: #gfmtablefrommarkdown +[api-gfm-table-from-markdown]: #gfmtablefrommarkdown -[api-gfmtabletomarkdown]: #gfmtabletomarkdownoptions +[api-gfm-table-to-markdown]: #gfmtabletomarkdownoptions [api-options]: #options diff --git a/test.js b/test.js index 13be67f..be8d721 100644 --- a/test.js +++ b/test.js @@ -20,12 +20,12 @@ test('core', async function (t) { }) }) -test('gfmTableFromMarkdown', async function (t) { +test('gfmTableFromMarkdown()', async function (t) { await t.test('should support tables', async function () { assert.deepEqual( fromMarkdown('| a\n| -', { extensions: [gfmTable()], - mdastExtensions: [gfmTableFromMarkdown] + mdastExtensions: [gfmTableFromMarkdown()] }), { type: 'root', @@ -79,7 +79,7 @@ test('gfmTableFromMarkdown', async function (t) { assert.deepEqual( fromMarkdown('| a | b | c | d |\n| - | :- | -: | :-: |', { extensions: [gfmTable()], - mdastExtensions: [gfmTableFromMarkdown] + mdastExtensions: [gfmTableFromMarkdown()] }), { type: 'root', @@ -185,7 +185,7 @@ test('gfmTableFromMarkdown', async function (t) { async function () { const tree = fromMarkdown('| `\\|` |\n | --- |', { extensions: [gfmTable()], - mdastExtensions: [gfmTableFromMarkdown] + mdastExtensions: [gfmTableFromMarkdown()] }) removePosition(tree, {force: true}) @@ -218,7 +218,7 @@ test('gfmTableFromMarkdown', async function (t) { async function () { const tree = fromMarkdown('`\\|`', { extensions: [gfmTable()], - mdastExtensions: [gfmTableFromMarkdown] + mdastExtensions: [gfmTableFromMarkdown()] }) removePosition(tree, {force: true}) @@ -237,7 +237,7 @@ test('gfmTableFromMarkdown', async function (t) { async function () { const tree = fromMarkdown('| `\\\\|`\\\\` b |\n | --- | --- |', { extensions: [gfmTable()], - mdastExtensions: [gfmTableFromMarkdown] + mdastExtensions: [gfmTableFromMarkdown()] }) removePosition(tree, {force: true})