diff --git a/dev/lib/index.js b/dev/lib/index.js index cb4cd18..d8e61ce 100644 --- a/dev/lib/index.js +++ b/dev/lib/index.js @@ -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' diff --git a/package.json b/package.json index 41e027f..aeb51f5 100644 --- a/package.json +++ b/package.json @@ -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" }, @@ -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", diff --git a/readme.md b/readme.md index bbf7ade..9be48d1 100644 --- a/readme.md +++ b/readme.md @@ -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 @@ -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). @@ -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 diff --git a/test/index.js b/test/index.js index 7290d45..0704d65 100644 --- a/test/index.js +++ b/test/index.js @@ -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' @@ -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', + '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' )