Skip to content

Commit

Permalink
Update micromark, change buffers to Uint8Arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 8, 2023
1 parent 662d0cd commit 12a5622
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 24 deletions.
8 changes: 2 additions & 6 deletions dev/lib/index.js
Expand Up @@ -146,15 +146,11 @@

import {ok as assert} from 'uvu/assert'
import {toString} from 'mdast-util-to-string'
import {parse} from 'micromark/lib/parse.js'
import {preprocess} from 'micromark/lib/preprocess.js'
import {postprocess} from 'micromark/lib/postprocess.js'
import {parse, postprocess, preprocess} from 'micromark'
import {decodeNumericCharacterReference} from 'micromark-util-decode-numeric-character-reference'
import {decodeString} from 'micromark-util-decode-string'
import {normalizeIdentifier} from 'micromark-util-normalize-identifier'
import {codes} from 'micromark-util-symbol/codes.js'
import {constants} from 'micromark-util-symbol/constants.js'
import {types} from 'micromark-util-symbol/types.js'
import {codes, constants, types} from 'micromark-util-symbol'
import {decodeNamedCharacterReference} from 'decode-named-character-reference'
import {stringifyPosition} from 'unist-util-stringify-position'

Expand Down
14 changes: 7 additions & 7 deletions package.json
Expand Up @@ -45,12 +45,12 @@
"@types/unist": "^2.0.0",
"decode-named-character-reference": "^1.0.0",
"mdast-util-to-string": "^3.1.0",
"micromark": "^3.0.0",
"micromark-util-decode-numeric-character-reference": "^1.0.0",
"micromark-util-decode-string": "^1.0.0",
"micromark-util-normalize-identifier": "^1.0.0",
"micromark-util-symbol": "^1.0.0",
"micromark-util-types": "^1.0.0",
"micromark": "^4.0.0",
"micromark-util-decode-numeric-character-reference": "^2.0.0",
"micromark-util-decode-string": "^2.0.0",
"micromark-util-normalize-identifier": "^2.0.0",
"micromark-util-symbol": "^2.0.0",
"micromark-util-types": "^2.0.0",
"unist-util-stringify-position": "^3.0.0",
"uvu": "^0.5.0"
},
Expand All @@ -63,7 +63,7 @@
"hast-util-from-html": "^1.0.0",
"hast-util-to-html": "^8.0.0",
"mdast-util-to-hast": "^12.0.0",
"micromark-build": "^1.0.0",
"micromark-build": "^2.0.0",
"prettier": "^2.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
Expand Down
10 changes: 5 additions & 5 deletions readme.md
Expand Up @@ -150,8 +150,8 @@ Turn markdown into a syntax tree.
* `value` ([`Value`][api-value])
— markdown to parse
* `encoding` ([`Encoding`][api-encoding], default: `'utf8'`)
[character encoding][character-encoding] for when `value` is
[`Buffer`][buffer]
[character encoding][encoding] for when `value` is
[`Uint8Array`][uint8-array]
* `options` ([`Options`][api-options], optional)
— configuration

Expand Down Expand Up @@ -210,7 +210,7 @@ declare module 'mdast-util-from-markdown' {

### `Encoding`

Encodings supported by the [`Buffer`][buffer] class (TypeScript type).
Encodings supported by the [`Uint8Array`][uint8-array] class (TypeScript type).

<!-- To do: link to micromark type, when documented. -->

Expand Down Expand Up @@ -499,9 +499,9 @@ abide by its terms.
[root]: https://github.com/syntax-tree/mdast#root
[character-encoding]: https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings
[uint8-array]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
[buffer]: https://nodejs.org/api/buffer.html
[encoding]: https://nodejs.org/api/util.html#whatwg-supported-encodings
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
Expand Down
27 changes: 21 additions & 6 deletions test/index.js
Expand Up @@ -3,7 +3,6 @@
*/

import assert from 'node:assert/strict'
import {Buffer} from 'node:buffer'
import fs from 'node:fs/promises'
import test from 'node:test'
import {toHast} from 'mdast-util-to-hast'
Expand Down Expand Up @@ -65,17 +64,33 @@ test('fromMarkdown', () => {
'should parse a paragraph'
)

assert.deepEqual(
fromMarkdown(new Uint8Array()),
{
type: 'root',
children: [],
position: {
start: {line: 1, column: 1, offset: 0},
end: {line: 1, column: 1, offset: 0}
}
},
'should support empty typed arrays'
)

assert.equal(
toString(fromMarkdown(Buffer.from([0x62, 0x72, 0xc3, 0xa1, 0x76, 0x6f]))),
'brávo',
'should support buffers'
toString(fromMarkdown(new TextEncoder().encode('<admin@example.com>'))),
'admin@example.com',
'should support types arrays'
)

assert.equal(
toString(
fromMarkdown(Buffer.from([0x62, 0x72, 0xc3, 0xa1, 0x76, 0x6f]), 'ascii')
fromMarkdown(
new Uint8Array([0xff, 0xfe, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00]),
'utf-16le'
)
),
'brC!vo',
'abc',
'should support encoding'
)

Expand Down

0 comments on commit 12a5622

Please sign in to comment.