@mirrordown/remd-sub 0.1.2 → 0.2.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/CHANGELOG.md +20 -0
- package/README.md +18 -19
- package/dist/index.d.mts +11 -13
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +24 -86
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -11
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
## 0.2.0
|
|
8
|
+
<sub>2026-10-28</sub>
|
|
9
|
+
|
|
10
|
+
- *(minor)*
|
|
11
|
+
`~subscript~` and `^superscript^` now parse the same way in markdown-it, remark and Sätteri: a single `~` or `^` is a delimiter run with emphasis-style flanking, its content is inline markup (spaces, emphasis, links, code and each other), and crossing runs resolve leftmost-first.
|
|
12
|
+
|
|
13
|
+
- `mdit-sub` and `mdit-sup` used to keep the content as plain text and reject any space inside it. They now parse it as inline markup, so `~*a* b~` renders emphasis and `^a~b~c^` nests.
|
|
14
|
+
- `remd-sub` and `remd-sup` are now micromark syntax extensions sharing one resolver from `@mirrordown/core` (`scriptSyntax`), instead of text scans run one after another. Crossing runs such as `^a~b^c~` no longer depend on which plugin was registered first, `~~a~~` without GFM is no longer turned into empty subscripts, and the packages drop their `unist-util-*` dependencies.
|
|
15
|
+
- The sub guide now shows `remark-gfm` with `singleTilde: false`: GFM's single-tilde strikethrough, which Astro enables by default, otherwise claims `~text~` first.
|
|
16
|
+
- *(patch)*
|
|
17
|
+
Backslash-escaped delimiters are now literal in `remd-mark`, `remd-ins`, `remd-del`, `remd-kbd`, `remd-spoiler`, `remd-sub` and `remd-sup`, as they already were in the `mdit-*` plugins: `\==not marked==` renders as `==not marked==` instead of a `<mark>`, while an escaped backslash (`\==marked==`) still allows the markup. These plugins now depend on the new `@mirrordown/core` package, which holds logic shared across Mirrordown's engines.
|
|
18
|
+
|
|
19
|
+
## 0.1.3
|
|
20
|
+
<sub>2026-06-28</sub>
|
|
21
|
+
|
|
22
|
+
- *(patch)*
|
|
23
|
+
Improve JSR package scores: add package descriptions, document all exported symbols (JSDoc), add READMEs for the inline-svg packages, clear slow-type errors on the exported hast handlers, and trim internal regex constants from the public API.
|
|
24
|
+
|
|
5
25
|
## 0.1.2
|
|
6
26
|
<sub>2026-06-28</sub>
|
|
7
27
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @mirrordown/remd-sub
|
|
2
2
|
|
|
3
|
-
> Part of [Mirrordown](https://github.com/mirrordown/mirrordown) — a suite of markdown syntax extensions for the unified
|
|
3
|
+
> Part of [Mirrordown](https://github.com/mirrordown/mirrordown) — a suite of markdown syntax extensions for the unified, markdown-it and Sätteri ecosystems.
|
|
4
4
|
|
|
5
5
|
A remark/rehype (unified) plugin for the `sub` syntax extension.
|
|
6
6
|
|
|
@@ -16,11 +16,19 @@ The `sub` plugin renders `~text~` as an HTML `<sub>` element, representing subsc
|
|
|
16
16
|
|
|
17
17
|
Wrap text in single tildes to render it as subscript:
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
````markdown
|
|
20
20
|
The chemical formula for water is H~2~O.
|
|
21
21
|
|
|
22
22
|
Carbon dioxide is CO~2~.
|
|
23
|
-
|
|
23
|
+
````
|
|
24
|
+
|
|
25
|
+
### Formatting inside
|
|
26
|
+
|
|
27
|
+
The content is inline markup, like emphasis: it can hold spaces, other formatting and superscript, but can't start or end with a space.
|
|
28
|
+
|
|
29
|
+
````markdown
|
|
30
|
+
x~n^2^~ and the ~*base* index~
|
|
31
|
+
````
|
|
24
32
|
|
|
25
33
|
## Install
|
|
26
34
|
|
|
@@ -39,6 +47,8 @@ import { remarkSub } from "@mirrordown/remd-sub";
|
|
|
39
47
|
|
|
40
48
|
const processor = unified()
|
|
41
49
|
.use(remarkParse)
|
|
50
|
+
// With GFM, turn off single-tilde strikethrough, which would take `~text~` first:
|
|
51
|
+
// .use(remarkGfm, { singleTilde: false })
|
|
42
52
|
.use(remarkSub)
|
|
43
53
|
.use(remarkRehype)
|
|
44
54
|
.use(rehypeStringify);
|
|
@@ -49,26 +59,15 @@ const processor = unified()
|
|
|
49
59
|
```ts
|
|
50
60
|
// astro.config.ts
|
|
51
61
|
import { defineConfig } from "astro/config";
|
|
62
|
+
import remarkGfm from "remark-gfm";
|
|
52
63
|
import { remarkSub } from "@mirrordown/remd-sub";
|
|
53
64
|
|
|
54
65
|
export default defineConfig({
|
|
55
66
|
markdown: {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
### VitePress
|
|
62
|
-
|
|
63
|
-
```ts
|
|
64
|
-
// .vitepress/config.ts
|
|
65
|
-
import { defineConfig } from "vitepress";
|
|
66
|
-
import { remarkSub } from "@mirrordown/remd-sub";
|
|
67
|
-
|
|
68
|
-
export default defineConfig({
|
|
69
|
-
markdown: {
|
|
70
|
-
remarkPlugins: [remarkSub]
|
|
71
|
-
}
|
|
67
|
+
// Astro's own GFM uses single-tilde strikethrough, which takes `~text~` first.
|
|
68
|
+
gfm: false,
|
|
69
|
+
remarkPlugins: [[remarkGfm, { singleTilde: false }], remarkSub],
|
|
70
|
+
},
|
|
72
71
|
});
|
|
73
72
|
```
|
|
74
73
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { Plugin } from "unified";
|
|
2
2
|
import { Data, Parent, PhrasingContent, Root } from "mdast";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
interface SubscriptData extends Data {}
|
|
6
|
-
|
|
3
|
+
import { Extension } from "mdast-util-from-markdown";
|
|
4
|
+
/** Optional data carried by a {@link Subscript} node. */
|
|
5
|
+
export interface SubscriptData extends Data {}
|
|
6
|
+
/** An mdast node for `~subscript~` text, rendered as a `<sub>` element. */
|
|
7
|
+
export interface Subscript extends Parent {
|
|
7
8
|
type: `subscript`;
|
|
8
9
|
children: PhrasingContent[];
|
|
9
10
|
data?: SubscriptData | undefined;
|
|
10
11
|
}
|
|
12
|
+
/** mdast-util-from-markdown extension turning `subscript` tokens into {@link Subscript} nodes. */
|
|
13
|
+
export declare const subscriptFromMarkdown: Extension;
|
|
14
|
+
/**
|
|
15
|
+
* remark plugin for subscript syntax (`~text~`), parsed as a {@link Subscript} node that renders as a `<sub>` element. A single `~` is a delimiter run like emphasis, and its content is inline markup; it shares its syntax with `remd-sup` through `@mirrordown/core`, so the two nest and resolve crossing runs leftmost-first. Use `remark-gfm` with `singleTilde: false`, or GFM claims `~text~` as strikethrough first.
|
|
16
|
+
*/
|
|
17
|
+
export declare const remarkSub: Plugin<[], Root>;
|
|
11
18
|
declare module "mdast" {
|
|
12
19
|
interface PhrasingContentMap {
|
|
13
20
|
subscript: Subscript;
|
|
@@ -16,13 +23,4 @@ declare module "mdast" {
|
|
|
16
23
|
subscript: Subscript;
|
|
17
24
|
}
|
|
18
25
|
}
|
|
19
|
-
declare const REGEX: RegExp;
|
|
20
|
-
declare const REGEX_GLOBAL: RegExp;
|
|
21
|
-
declare const REGEX_STARTING: RegExp;
|
|
22
|
-
declare const REGEX_STARTING_GLOBAL: RegExp;
|
|
23
|
-
declare const REGEX_ENDING: RegExp;
|
|
24
|
-
declare const REGEX_ENDING_GLOBAL: RegExp;
|
|
25
|
-
declare const remarkSub: Plugin<[], Root>;
|
|
26
|
-
//#endregion
|
|
27
|
-
export { REGEX, REGEX_ENDING, REGEX_ENDING_GLOBAL, REGEX_GLOBAL, REGEX_STARTING, REGEX_STARTING_GLOBAL, remarkSub };
|
|
28
26
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["FromMarkdownExtension"],"sources":["../src/plugin.ts","../src/augment.ts"],"mappings":";;;;iBAUiB,sBAAsB;;iBAGtB,kBAAkB;EACjC;EACA,UAAU;EACV,OAAO;;;qBAII,uBAAuBA;;;;qBAwBvB,WAAW,WAAW;;YCtCvB;IACR,WAAW;;YAGH;IACR,WAAW"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,89 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
type: `subscript`,
|
|
17
|
-
children,
|
|
18
|
-
data: { hName: `sub` }
|
|
19
|
-
});
|
|
20
|
-
const visitorFirst = (node, index, parent) => {
|
|
21
|
-
/* v8 ignore next */
|
|
22
|
-
if (!parent || typeof index === `undefined`) return;
|
|
23
|
-
if (!REGEX.test(node.value)) return;
|
|
24
|
-
const children = [];
|
|
25
|
-
const value = node.value;
|
|
26
|
-
let tempValue = ``;
|
|
27
|
-
let prevMatchIndex = 0;
|
|
28
|
-
let prevMatchLength = 0;
|
|
29
|
-
const matches = Array.from(value.matchAll(REGEX_GLOBAL));
|
|
30
|
-
for (const match of matches) {
|
|
31
|
-
const [matched, subscriptText] = match;
|
|
32
|
-
const mIndex = match.index;
|
|
33
|
-
const mLength = matched.length;
|
|
34
|
-
const textPartIndex = prevMatchIndex + prevMatchLength;
|
|
35
|
-
prevMatchIndex = mIndex;
|
|
36
|
-
prevMatchLength = mLength;
|
|
37
|
-
if (mIndex > textPartIndex) children.push(u(`text`, value.substring(textPartIndex, mIndex)));
|
|
38
|
-
children.push(constructSubscriptNode([{
|
|
39
|
-
type: `text`,
|
|
40
|
-
value: subscriptText.trim()
|
|
41
|
-
}]));
|
|
42
|
-
tempValue = value.slice(mIndex + mLength);
|
|
43
|
-
}
|
|
44
|
-
if (tempValue) children.push(u(`text`, tempValue));
|
|
45
|
-
if (children.length) parent.children.splice(index, 1, ...children);
|
|
46
|
-
};
|
|
47
|
-
const visitorSecond = (node, index, parent) => {
|
|
48
|
-
/* v8 ignore next */
|
|
49
|
-
if (!parent || typeof index === `undefined`) return;
|
|
50
|
-
if (!REGEX_STARTING.test(node.value)) return;
|
|
51
|
-
const openingNode = node;
|
|
52
|
-
const closingNode = findAfter(parent, openingNode, (n) => {
|
|
53
|
-
return n.type === `text` && REGEX_ENDING.test(n.value);
|
|
54
|
-
});
|
|
55
|
-
if (!closingNode) return;
|
|
56
|
-
const beforeChildren = findAllBefore(parent, openingNode);
|
|
57
|
-
const mainChildren = findAllBetween(parent, openingNode, closingNode);
|
|
58
|
-
const afterChildren = findAllAfter(parent, closingNode);
|
|
59
|
-
const value = openingNode.value;
|
|
60
|
-
const match = Array.from(value.matchAll(REGEX_STARTING_GLOBAL))[0];
|
|
61
|
-
const [matched] = match;
|
|
62
|
-
const mIndex = match.index;
|
|
63
|
-
const mLength = matched.length;
|
|
64
|
-
if (mIndex > 0) beforeChildren.push(u(`text`, value.substring(0, mIndex)));
|
|
65
|
-
if (value.length > mIndex + mLength) mainChildren.unshift(u(`text`, value.slice(mIndex + mLength)));
|
|
66
|
-
const value_ = closingNode.value;
|
|
67
|
-
const match_ = Array.from(value_.matchAll(REGEX_ENDING_GLOBAL))[0];
|
|
68
|
-
const [matched_] = match_;
|
|
69
|
-
const mIndex_ = match_.index;
|
|
70
|
-
const mLength_ = matched_.length;
|
|
71
|
-
if (mIndex_ > 0) mainChildren.push(u(`text`, value_.substring(0, mIndex_)));
|
|
72
|
-
if (value_.length > mIndex_ + mLength_) afterChildren.unshift(u(`text`, value_.slice(mIndex_ + mLength_)));
|
|
73
|
-
parent.children = [
|
|
74
|
-
...beforeChildren,
|
|
75
|
-
constructSubscriptNode(mainChildren),
|
|
76
|
-
...afterChildren
|
|
77
|
-
];
|
|
78
|
-
return index;
|
|
79
|
-
};
|
|
80
|
-
const transformer = (tree) => {
|
|
81
|
-
visit(tree, `text`, visitorFirst);
|
|
82
|
-
visit(tree, `text`, visitorSecond);
|
|
83
|
-
};
|
|
84
|
-
return transformer;
|
|
1
|
+
import { scriptSyntax } from "@mirrordown/core";
|
|
2
|
+
// src/plugin.ts
|
|
3
|
+
/** mdast-util-from-markdown extension turning `subscript` tokens into {@link Subscript} nodes. */
|
|
4
|
+
const subscriptFromMarkdown = {
|
|
5
|
+
canContainEols: [`subscript`],
|
|
6
|
+
enter: { subscript(token) {
|
|
7
|
+
this.enter({
|
|
8
|
+
type: `subscript`,
|
|
9
|
+
children: [],
|
|
10
|
+
data: { hName: `sub` }
|
|
11
|
+
}, token);
|
|
12
|
+
} },
|
|
13
|
+
exit: { subscript(token) {
|
|
14
|
+
this.exit(token);
|
|
15
|
+
} }
|
|
85
16
|
};
|
|
86
|
-
|
|
87
|
-
|
|
17
|
+
/**
|
|
18
|
+
* remark plugin for subscript syntax (`~text~`), parsed as a {@link Subscript} node that renders as a `<sub>` element. A single `~` is a delimiter run like emphasis, and its content is inline markup; it shares its syntax with `remd-sup` through `@mirrordown/core`, so the two nest and resolve crossing runs leftmost-first. Use `remark-gfm` with `singleTilde: false`, or GFM claims `~text~` as strikethrough first.
|
|
19
|
+
*/
|
|
20
|
+
const remarkSub = function() {
|
|
21
|
+
const data = this.data();
|
|
22
|
+
(data.micromarkExtensions ??= []).push(scriptSyntax(`~`));
|
|
23
|
+
(data.fromMarkdownExtensions ??= []).push(subscriptFromMarkdown);
|
|
24
|
+
};
|
|
25
|
+
export { remarkSub, subscriptFromMarkdown };
|
|
88
26
|
|
|
89
27
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import type { Plugin } from \"unified\";\nimport type { Data, Nodes, Parent, PhrasingContent, Root } from \"mdast\";\nimport type {\n CompileContext,\n Extension as FromMarkdownExtension,\n Token\n} from \"mdast-util-from-markdown\";\nimport { scriptSyntax } from \"@mirrordown/core\";\n\n/** Optional data carried by a {@link Subscript} node. */\nexport interface SubscriptData extends Data {}\n\n/** An mdast node for `~subscript~` text, rendered as a `<sub>` element. */\nexport interface Subscript extends Parent {\n type: `subscript`;\n children: PhrasingContent[];\n data?: SubscriptData | undefined;\n}\n\n/** mdast-util-from-markdown extension turning `subscript` tokens into {@link Subscript} nodes. */\nexport const subscriptFromMarkdown: FromMarkdownExtension = {\n canContainEols: [`subscript`],\n enter: {\n subscript(this: CompileContext, token: Token) {\n const node: Subscript = {\n type: `subscript`,\n children: [],\n data: { hName: `sub` }\n };\n // The JSR build has no mdast augmentation, so `Subscript` is not in `Nodes` there.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion, typescript/no-unnecessary-type-assertion\n this.enter(node as unknown as Nodes, token);\n }\n },\n exit: {\n subscript(this: CompileContext, token: Token) {\n this.exit(token);\n }\n }\n};\n\n/**\n * remark plugin for subscript syntax (`~text~`), parsed as a {@link Subscript} node that renders as a `<sub>` element. A single `~` is a delimiter run like emphasis, and its content is inline markup; it shares its syntax with `remd-sup` through `@mirrordown/core`, so the two nest and resolve crossing runs leftmost-first. Use `remark-gfm` with `singleTilde: false`, or GFM claims `~text~` as strikethrough first.\n */\nexport const remarkSub: Plugin<[], Root> = function () {\n // this.data() in remark plugin context returns a generic shape; the cast narrows the known extension arrays.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n const data = this.data() as {\n micromarkExtensions?: unknown[];\n fromMarkdownExtensions?: unknown[];\n };\n (data.micromarkExtensions ??= []).push(scriptSyntax(`~`));\n (data.fromMarkdownExtensions ??= []).push(subscriptFromMarkdown);\n};\n"],"mappings":";;;AAoBA,MAAa,wBAA+C;CAC1D,gBAAgB,CAAC,WAAW;CAC5B,OAAO,EACL,UAAgC,OAAc;EAQ5C,KAAK,MAAM;GANT,MAAM;GACN,UAAU,CAAC;GACX,MAAM,EAAE,OAAO,MAAM;EAIT,GAAuB,KAAK;CAC5C,EACF;CACA,MAAM,EACJ,UAAgC,OAAc;EAC5C,KAAK,KAAK,KAAK;CACjB,EACF;AACF;;;;AAKA,MAAa,YAA8B,WAAY;CAGrD,MAAM,OAAO,KAAK,KAAK;CAIvB,CAAC,KAAK,wBAAwB,CAAC,EAAA,CAAG,KAAK,aAAa,GAAG,CAAC;CACxD,CAAC,KAAK,2BAA2B,CAAC,EAAA,CAAG,KAAK,qBAAqB;AACjE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mirrordown/remd-sub",
|
|
3
|
-
"
|
|
3
|
+
"description": "A remark plugin for subscript syntax (~text~), rendering <sub> elements.",
|
|
4
|
+
"version": "0.2.0",
|
|
4
5
|
"license": "MIT",
|
|
5
6
|
"author": "Drake Costa <drake@saeris.io> (https://saeris.gg)",
|
|
6
7
|
"repository": {
|
|
@@ -19,12 +20,8 @@
|
|
|
19
20
|
}
|
|
20
21
|
},
|
|
21
22
|
"dependencies": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"unist-util-find-all-after": "^5.0.0",
|
|
25
|
-
"unist-util-find-all-before": "^5.0.0",
|
|
26
|
-
"unist-util-find-between-all": "^1.1.6",
|
|
27
|
-
"unist-util-visit": "^5.1.0"
|
|
23
|
+
"@mirrordown/core": "^0.1.0",
|
|
24
|
+
"mdast-util-from-markdown": "^2.0.3"
|
|
28
25
|
},
|
|
29
26
|
"devDependencies": {
|
|
30
27
|
"@types/mdast": "^4.0.4",
|
|
@@ -37,12 +34,11 @@
|
|
|
37
34
|
"node": ">=24.0.0"
|
|
38
35
|
},
|
|
39
36
|
"bumpy": {
|
|
40
|
-
"buildCommand": "vp pack",
|
|
41
37
|
"publishCommand": [
|
|
42
38
|
"node ../../scripts/sync-jsr-version.mjs",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
39
|
+
"node ../../scripts/npm-publish.mjs",
|
|
40
|
+
"node ../../scripts/jsr-resolve-deps.mjs",
|
|
41
|
+
"node ../../scripts/jsr-publish.mjs"
|
|
46
42
|
]
|
|
47
43
|
}
|
|
48
44
|
}
|