Repository navigation
feat: add remark-directive support for directive syntax - #11
Conversation
|
hi @3w36zj6 . thanks for working on that plugin. |
There was a problem hiding this comment.
Pull request overview
This PR adds remark-directive support to the textlint MDX plugin, enabling proper parsing of CommonMark directive syntax (e.g., :abbr[HTML]{title="..."}, ::youtube[...]{}, :::note[...]) that would otherwise cause parse errors when remark-mdx tries to interpret {...} attribute blocks as JavaScript expressions.
Changes:
- Integrates
remark-directiveinto the unified pipeline and adds three new AST node types (TextDirective,LeafDirective,ContainerDirective) to the syntax map - Handles directive node cleanup during AST traversal by stripping remark-directive–specific properties (
name,attributes,data) - Adds test fixtures for all three directive types
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/parse.ts |
Adds remark-directive to the remark pipeline and handles directive node type mapping/cleanup during AST traversal |
src/mapping/markdown-syntax-map.ts |
Adds textDirective, leafDirective, and containerDirective mappings to custom textlint AST types |
package.json |
Adds remark-directive as a devDependency |
test/fixtures/textDirective/* |
Test fixture for inline text directive (:abbr[HTML]{...}) |
test/fixtures/leafDirective/* |
Test fixture for leaf directive (::youtube[...]{...}) |
test/fixtures/containerDirective/* |
Test fixture for container directive (:::note[...]) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
This PR adds remark-directive support to the textlint MDX plugin, solving parse errors when directive syntax (e.g., ::directive[foo]{bar=baz}) is used in MDX files. The {...} attribute block was previously misinterpreted as an MDX/JSX expression, causing failures.
Changes:
- Integrates
remark-directiveinto the remark pipeline (beforeremark-mdx) so directive nodes are parsed correctly - Maps three directive node types (
textDirective,leafDirective,containerDirective) to custom textlint AST types and strips directive-specific properties - Adds test fixtures for all three directive types
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
package.json |
Adds remark-directive ^4.0.0 as a devDependency (bundled via esbuild) |
src/parse.ts |
Imports remark-directive, adds it to the unified pipeline, and handles directive node type mapping and property stripping |
src/mapping/markdown-syntax-map.ts |
Adds syntax map entries for the three directive types |
test/fixtures/textDirective/* |
Test fixture for inline text directives |
test/fixtures/leafDirective/* |
Test fixture for leaf (block) directives |
test/fixtures/containerDirective/* |
Test fixture for container directives with content |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
This PR adds remark-directive support to the textlint MDX plugin, allowing directive syntax (:text, ::leaf, :::container) to be parsed correctly instead of failing when remark-mdx tries to interpret {attributes} as JavaScript expressions.
Changes:
- Integrates
remark-directiveinto the remark pipeline beforeremark-mdx, and maps directive node types to custom textlint AST types - Strips directive-specific properties (
name,attributes,data) from directive nodes anddatafrom general nodes to keep the AST clean - Adds test fixtures for all three directive types (
textDirective,leafDirective,containerDirective)
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/parse.ts | Adds remark-directive to the pipeline and handles directive node type mapping and property stripping |
| src/mapping/markdown-syntax-map.ts | Maps the three directive node types to custom AST type strings |
| package.json | Adds remark-directive as a devDependency |
| test/fixtures/textDirective/* | Test fixture for inline text directive |
| test/fixtures/leafDirective/* | Test fixture for leaf directive |
| test/fixtures/containerDirective/* | Test fixture for container directive |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Integrates `remark-directive` to support the `::name[content]{key=val}`
directive syntax (https://talk.commonmark.org/t/generic-directives-plugins-syntax/444).
Maps `textDirective`, `leafDirective`, and `containerDirective` to custom
AST node types (`TextDirective`, `LeafDirective`, `ContainerDirective`) and
strips directive-specific properties (`name`, `attributes`, `data`) to
conform to the textlint AST.
Adds test fixtures for all three directive types.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Ensures `remark-directive` processes directive syntax before `remark-mdx` sees it, making the ordering match the stated intent and providing a clearer guarantee that directive nodes are recognized first. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
remark-directive sets `data: { directiveLabel: true }` on the label
paragraph child of container directives. This internal metadata was
leaking into the textlint AST since the general node-processing branch
did not strip `data`. Now `data` is stripped consistently across all
node-processing branches.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
b622f23 to
e1d2c9b
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds remark-directive support to the textlint MDX plugin, fixing parse errors when MDX files contain directive syntax (e.g., ::directive[foo]{bar=baz}). The {...} attribute portion of directives was previously misinterpreted as MDX/JSX expressions, causing parsing failures.
Changes:
- Integrates
remark-directiveinto the remark pipeline (beforeremark-mdx) and maps directive node types to custom textlint AST types - Strips directive-specific properties (
name,attributes,data) from directive nodes anddatafrom general nodes to keep the AST clean - Adds test fixtures for all three directive types (text, leaf, container)
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/parse.ts | Adds remark-directive to the unified pipeline and handles directive node type mapping/property stripping |
| src/mapping/markdown-syntax-map.ts | Adds mappings for textDirective, leafDirective, and containerDirective to PascalCase AST types |
| package.json | Adds remark-directive ^4.0.0 as a devDependency |
| bun.lock | Lockfile updated with remark-directive and its transitive dependencies |
| test/fixtures/textDirective/* | Test fixture for inline text directive |
| test/fixtures/leafDirective/* | Test fixture for leaf (block-level) directive |
| test/fixtures/containerDirective/* | Test fixture for container directive |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
I use directive syntax in my MDX files and want to lint them with textlint. However, the plugin currently throws a parse error when a directive with attributes is encountered — e.g.,
::directive[foo]{bar=baz qux=quux}.The root cause is that
remark-mdxtreats the{...}part of a directive as an MDX/JSX expression and tries to parse its content as JavaScript. Attribute syntax like{key1=val1 key2=val2}is not valid JavaScript expression, so parsing fails.Fix
This PR integrates
remark-directiveinto the plugin's remark pipeline. By adding it beforeremark-mdxprocesses the AST, directive nodes (textDirective,leafDirective,containerDirective) are recognized and parsed correctly instead of being handed off to the MDX expression parser.The three directive node types are mapped to custom textlint AST node types (
TextDirective,LeafDirective,ContainerDirective), and directive-specific properties (name,attributes,data) are stripped to keep the AST clean.Test plan
textDirective,leafDirective,containerDirective)