Skip to content

Commit 5c143e0

Browse files
authored
🤖 Merge PR DefinitelyTyped#75392 [markdown-it] Improve compatibility/compliant with 14.1.0+ (including 15's built-in types) by @tats-u
1 parent 0033158 commit 5c143e0

4 files changed

Lines changed: 72 additions & 12 deletions

File tree

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
1-
export { default, Options, PluginSimple, PluginWithOptions, PluginWithParams, PresetName } from "./lib/index.mjs";
1+
export {
2+
default,
3+
type default as MarkdownIt,
4+
Options,
5+
type Options as MarkdownItOptions,
6+
PluginSimple,
7+
PluginWithOptions,
8+
PluginWithParams,
9+
PresetName,
10+
type PresetName as MarkdownItPresetName,
11+
} from "./lib/index.mjs";
12+
export type { default as ParserBlock } from "./lib/parser_block.mts";
13+
export type { default as ParserCore } from "./lib/parser_core.mts";
14+
export type { default as ParserInline } from "./lib/parser_inline.mts";
15+
export type { default as Renderer, RenderRule as RendererRule } from "./lib/renderer.mts";
16+
export type { default as Ruler } from "./lib/ruler.mts";
17+
export type { default as StateBlock } from "./lib/rules_block/state_block.mts";
18+
export type { default as StateCore } from "./lib/rules_core/state_core.mts";
19+
export type { default as StateInline, Delimiter } from "./lib/rules_inline/state_inline.mts";
20+
export type { default as Token } from "./lib/token.mts";

‎types/markdown-it/lib/common/utils.d.mts‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,37 @@ export function isSpace(code: number): boolean;
3939
export function isWhiteSpace(code: number): boolean;
4040

4141
/**
42-
* Markdown ASCII punctuation characters.
42+
* Markdown [ASCII punctuation characters](https://spec.commonmark.org/0.31.2/#ascii-punctuation-character).
4343
*
44-
* !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \, ], ^, _, `, {, |, }, or ~
44+
* !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, \@, [, \\, ], ^, _, `, {, |, }, or ~
4545
*
46-
* Don't confuse with unicode punctuation !!! It lacks some chars in ascii range.
46+
* {@link isPunctChar} is missing some ASCII punctuation chars in < 14.1.0.
47+
* This is consistent with CommonMark 0.30 and older behavior, where the range of ASCII punctuation
48+
* characters was not fully contained in that of
49+
* [Unicode punctuation characters](https://spec.commonmark.org/0.31.2/#unicode-punctuation-character).
4750
*
48-
* @see http://spec.commonmark.org/0.15/#ascii-punctuation-character
51+
* In >= 14.1.0 (compliant with CommonMark 0.31.2), {@link isPunctChar} includes all ASCII punctuation characters,
52+
* so combining {@link isMdAsciiPunct} with {@link isPunctChar} is only for backwards compatibility or
53+
* to try to provide a fast path for ASCII ranges.
54+
*
55+
* @see https://spec.commonmark.org/0.31.2/changes.html#part-4
4956
*/
5057
export function isMdAsciiPunct(code: number): boolean;
5158

5259
/**
53-
* Currently without astral characters support.
60+
* [Unicode punctuation characters](https://spec.commonmark.org/0.31.2/#unicode-punctuation-character).
61+
*
62+
* Astral (supplementary) characters support requires >= 14.2.0.
5463
*/
5564
export function isPunctChar(ch: string): boolean;
5665

66+
/**
67+
* [Unicode punctuation characters](https://spec.commonmark.org/0.31.2/#unicode-punctuation-character).
68+
*
69+
* Added in 14.2.0. Supports astral (supplementary) characters.
70+
*/
71+
export function isPunctCharCode(code: number): boolean;
72+
5773
export function escapeRE(str: string): string;
5874

5975
/**

‎types/markdown-it/markdown-it-tests.mts‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,22 @@ import LinkifyIt from "linkify-it";
44
import MarkdownIt, { Options, PresetName } from "markdown-it";
55
// eslint-disable-next-line no-duplicate-imports
66
import MarkdownIt1 from "markdown-it";
7+
// eslint-disable-next-line no-duplicate-imports
8+
import type {
9+
Delimiter,
10+
MarkdownIt as MarkdownIt2,
11+
MarkdownItOptions as Options2,
12+
MarkdownItPresetName as PresetName2,
13+
Renderer,
14+
StateBlock,
15+
StateCore,
16+
StateInline,
17+
Token,
18+
} from "markdown-it";
719
import { RuleBlock } from "markdown-it/lib/parser_block.mjs";
820
import { RuleCore } from "markdown-it/lib/parser_core.mjs";
921
import { RuleInline, RuleInline2 } from "markdown-it/lib/parser_inline.mjs";
10-
import Renderer from "markdown-it/lib/renderer.mjs";
11-
import StateBlock from "markdown-it/lib/rules_block/state_block.mjs";
12-
import StateCore from "markdown-it/lib/rules_core/state_core.mjs";
13-
import StateInline, { Delimiter, Scanned, TokenMeta } from "markdown-it/lib/rules_inline/state_inline.mjs";
14-
import Token from "markdown-it/lib/token.mjs";
22+
import { Scanned, TokenMeta } from "markdown-it/lib/rules_inline/state_inline.mjs";
1523

1624
// stub highlight-js interaction
1725
declare const hljs: {
@@ -519,3 +527,20 @@ let md: MarkdownIt;
519527
const href: string | null = token.attrGet("href");
520528
token.attrJoin("class", "foobar");
521529
}
530+
531+
{
532+
// Minimal compatibility with built-in types in v15
533+
534+
const options: Options2 = { html: true, linkify: true };
535+
const preset: PresetName2 = "default";
536+
537+
const md2: MarkdownIt2 = new MarkdownIt();
538+
const md3: MarkdownIt2 = new MarkdownIt(options);
539+
const md4: MarkdownIt2 = new MarkdownIt(preset);
540+
const md5: MarkdownIt2 = new MarkdownIt(preset, options);
541+
542+
md2.render("# Example");
543+
md3.renderInline("**Example**");
544+
md4.render("[link](https://example.com)");
545+
md5.render("---\n\nA paragraph");
546+
}

‎types/markdown-it/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/markdown-it",
4-
"version": "14.1.9999",
4+
"version": "14.2.9999",
55
"projects": [
66
"https://github.com/markdown-it/markdown-it"
77
],

0 commit comments

Comments
 (0)