@markuplint/markdown-parser 5.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +190 -0
- package/CHANGELOG.md +10 -0
- package/LICENSE +21 -0
- package/README.ja.md +47 -0
- package/README.md +47 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +6 -0
- package/lib/markdown-aware-parser.d.ts +179 -0
- package/lib/markdown-aware-parser.js +529 -0
- package/lib/parser.d.ts +40 -0
- package/lib/parser.js +91 -0
- package/package.json +39 -0
- package/src/index.spec.ts +747 -0
- package/src/index.ts +7 -0
- package/src/markdown-aware-parser.ts +656 -0
- package/src/parser.ts +109 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +17 -0
package/ARCHITECTURE.md
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# @markuplint/markdown-parser
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
`@markuplint/markdown-parser` parses Markdown (`.md`) files for markuplint. It converts both Markdown-native syntax and embedded HTML into markuplint's AST. Markdown constructs (headings, links, images, lists, emphasis, tables, etc.) are mapped to their equivalent HTML elements, enabling lint rules like `heading-levels`, `required-attr`, and `wai-aria` to work on Markdown content. Raw HTML regions are delegated to `HtmlParser`.
|
|
6
|
+
|
|
7
|
+
## Design Decisions
|
|
8
|
+
|
|
9
|
+
### Why `remark-parse` (unified ecosystem)?
|
|
10
|
+
|
|
11
|
+
| Approach | Pros | Cons | Verdict |
|
|
12
|
+
| ---------------------------- | ----------------------------------------------------------------------- | ----------------------------------------------------------------- | ---------- |
|
|
13
|
+
| **`remark-parse`** (unified) | De facto standard; mdast AST with position info; extensible via plugins | Adds unified ecosystem as dependency | **Chosen** |
|
|
14
|
+
| **`@mdx-js/mdx`** | Official MDX package | Wraps `remark-parse` internally; adds 24 unnecessary dependencies | Rejected |
|
|
15
|
+
| **`micromark`** (direct) | Maximum control; lowest level | Must build mdast conversion manually; no practical benefit | Rejected |
|
|
16
|
+
|
|
17
|
+
### Why extend `Parser` via `MarkdownAwareParser` (not `HtmlParser`)?
|
|
18
|
+
|
|
19
|
+
Earlier designs extended `HtmlParser` and treated Markdown as opaque psblock nodes. The current design extends `Parser<MdastNode>` through `MarkdownAwareParser` because:
|
|
20
|
+
|
|
21
|
+
1. **Markdown elements are now lintable** -- headings, links, images, etc. are converted to their HTML equivalents, enabling rule coverage
|
|
22
|
+
2. **Synthetic attributes** -- Markdown's `` produces `<img src="..." alt="...">` with synthesized attributes
|
|
23
|
+
3. **Shared base class** -- `MarkdownAwareParser` provides common Markdown-to-HTML conversion logic reused by `@markuplint/mdx-parser`
|
|
24
|
+
|
|
25
|
+
Raw HTML regions (CommonMark HTML blocks and inline HTML) are still parsed via a cached `HtmlParser` instance for full HTML support.
|
|
26
|
+
|
|
27
|
+
### Markdown elements as HTML equivalents
|
|
28
|
+
|
|
29
|
+
| Markdown Syntax | HTML Element | Attributes |
|
|
30
|
+
| ------------------- | -------------------------- | -------------------------------- |
|
|
31
|
+
| `# Heading` | `h1`-`h6` | -- |
|
|
32
|
+
| `[text](url)` | `a` | `href`, optionally `title` |
|
|
33
|
+
| `` | `img` | `src`, `alt`, optionally `title` |
|
|
34
|
+
| `*text*` / `_text_` | `em` | -- |
|
|
35
|
+
| `**text**` | `strong` | -- |
|
|
36
|
+
| `- item` | `ul` > `li` | -- |
|
|
37
|
+
| `1. item` | `ol` > `li` | `start` when != 1 |
|
|
38
|
+
| `> quote` | `blockquote` | -- |
|
|
39
|
+
| `` `code` `` | `code` | -- |
|
|
40
|
+
| ` ```lang ... ``` ` | `pre` > `code` | `class="language-{lang}"` |
|
|
41
|
+
| `---` | `hr` | -- |
|
|
42
|
+
| GFM `\| table \|` | `table` > `tr` > `th`/`td` | -- |
|
|
43
|
+
| GFM `~~text~~` | `del` | -- |
|
|
44
|
+
| `[text][ref]` | `a` | resolved from definitions |
|
|
45
|
+
| `![alt][ref]` | `img` | resolved from definitions |
|
|
46
|
+
|
|
47
|
+
### Synthetic attribute positions
|
|
48
|
+
|
|
49
|
+
Markdown syntax does not have discrete source positions for attributes. Synthesized attributes (e.g., `href` from `[text](url)`) point to the element's own token range. This is an intentional trade-off: markuplint can check attribute existence and values, but attribute-level source positions are approximate.
|
|
50
|
+
|
|
51
|
+
### blockquote and cite
|
|
52
|
+
|
|
53
|
+
The HTML `<blockquote>` element supports a `cite` attribute for source URLs, but Markdown's `> quote` syntax has no equivalent. The parser does not synthesize a `cite` attribute.
|
|
54
|
+
|
|
55
|
+
## How It Works
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
.md source file
|
|
59
|
+
|
|
|
60
|
+
v
|
|
61
|
+
[remark-parse + remark-gfm + remark-frontmatter]
|
|
62
|
+
| Parse Markdown into mdast AST
|
|
63
|
+
v
|
|
64
|
+
[collectDefinitions()] Extract [id]: url definitions
|
|
65
|
+
|
|
|
66
|
+
v
|
|
67
|
+
[nodeize() per mdast node]
|
|
68
|
+
|
|
|
69
|
+
+-- heading --> h1-h6 element with text children
|
|
70
|
+
+-- paragraph --> p element with inline children
|
|
71
|
+
+-- emphasis/strong --> em/strong elements
|
|
72
|
+
+-- link --> a element with href, title attrs
|
|
73
|
+
+-- image --> img element with src, alt, title attrs
|
|
74
|
+
+-- list/listItem --> ul/ol > li elements
|
|
75
|
+
+-- blockquote --> blockquote element
|
|
76
|
+
+-- inlineCode --> code element with text child
|
|
77
|
+
+-- code (fenced) --> pre > code elements
|
|
78
|
+
+-- table/row/cell --> table > tr > th/td elements
|
|
79
|
+
+-- delete (GFM) --> del element
|
|
80
|
+
+-- linkReference --> a element (resolved) or psblock
|
|
81
|
+
+-- imageReference --> img element (resolved) or psblock
|
|
82
|
+
+-- html --> HtmlParser.parse() with offset mapping
|
|
83
|
+
+-- text --> MLASTText
|
|
84
|
+
+-- yaml --> psblock (#ps:yaml)
|
|
85
|
+
+-- definition --> psblock
|
|
86
|
+
v
|
|
87
|
+
MLASTDocument Positions reference the original .md file
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Class Hierarchy
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
Parser<MdastNode> (from @markuplint/parser-utils)
|
|
94
|
+
|
|
|
95
|
+
MarkdownAwareParser (shared Markdown-to-HTML conversion)
|
|
96
|
+
| - createSyntheticAttr()
|
|
97
|
+
| - visitMarkdownElement()
|
|
98
|
+
| - visitLinkElement() / visitImageElement()
|
|
99
|
+
| - visitListElement() / visitCodeBlock()
|
|
100
|
+
| - visitTableElement()
|
|
101
|
+
| - nodeizeMarkdownNode()
|
|
102
|
+
| - collectDefinitions()
|
|
103
|
+
|
|
|
104
|
+
MarkdownParser (this package)
|
|
105
|
+
| - tokenize(): remark-parse + remark-gfm
|
|
106
|
+
| - nodeize(): delegates then handles html/text/yaml
|
|
107
|
+
| - #htmlParser: cached HtmlParser for HTML regions
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### GFM Table Header Detection
|
|
111
|
+
|
|
112
|
+
GFM tables use the first row as the header row. The parser tracks this via:
|
|
113
|
+
|
|
114
|
+
1. `visitTableElement()` records the first row's source offset in `#headerRowOffsets`
|
|
115
|
+
2. `nodeizeMarkdownNode()` for `tableRow` checks the offset set to decide `th` vs `td`
|
|
116
|
+
3. The set is consumed (deleted) after use, so subsequent rows produce `td` cells
|
|
117
|
+
|
|
118
|
+
### Link/Image Reference Resolution
|
|
119
|
+
|
|
120
|
+
1. `tokenize()` calls `collectDefinitions()` to build a `Map<identifier, Definition>`
|
|
121
|
+
2. `nodeizeMarkdownNode()` dispatches `linkReference`/`imageReference` to resolution methods
|
|
122
|
+
3. Resolved references produce `<a>` or `<img>` elements; unresolved ones become psblock nodes
|
|
123
|
+
4. Note: remark-parse resolves references at parse time when definitions exist, so unresolved references typically appear as plain text rather than `linkReference` nodes
|
|
124
|
+
|
|
125
|
+
## Architecture Diagram
|
|
126
|
+
|
|
127
|
+
```mermaid
|
|
128
|
+
flowchart TD
|
|
129
|
+
subgraph upstream ["Upstream"]
|
|
130
|
+
parserUtils["@markuplint/parser-utils\n(Parser base class)"]
|
|
131
|
+
htmlParser["@markuplint/html-parser\n(HtmlParser for HTML regions)"]
|
|
132
|
+
remark["remark-parse\n(Markdown -> mdast)"]
|
|
133
|
+
remarkGfm["remark-gfm\n(GFM tables, strikethrough)"]
|
|
134
|
+
remarkFm["remark-frontmatter\n(Front matter support)"]
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
subgraph pkg ["@markuplint/markdown-parser"]
|
|
138
|
+
aware["MarkdownAwareParser\nextends Parser<MdastNode>"]
|
|
139
|
+
mdParser["MarkdownParser\nextends MarkdownAwareParser"]
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
subgraph downstream ["Downstream"]
|
|
143
|
+
mdxParser["@markuplint/mdx-parser\n(reuses MarkdownAwareParser)"]
|
|
144
|
+
mlCore["@markuplint/ml-core\n(MLASTDocument -> MLDOM)"]
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
parserUtils -->|"base class"| aware
|
|
148
|
+
remark -->|"mdast AST"| mdParser
|
|
149
|
+
remarkGfm -->|"GFM extensions"| mdParser
|
|
150
|
+
remarkFm -->|"front matter"| mdParser
|
|
151
|
+
htmlParser -->|"HTML region parsing"| mdParser
|
|
152
|
+
aware -->|"extends"| mdParser
|
|
153
|
+
aware -->|"shared base"| mdxParser
|
|
154
|
+
mdParser -->|"MLASTDocument"| mlCore
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## External Dependencies
|
|
158
|
+
|
|
159
|
+
| Dependency | Purpose |
|
|
160
|
+
| -------------------------- | -------------------------------------- |
|
|
161
|
+
| `@markuplint/html-parser` | Parses raw HTML regions in Markdown |
|
|
162
|
+
| `@markuplint/ml-ast` | AST type definitions |
|
|
163
|
+
| `@markuplint/parser-utils` | Parser base class, token utilities |
|
|
164
|
+
| `unified` | Processor pipeline for remark |
|
|
165
|
+
| `remark-parse` | Markdown -> mdast parser |
|
|
166
|
+
| `remark-gfm` | GFM extensions (tables, strikethrough) |
|
|
167
|
+
| `remark-frontmatter` | Front matter (YAML) support in mdast |
|
|
168
|
+
|
|
169
|
+
## Directory Structure
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
src/
|
|
173
|
+
+-- index.ts -- Re-exports parser instance and MarkdownAwareParser
|
|
174
|
+
+-- parser.ts -- MarkdownParser class
|
|
175
|
+
+-- markdown-aware-parser.ts -- MarkdownAwareParser shared base class
|
|
176
|
+
+-- index.spec.ts -- Unit and integration tests
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Relationship to @markuplint/mdx-parser
|
|
180
|
+
|
|
181
|
+
Both parsers share `MarkdownAwareParser` as a common base class. The key differences:
|
|
182
|
+
|
|
183
|
+
| Aspect | markdown-parser (.md) | mdx-parser (.mdx) |
|
|
184
|
+
| --------------- | -------------------------- | ---------------------------------- |
|
|
185
|
+
| Base class | MarkdownAwareParser | MarkdownAwareParser |
|
|
186
|
+
| HTML regions | HtmlParser re-parse | parseCodeFragment (XML-style) |
|
|
187
|
+
| JSX support | No | Yes (components, expressions, ESM) |
|
|
188
|
+
| Attribute style | HTML (`class`, `for`) | JSX (`className`, `htmlFor`) |
|
|
189
|
+
| Tag closing | HTML rules (void elements) | XML rules (self-closing required) |
|
|
190
|
+
| Spec package | None needed | `@markuplint/react-spec` |
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# [5.0.0-alpha.0](https://github.com/markuplint/markuplint/compare/v4.14.1...v5.0.0-alpha.0) (2026-02-20)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **markdown-parser:** add Markdown parser for markuplint ([cc30558](https://github.com/markuplint/markuplint/commit/cc3055816f1fad56ba4691df445865f3f82dc500))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-2024 Yusuke Hirao
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.ja.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @markuplint/markdown-parser
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@markuplint/markdown-parser)
|
|
4
|
+
|
|
5
|
+
**Markdown** ファイルで **markuplint** を使用するためのパーサーです。
|
|
6
|
+
|
|
7
|
+
Markdown 構文(見出し、リンク、画像、リスト、テーブルなど)を対応する HTML 要素に変換し、markuplint のルールで解析できるようにします。[GFM](https://github.github.com/gfm/)(テーブル、取り消し線、オートリンク)および YAML フロントマターをサポートしています。
|
|
8
|
+
|
|
9
|
+
## インストール
|
|
10
|
+
|
|
11
|
+
```shell
|
|
12
|
+
$ npm install -D @markuplint/markdown-parser
|
|
13
|
+
|
|
14
|
+
$ yarn add -D @markuplint/markdown-parser
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 使い方
|
|
18
|
+
|
|
19
|
+
[設定ファイル](https://markuplint.dev/configuration/#properties/parser)に `parser` オプションを追加してください。
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"parser": {
|
|
24
|
+
".md$": "@markuplint/markdown-parser"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 対応構文
|
|
30
|
+
|
|
31
|
+
| Markdown | HTML |
|
|
32
|
+
| ------------------------------------- | ---------------------------- |
|
|
33
|
+
| `# 見出し` | `<h1>` – `<h6>` |
|
|
34
|
+
| `[テキスト](url)` / `[テキスト][ref]` | `<a href="...">` |
|
|
35
|
+
| `` / `![alt][ref]` | `<img src="..." alt="...">` |
|
|
36
|
+
| `- アイテム` / `1. アイテム` | `<ul>` / `<ol>` と `<li>` |
|
|
37
|
+
| `` `コード` `` | `<code>` |
|
|
38
|
+
| フェンスコードブロック | `<pre><code>` |
|
|
39
|
+
| `> 引用` | `<blockquote>` |
|
|
40
|
+
| GFM テーブル | `<table>` と `<th>` / `<td>` |
|
|
41
|
+
| `~~テキスト~~` | `<del>` |
|
|
42
|
+
| `---` | `<hr>` |
|
|
43
|
+
| 生 HTML | HTML としてパース |
|
|
44
|
+
|
|
45
|
+
## 既知の制限事項
|
|
46
|
+
|
|
47
|
+
- **合成された属性位置**: Markdown 構文から導出された属性(例: `[テキスト](url)` の `href`)は、属性値の正確な文字位置ではなく、Markdown 構文全体のソース位置を共有します。
|
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @markuplint/markdown-parser
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@markuplint/markdown-parser)
|
|
4
|
+
|
|
5
|
+
Use **markuplint** with **Markdown** files.
|
|
6
|
+
|
|
7
|
+
Converts Markdown constructs (headings, links, images, lists, tables, etc.) to their corresponding HTML elements so that markuplint rules can analyze them. Supports [GFM](https://github.github.com/gfm/) (tables, strikethrough, autolinks) and YAML frontmatter.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```shell
|
|
12
|
+
$ npm install -D @markuplint/markdown-parser
|
|
13
|
+
|
|
14
|
+
$ yarn add -D @markuplint/markdown-parser
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Add `parser` option to your [configuration](https://markuplint.dev/configuration/#properties/parser).
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"parser": {
|
|
24
|
+
".md$": "@markuplint/markdown-parser"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Supported Syntax
|
|
30
|
+
|
|
31
|
+
| Markdown | HTML |
|
|
32
|
+
| ----------------------------- | ------------------------------ |
|
|
33
|
+
| `# Heading` | `<h1>` – `<h6>` |
|
|
34
|
+
| `[text](url)` / `[text][ref]` | `<a href="...">` |
|
|
35
|
+
| `` / `![alt][ref]` | `<img src="..." alt="...">` |
|
|
36
|
+
| `- item` / `1. item` | `<ul>` / `<ol>` with `<li>` |
|
|
37
|
+
| `` `code` `` | `<code>` |
|
|
38
|
+
| Fenced code block | `<pre><code>` |
|
|
39
|
+
| `> quote` | `<blockquote>` |
|
|
40
|
+
| GFM table | `<table>` with `<th>` / `<td>` |
|
|
41
|
+
| `~~text~~` | `<del>` |
|
|
42
|
+
| `---` | `<hr>` |
|
|
43
|
+
| Raw HTML | Parsed as HTML |
|
|
44
|
+
|
|
45
|
+
## Known Limitations
|
|
46
|
+
|
|
47
|
+
- **Synthesized attribute positions**: Attributes derived from Markdown syntax (e.g., `href` from `[text](url)`) share the source position of the enclosing Markdown construct rather than pointing to the exact character range of the attribute value.
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type { MLASTAttr, MLASTHTMLAttr, MLASTNodeTreeItem, MLASTParentNode } from '@markuplint/ml-ast';
|
|
2
|
+
import type { ParserOptions, Token } from '@markuplint/parser-utils';
|
|
3
|
+
import type { Code, Definition, Image, InlineCode, Link, List, RootContent, Table } from 'mdast';
|
|
4
|
+
import { Parser } from '@markuplint/parser-utils';
|
|
5
|
+
type MdastNode = RootContent;
|
|
6
|
+
/**
|
|
7
|
+
* Abstract base class for parsers that handle Markdown content.
|
|
8
|
+
*
|
|
9
|
+
* Provides shared logic for converting mdast nodes (headings, links, images,
|
|
10
|
+
* lists, code, tables, etc.) into markuplint's AST. Both MarkdownParser and
|
|
11
|
+
* MDXParser extend this class to avoid code duplication.
|
|
12
|
+
*/
|
|
13
|
+
export declare abstract class MarkdownAwareParser extends Parser<MdastNode> {
|
|
14
|
+
#private;
|
|
15
|
+
/**
|
|
16
|
+
* Stores link/image reference definitions (`[id]: url "title"`)
|
|
17
|
+
* extracted during tokenization for resolving linkReference/imageReference nodes.
|
|
18
|
+
*/
|
|
19
|
+
protected definitions: Map<string, Definition>;
|
|
20
|
+
constructor(options?: ParserOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Resets mutable state accumulated during a previous `parse()` call.
|
|
23
|
+
*
|
|
24
|
+
* Must be called at the beginning of every `tokenize()` invocation to
|
|
25
|
+
* prevent definitions, header-row offsets, and cell-name state from
|
|
26
|
+
* leaking across successive `parse()` calls on the same parser instance.
|
|
27
|
+
*/
|
|
28
|
+
protected resetMarkdownState(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Adjusts the flattened node list for Markdown output.
|
|
31
|
+
*
|
|
32
|
+
* Disables whitespace and invalid-node exposure because Markdown
|
|
33
|
+
* generates only synthetic elements with no real HTML whitespace tokens.
|
|
34
|
+
*
|
|
35
|
+
* @param nodeList - The flattened node tree produced by the base class.
|
|
36
|
+
* @returns The adjusted node list.
|
|
37
|
+
*/
|
|
38
|
+
afterFlattenNodes(nodeList: readonly MLASTNodeTreeItem[]): readonly MLASTNodeTreeItem[];
|
|
39
|
+
/**
|
|
40
|
+
* Creates a synthetic HTML attribute token for Markdown-derived elements.
|
|
41
|
+
*
|
|
42
|
+
* The attribute positions point to the element's own token range because
|
|
43
|
+
* Markdown syntax does not have discrete attribute source positions.
|
|
44
|
+
*
|
|
45
|
+
* @param name - The attribute name (e.g., `"href"`, `"alt"`).
|
|
46
|
+
* @param value - The attribute value extracted from Markdown syntax.
|
|
47
|
+
* @param token - The source token whose position is reused for the attribute.
|
|
48
|
+
* @returns A fully-formed HTML attribute node.
|
|
49
|
+
*/
|
|
50
|
+
protected createSyntheticAttr(name: string, value: string, token: Token): MLASTHTMLAttr;
|
|
51
|
+
/**
|
|
52
|
+
* Builds a generic HTML element node from a Markdown construct.
|
|
53
|
+
*
|
|
54
|
+
* @param token - The source token covering the entire construct.
|
|
55
|
+
* @param nodeName - The HTML element name (e.g., `"p"`, `"h1"`, `"li"`).
|
|
56
|
+
* @param childNodes - The mdast children to recurse into.
|
|
57
|
+
* @param depth - Current nesting depth in the AST.
|
|
58
|
+
* @param parentNode - Parent AST node, or `null` for top-level nodes.
|
|
59
|
+
* @param attributes - Optional pre-built attributes to attach.
|
|
60
|
+
* @returns The element node followed by its descendants.
|
|
61
|
+
*/
|
|
62
|
+
protected visitMarkdownElement(token: Token, nodeName: string, childNodes: readonly MdastNode[], depth: number, parentNode: MLASTParentNode | null, attributes?: readonly MLASTAttr[]): readonly MLASTNodeTreeItem[];
|
|
63
|
+
/**
|
|
64
|
+
* Builds an `<a>` element with `href` (and optionally `title`) attributes.
|
|
65
|
+
*
|
|
66
|
+
* @param originNode - The mdast `link` node.
|
|
67
|
+
* @param token - The source token covering the link.
|
|
68
|
+
* @param depth - Current nesting depth.
|
|
69
|
+
* @param parentNode - Parent AST node, or `null` for top-level.
|
|
70
|
+
* @returns The `<a>` element node and its descendants.
|
|
71
|
+
*/
|
|
72
|
+
protected visitLinkElement(originNode: Link, token: Token, depth: number, parentNode: MLASTParentNode | null): readonly MLASTNodeTreeItem[];
|
|
73
|
+
/**
|
|
74
|
+
* Builds an `<img>` element with `src`, `alt`, and optionally `title` attributes.
|
|
75
|
+
*
|
|
76
|
+
* @param originNode - The mdast `image` node.
|
|
77
|
+
* @param token - The source token covering the image.
|
|
78
|
+
* @param depth - Current nesting depth.
|
|
79
|
+
* @param parentNode - Parent AST node, or `null` for top-level.
|
|
80
|
+
* @returns The `<img>` element node.
|
|
81
|
+
*/
|
|
82
|
+
protected visitImageElement(originNode: Image, token: Token, depth: number, parentNode: MLASTParentNode | null): readonly MLASTNodeTreeItem[];
|
|
83
|
+
/**
|
|
84
|
+
* Builds a `<ul>` or `<ol>` element. Adds a `start` attribute when the
|
|
85
|
+
* ordered list begins at a number other than 1.
|
|
86
|
+
*
|
|
87
|
+
* @param originNode - The mdast `list` node.
|
|
88
|
+
* @param token - The source token covering the list.
|
|
89
|
+
* @param depth - Current nesting depth.
|
|
90
|
+
* @param parentNode - Parent AST node, or `null` for top-level.
|
|
91
|
+
* @returns The list element node and its descendants.
|
|
92
|
+
*/
|
|
93
|
+
protected visitListElement(originNode: List, token: Token, depth: number, parentNode: MLASTParentNode | null): readonly MLASTNodeTreeItem[];
|
|
94
|
+
/**
|
|
95
|
+
* Builds a `<code>` element for inline code spans (backtick-delimited).
|
|
96
|
+
*
|
|
97
|
+
* @param originNode - The mdast `inlineCode` node.
|
|
98
|
+
* @param token - The source token covering the code span.
|
|
99
|
+
* @param offset - Start offset in the original source.
|
|
100
|
+
* @param endOffset - End offset in the original source.
|
|
101
|
+
* @param depth - Current nesting depth.
|
|
102
|
+
* @param parentNode - Parent AST node, or `null` for top-level.
|
|
103
|
+
* @returns The `<code>` element node (with a text child when content is found).
|
|
104
|
+
*/
|
|
105
|
+
protected visitInlineCode(originNode: InlineCode, token: Token, offset: number, endOffset: number, depth: number, parentNode: MLASTParentNode | null): readonly MLASTNodeTreeItem[];
|
|
106
|
+
/**
|
|
107
|
+
* Builds a `<pre><code>` structure for fenced code blocks.
|
|
108
|
+
* When a language is specified, adds `class="language-{lang}"` to the `<code>` element.
|
|
109
|
+
*
|
|
110
|
+
* @param originNode - The mdast `code` node.
|
|
111
|
+
* @param token - The source token covering the fenced block.
|
|
112
|
+
* @param depth - Current nesting depth.
|
|
113
|
+
* @param parentNode - Parent AST node, or `null` for top-level.
|
|
114
|
+
* @returns The `<pre>` and `<code>` element nodes.
|
|
115
|
+
*/
|
|
116
|
+
protected visitCodeBlock(originNode: Code, token: Token, depth: number, parentNode: MLASTParentNode | null): readonly MLASTNodeTreeItem[];
|
|
117
|
+
/**
|
|
118
|
+
* Builds a `<table>` element from a GFM table node.
|
|
119
|
+
* Marks the first row's offset as a header row so that its cells become `<th>`.
|
|
120
|
+
*
|
|
121
|
+
* @param originNode - The mdast `table` node (GFM extension).
|
|
122
|
+
* @param token - The source token covering the table.
|
|
123
|
+
* @param depth - Current nesting depth.
|
|
124
|
+
* @param parentNode - Parent AST node, or `null` for top-level.
|
|
125
|
+
* @returns The `<table>` element node and its descendants.
|
|
126
|
+
*/
|
|
127
|
+
protected visitTableElement(originNode: Table, token: Token, depth: number, parentNode: MLASTParentNode | null): readonly MLASTNodeTreeItem[];
|
|
128
|
+
/**
|
|
129
|
+
* Dispatches a single mdast node to the appropriate visit method.
|
|
130
|
+
*
|
|
131
|
+
* @param originNode - The mdast node to convert.
|
|
132
|
+
* @param token - The source token covering the node's range.
|
|
133
|
+
* @param offset - Start offset in the original source.
|
|
134
|
+
* @param endOffset - End offset in the original source.
|
|
135
|
+
* @param depth - Current nesting depth.
|
|
136
|
+
* @param parentNode - Parent AST node, or `null` for top-level nodes.
|
|
137
|
+
* @returns An array of AST nodes for recognized Markdown constructs,
|
|
138
|
+
* or `null` when the node type is not handled here (the caller is
|
|
139
|
+
* responsible for handling it — typically `text`, `html`, or
|
|
140
|
+
* parser-specific node types).
|
|
141
|
+
*/
|
|
142
|
+
protected nodeizeMarkdownNode(originNode: MdastNode, token: Token, offset: number, endOffset: number, depth: number, parentNode: MLASTParentNode | null): readonly MLASTNodeTreeItem[] | null;
|
|
143
|
+
/**
|
|
144
|
+
* Resolves a linkReference using collected definitions, producing an `<a>` element.
|
|
145
|
+
* Falls back to a psblock when the definition is not found.
|
|
146
|
+
*/
|
|
147
|
+
private visitLinkReference;
|
|
148
|
+
/**
|
|
149
|
+
* Resolves an imageReference using collected definitions, producing an `<img>` element.
|
|
150
|
+
* Falls back to a psblock when the definition is not found.
|
|
151
|
+
*/
|
|
152
|
+
private visitImageReference;
|
|
153
|
+
/**
|
|
154
|
+
* Extracts definition nodes from mdast children and populates `this.definitions`.
|
|
155
|
+
*
|
|
156
|
+
* Per CommonMark spec, the first definition for a given identifier takes
|
|
157
|
+
* precedence. remark-parse emits all definition nodes in source order, so
|
|
158
|
+
* we skip duplicates via `Map.has` to honour the first-wins rule.
|
|
159
|
+
*
|
|
160
|
+
* @param children - The root-level mdast children to scan for `definition` nodes.
|
|
161
|
+
*/
|
|
162
|
+
protected collectDefinitions(children: readonly RootContent[]): void;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Computes the 1-based line number and 1-based column for a given offset.
|
|
166
|
+
*
|
|
167
|
+
* Equivalent to `getPosition()` in `@markuplint/parser-utils`, but that
|
|
168
|
+
* function is not exported from the package. Kept as a standalone utility
|
|
169
|
+
* to avoid coupling to parser-utils internals.
|
|
170
|
+
*
|
|
171
|
+
* @param source - The full source string.
|
|
172
|
+
* @param offset - The 0-based character offset to resolve.
|
|
173
|
+
* @returns An object with 1-based `line` and `col` values.
|
|
174
|
+
*/
|
|
175
|
+
export declare function getLineAndColumn(source: string, offset: number): {
|
|
176
|
+
line: number;
|
|
177
|
+
col: number;
|
|
178
|
+
};
|
|
179
|
+
export {};
|