Skip to content

Commit

Permalink
Change to expose function
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 10, 2023
1 parent f70934a commit a7c8e1f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 34 deletions.
36 changes: 19 additions & 17 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down
27 changes: 16 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const doc = await fs.readFile('example.md')

const tree = fromMarkdown(doc, {
extensions: [gfmTable()],
mdastExtensions: [gfmTableFromMarkdown]
mdastExtensions: [gfmTableFromMarkdown()]
})

console.log(tree)
Expand Down Expand Up @@ -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?)`

Expand All @@ -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`

Expand Down Expand Up @@ -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]
}
Expand Down Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -218,7 +218,7 @@ test('gfmTableFromMarkdown', async function (t) {
async function () {
const tree = fromMarkdown('`\\|`', {
extensions: [gfmTable()],
mdastExtensions: [gfmTableFromMarkdown]
mdastExtensions: [gfmTableFromMarkdown()]
})

removePosition(tree, {force: true})
Expand All @@ -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})
Expand Down

0 comments on commit a7c8e1f

Please sign in to comment.