Skip to content

Commit fcf0b74

Browse files
committed
Refactor code-style
* Add more docs to JSDoc * Add support for `null` in input of API types
1 parent e521fb5 commit fcf0b74

File tree

4 files changed

+53
-26
lines changed

4 files changed

+53
-26
lines changed

lib/index.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
/**
22
* @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension
33
* @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension
4-
*
4+
*/
5+
6+
/**
57
* @typedef {import('mdast-util-gfm-table').Options} Options
8+
* Configuration.
69
*/
710

811
import {
@@ -24,7 +27,12 @@ import {
2427
} from 'mdast-util-gfm-task-list-item'
2528

2629
/**
30+
* Create an extension for `mdast-util-from-markdown` to enable GFM (autolink
31+
* literals, footnotes, strikethrough, tables, tasklists).
32+
*
2733
* @returns {Array<FromMarkdownExtension>}
34+
* Extension for `mdast-util-from-markdown` to enable GFM (autolink literals,
35+
* footnotes, strikethrough, tables, tasklists).
2836
*/
2937
export function gfmFromMarkdown() {
3038
return [
@@ -37,8 +45,14 @@ export function gfmFromMarkdown() {
3745
}
3846

3947
/**
40-
* @param {Options} [options]
48+
* Create an extension for `mdast-util-to-markdown` to enable GFM (autolink
49+
* literals, footnotes, strikethrough, tables, tasklists).
50+
*
51+
* @param {Options | null | undefined} [options]
52+
* Configuration.
4153
* @returns {ToMarkdownExtension}
54+
* Extension for `mdast-util-to-markdown` to enable GFM (autolink literals,
55+
* footnotes, strikethrough, tables, tasklists).
4256
*/
4357
export function gfmToMarkdown(options) {
4458
return {

package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,19 @@
8282
"trailingComma": "none"
8383
},
8484
"xo": {
85-
"prettier": true
85+
"prettier": true,
86+
"overrides": [
87+
{
88+
"files": "test/**/*.js",
89+
"rules": {
90+
"no-await-in-loop": "off"
91+
}
92+
}
93+
]
8694
},
8795
"remarkConfig": {
8896
"plugins": [
89-
"preset-wooorm"
97+
"remark-preset-wooorm"
9098
]
9199
},
92100
"typeCoverage": {

script/crawl-tests.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import assert from 'node:assert/strict'
22
import fs from 'node:fs'
3-
import path from 'node:path'
43
import fetch from 'node-fetch'
54

65
const response = await fetch(
76
'https://api.github.com/repos/micromark/micromark-extension-gfm/contents/test/spec.js',
87
{headers: {Accept: 'application/vnd.github.v3.raw'}}
98
)
109
assert(response.body, 'expected body')
11-
response.body.pipe(fs.createWriteStream(path.join('test', 'spec.js')))
10+
response.body.pipe(
11+
fs.createWriteStream(new URL('../test/spec.js', import.meta.url))
12+
)

test/index.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import assert from 'node:assert/strict'
2-
import fs from 'node:fs'
3-
import path from 'node:path'
2+
import fs from 'node:fs/promises'
43
import test from 'tape'
54
import {slug} from 'github-slugger'
65
import {toHast} from 'mdast-util-to-hast'
@@ -11,55 +10,60 @@ import {gfm} from 'micromark-extension-gfm'
1110
import {gfmFromMarkdown, gfmToMarkdown} from '../index.js'
1211
import {spec} from './spec.js'
1312

14-
test('markdown -> mdast', (t) => {
13+
test('markdown -> mdast', async (t) => {
1514
const files = spec.filter(
1615
(example) => !/disallowed raw html/i.test(example.category)
1716
)
1817
let index = -1
1918

2019
while (++index < files.length) {
2120
const example = files[index]
22-
const category = slug(example.category)
23-
const name = index + '-' + category
24-
const fixtureHtmlPath = path.join('test', name + '.html')
25-
const fixtureMarkdownPath = path.join('test', name + '.md')
26-
21+
const name = index + '-' + slug(example.category)
2722
const mdast = fromMarkdown(example.input, {
2823
extensions: [gfm()],
2924
mdastExtensions: [gfmFromMarkdown()]
3025
})
3126

3227
const hast = toHast(mdast, {allowDangerousHtml: true})
3328
assert(hast, 'expected node')
34-
35-
const html = toHtml(hast, {
29+
const actualHtml = toHtml(hast, {
3630
allowDangerousHtml: true,
3731
entities: {useNamedReferences: true},
3832
closeSelfClosing: true
3933
})
4034

4135
/** @type {string} */
42-
let fixtureHtml
36+
let expectedHtml
4337
/** @type {string} */
44-
let fixtureMarkdown
38+
let expectedMarkdown
39+
const expectedUrl = new URL(name + '.html', import.meta.url)
40+
const inputUrl = new URL(name + '.md', import.meta.url)
4541

4642
try {
47-
fixtureHtml = String(fs.readFileSync(fixtureHtmlPath))
43+
expectedHtml = String(await fs.readFile(expectedUrl))
4844
} catch {
49-
fixtureHtml = example.output.slice(0, -1)
45+
expectedHtml = example.output.slice(0, -1)
5046
}
5147

52-
const md = toMarkdown(mdast, {extensions: [gfmToMarkdown()]})
48+
const actualMarkdown = toMarkdown(mdast, {extensions: [gfmToMarkdown()]})
5349

5450
try {
55-
fixtureMarkdown = String(fs.readFileSync(fixtureMarkdownPath))
51+
expectedMarkdown = String(await fs.readFile(inputUrl))
5652
} catch {
57-
fixtureMarkdown = md
58-
fs.writeFileSync(fixtureMarkdownPath, fixtureMarkdown)
53+
expectedMarkdown = actualMarkdown
54+
await fs.writeFile(inputUrl, expectedMarkdown)
5955
}
6056

61-
t.deepEqual(html, fixtureHtml, category + ' (' + index + ') -> html')
62-
t.equal(md, fixtureMarkdown, category + ' (' + index + ') -> md')
57+
t.deepEqual(
58+
actualHtml,
59+
expectedHtml,
60+
example.category + ' (' + index + ') -> html'
61+
)
62+
t.equal(
63+
actualMarkdown,
64+
expectedMarkdown,
65+
example.category + ' (' + index + ') -> md'
66+
)
6367
}
6468

6569
t.end()

0 commit comments

Comments
 (0)