@mirrordown/remd-sub 0.1.3 → 0.2.1

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 CHANGED
@@ -3,6 +3,44 @@
3
3
 
4
4
 
5
5
 
6
+
7
+
8
+ ## 0.2.1
9
+ <sub>2026-11-17</sub>
10
+
11
+ - *(patch)*
12
+ One fix in markdown-it, for emphasis written tightly around a subscript. The remark plugin's output is unchanged.
13
+
14
+ - **Asterisks directly around a subscript inside a word are emphasis** (markdown-it, with its `strikethrough` rule on, which is the default).
15
+
16
+ ```markdown
17
+ H**~2~**O
18
+ ```
19
+
20
+ Was `H**<sub>2</sub>**O`. Now `H<strong><sub>2</sub></strong>O`, as in remark with GFM and in Sätteri. With strikethrough off the asterisks stay text in every engine, as before.
21
+
22
+ - **The same holds beside any tilde, not only a subscript's** (markdown-it, with the plugin installed and `strikethrough` on).
23
+
24
+ ```markdown
25
+ x*~~i~~*
26
+ ```
27
+
28
+ Was `x*<s>i</s>*`. Now `x<em><s>i</s></em>`, matching the emphasis of remark with GFM and of Sätteri.
29
+
30
+ The guide now says which plugin takes `~text~` under remark-gfm's single-tilde strikethrough, and what Sätteri's built-in subscript does differently.
31
+
32
+ ## 0.2.0
33
+ <sub>2026-10-28</sub>
34
+
35
+ - *(minor)*
36
+ `~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.
37
+
38
+ - `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.
39
+ - `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.
40
+ - The sub guide now shows `remark-gfm` with `singleTilde: false`: GFM's single-tilde strikethrough, which Astro enables by default, otherwise claims `~text~` first.
41
+ - *(patch)*
42
+ 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.
43
+
6
44
  ## 0.1.3
7
45
  <sub>2026-06-28</sub>
8
46
 
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 and markdown-it ecosystems.
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,25 @@ 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
- ```markdown
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. As with emphasis, a tilde between a letter or digit and punctuation doesn't open or close one, so `10~-3~` and `H~(2)~O` stay as written; after a space it does (`x ~-1~`).
28
+
29
+ ````markdown
30
+ x~n^2^~ and the ~*base* index~
31
+ ````
32
+
33
+ A backslash keeps a tilde literal (`H\~2\~O`). Asterisks wrapped tightly around a subscript inside a word (`H**~2~**O`) are emphasis only with GFM, which lets emphasis sit against a `~`; in markdown-it that is the `strikethrough` rule, on by default. A few things differ between the engines:
34
+
35
+ - Spans have to nest. When a subscript crosses a span another plugin builds (`==a ~b== c~`, `--a ~b-- c~`), each engine resolves it its own way. Crossing emphasis (`~a *b~ c*`) renders the same in all three.
36
+ - With GFM off, Sätteri still reads `~~…~~` as a pair and finds no subscript inside it (`~~H~2~O~~`). markdown-it and remark do.
37
+ - Sätteri's subscript takes no attribute block: `x~2~{.s}` sets the class with the markdown-it and remark attrs plugins and keeps the braces as text on Sätteri, where a block at the end of a paragraph, heading or list item (`x~2~{.s}` alone on a line) sets the class on that element instead.
24
38
 
25
39
  ## Install
26
40
 
@@ -39,6 +53,8 @@ import { remarkSub } from "@mirrordown/remd-sub";
39
53
 
40
54
  const processor = unified()
41
55
  .use(remarkParse)
56
+ // With GFM, turn off single-tilde strikethrough. Left on, whichever of the two plugins is added later takes `~text~`:
57
+ // .use(remarkGfm, { singleTilde: false })
42
58
  .use(remarkSub)
43
59
  .use(remarkRehype)
44
60
  .use(rehypeStringify);
@@ -49,26 +65,15 @@ const processor = unified()
49
65
  ```ts
50
66
  // astro.config.ts
51
67
  import { defineConfig } from "astro/config";
68
+ import remarkGfm from "remark-gfm";
52
69
  import { remarkSub } from "@mirrordown/remd-sub";
53
70
 
54
71
  export default defineConfig({
55
72
  markdown: {
56
- remarkPlugins: [remarkSub]
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
- }
73
+ // Astro's own GFM keeps single-tilde strikethrough on. Replacing it means `~text~` doesn't depend on the order plugins are added in.
74
+ gfm: false,
75
+ remarkPlugins: [[remarkGfm, { singleTilde: false }], remarkSub],
76
+ },
72
77
  });
73
78
  ```
74
79
 
package/dist/index.d.mts CHANGED
@@ -1,22 +1,20 @@
1
1
  import { Plugin } from "unified";
2
2
  import { Data, Parent, PhrasingContent, Root } from "mdast";
3
-
4
- //#region src/plugin.d.ts
3
+ import { Extension } from "mdast-util-from-markdown";
5
4
  /** Optional data carried by a {@link Subscript} node. */
6
- interface SubscriptData extends Data {}
5
+ export interface SubscriptData extends Data {}
7
6
  /** An mdast node for `~subscript~` text, rendered as a `<sub>` element. */
8
- interface Subscript extends Parent {
7
+ export interface Subscript extends Parent {
9
8
  type: `subscript`;
10
9
  children: PhrasingContent[];
11
10
  data?: SubscriptData | undefined;
12
11
  }
12
+ /** mdast-util-from-markdown extension turning `subscript` tokens into {@link Subscript} nodes. */
13
+ export declare const subscriptFromMarkdown: Extension;
13
14
  /**
14
- * remark plugin for subscript syntax (`~text~`), wrapping each match in a
15
- * {@link Subscript} node that renders as a `<sub>` element.
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 runs that cross each other leftmost-first. Use `remark-gfm` with `singleTilde: false`: with its single-tilde strikethrough on, whichever of the two plugins is added later takes `~text~`.
16
16
  */
17
- declare const remarkSub: Plugin<[], Root>;
18
- //#endregion
19
- //#region src/augment.d.ts
17
+ export declare const remarkSub: Plugin<[], Root>;
20
18
  declare module "mdast" {
21
19
  interface PhrasingContentMap {
22
20
  subscript: Subscript;
@@ -24,7 +22,5 @@ declare module "mdast" {
24
22
  interface RootContentMap {
25
23
  subscript: Subscript;
26
24
  }
27
- } //# sourceMappingURL=augment.d.ts.map
28
- //#endregion
29
- export { Subscript, SubscriptData, remarkSub };
25
+ }
30
26
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/plugin.ts","../src/augment.ts"],"mappings":";;;;;UAWiB,aAAA,SAAsB,IAAA;;UAGtB,SAAA,SAAkB,MAAA;EACjC,IAAA;EACA,QAAA,EAAU,eAAA;EACV,IAAA,GAAO,aAAA;AAAA;;;;;cAgBI,SAAA,EAAW,MAAA,KAAW,IAAA;;;;YC3BvB,kBAAA;IACR,SAAA,EAAW,SAAA;EAAA;EAAA,UAGH,cAAA;IACR,SAAA,EAAW,SAAA;EAAA;AAAA"}
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,93 +1,27 @@
1
- import { visit } from "unist-util-visit";
2
- import { findAllBetween } from "unist-util-find-between-all";
3
- import { findAllBefore } from "unist-util-find-all-before";
4
- import { findAllAfter } from "unist-util-find-all-after";
5
- import { findAfter } from "unist-util-find-after";
6
- import { u } from "unist-builder";
7
- //#region src/plugin.ts
8
- const REGEX = /~(?!\s)([\s\S]*?)(?<!\s)~/;
9
- const REGEX_GLOBAL = /~(?!\s)([\s\S]*?)(?<!\s)~/g;
10
- const REGEX_STARTING = /~(?!\s)/;
11
- const REGEX_STARTING_GLOBAL = /~(?!\s)/g;
12
- const REGEX_ENDING = /(?<!\s)~/;
13
- const REGEX_ENDING_GLOBAL = /(?<!\s)~/g;
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
+ } }
16
+ };
14
17
  /**
15
- * remark plugin for subscript syntax (`~text~`), wrapping each match in a
16
- * {@link Subscript} node that renders as a `<sub>` element.
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 runs that cross each other leftmost-first. Use `remark-gfm` with `singleTilde: false`: with its single-tilde strikethrough on, whichever of the two plugins is added later takes `~text~`.
17
19
  */
18
- const remarkSub = () => {
19
- const constructSubscriptNode = (children) => ({
20
- type: `subscript`,
21
- children,
22
- data: { hName: `sub` }
23
- });
24
- const visitorFirst = (node, index, parent) => {
25
- /* v8 ignore next */
26
- if (!parent || typeof index === `undefined`) return;
27
- if (!REGEX.test(node.value)) return;
28
- const children = [];
29
- const value = node.value;
30
- let tempValue = ``;
31
- let prevMatchIndex = 0;
32
- let prevMatchLength = 0;
33
- const matches = Array.from(value.matchAll(REGEX_GLOBAL));
34
- for (const match of matches) {
35
- const [matched, subscriptText] = match;
36
- const mIndex = match.index;
37
- const mLength = matched.length;
38
- const textPartIndex = prevMatchIndex + prevMatchLength;
39
- prevMatchIndex = mIndex;
40
- prevMatchLength = mLength;
41
- if (mIndex > textPartIndex) children.push(u(`text`, value.substring(textPartIndex, mIndex)));
42
- children.push(constructSubscriptNode([{
43
- type: `text`,
44
- value: subscriptText.trim()
45
- }]));
46
- tempValue = value.slice(mIndex + mLength);
47
- }
48
- if (tempValue) children.push(u(`text`, tempValue));
49
- if (children.length) parent.children.splice(index, 1, ...children);
50
- };
51
- const visitorSecond = (node, index, parent) => {
52
- /* v8 ignore next */
53
- if (!parent || typeof index === `undefined`) return;
54
- if (!REGEX_STARTING.test(node.value)) return;
55
- const openingNode = node;
56
- const closingNode = findAfter(parent, openingNode, (n) => {
57
- return n.type === `text` && REGEX_ENDING.test(n.value);
58
- });
59
- if (!closingNode) return;
60
- const beforeChildren = findAllBefore(parent, openingNode);
61
- const mainChildren = findAllBetween(parent, openingNode, closingNode);
62
- const afterChildren = findAllAfter(parent, closingNode);
63
- const value = openingNode.value;
64
- const match = Array.from(value.matchAll(REGEX_STARTING_GLOBAL))[0];
65
- const [matched] = match;
66
- const mIndex = match.index;
67
- const mLength = matched.length;
68
- if (mIndex > 0) beforeChildren.push(u(`text`, value.substring(0, mIndex)));
69
- if (value.length > mIndex + mLength) mainChildren.unshift(u(`text`, value.slice(mIndex + mLength)));
70
- const value_ = closingNode.value;
71
- const match_ = Array.from(value_.matchAll(REGEX_ENDING_GLOBAL))[0];
72
- const [matched_] = match_;
73
- const mIndex_ = match_.index;
74
- const mLength_ = matched_.length;
75
- if (mIndex_ > 0) mainChildren.push(u(`text`, value_.substring(0, mIndex_)));
76
- if (value_.length > mIndex_ + mLength_) afterChildren.unshift(u(`text`, value_.slice(mIndex_ + mLength_)));
77
- parent.children = [
78
- ...beforeChildren,
79
- constructSubscriptNode(mainChildren),
80
- ...afterChildren
81
- ];
82
- return index;
83
- };
84
- const transformer = (tree) => {
85
- visit(tree, `text`, visitorFirst);
86
- visit(tree, `text`, visitorSecond);
87
- };
88
- return transformer;
20
+ const remarkSub = function() {
21
+ const data = this.data();
22
+ (data.micromarkExtensions ??= []).push(scriptSyntax(`~`));
23
+ (data.fromMarkdownExtensions ??= []).push(subscriptFromMarkdown);
89
24
  };
90
- //#endregion
91
- export { remarkSub };
25
+ export { remarkSub, subscriptFromMarkdown };
92
26
 
93
27
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import { visit } from \"unist-util-visit\";\nimport type { Visitor, VisitorResult } from \"unist-util-visit\";\nimport type { Plugin, Transformer } from \"unified\";\nimport type { Data, Parent, PhrasingContent, Root, Text } from \"mdast\";\nimport { findAllBetween } from \"unist-util-find-between-all\";\nimport { findAllBefore } from \"unist-util-find-all-before\";\nimport { findAllAfter } from \"unist-util-find-all-after\";\nimport { findAfter } from \"unist-util-find-after\";\nimport { u } from \"unist-builder\";\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\nconst REGEX = /~(?!\\s)([\\s\\S]*?)(?<!\\s)~/;\nconst REGEX_GLOBAL = /~(?!\\s)([\\s\\S]*?)(?<!\\s)~/g;\n\nconst REGEX_STARTING = /~(?!\\s)/;\nconst REGEX_STARTING_GLOBAL = /~(?!\\s)/g;\n\nconst REGEX_ENDING = /(?<!\\s)~/;\nconst REGEX_ENDING_GLOBAL = /(?<!\\s)~/g;\n\n/**\n * remark plugin for subscript syntax (`~text~`), wrapping each match in a\n * {@link Subscript} node that renders as a `<sub>` element.\n */\nexport const remarkSub: Plugin<[], Root> = () => {\n const constructSubscriptNode = (children: PhrasingContent[]): Subscript => ({\n type: `subscript`,\n children,\n data: { hName: `sub` }\n });\n\n const visitorFirst: Visitor<Text, Parent> = (\n node,\n index,\n parent\n ): VisitorResult => {\n /* v8 ignore next */\n if (!parent || typeof index === `undefined`) return;\n\n if (!REGEX.test(node.value)) return;\n\n const children: PhrasingContent[] = [];\n const value = node.value;\n let tempValue = ``;\n let prevMatchIndex = 0;\n let prevMatchLength = 0;\n\n const matches = Array.from(value.matchAll(REGEX_GLOBAL));\n\n for (const match of matches) {\n const [matched, subscriptText] = match;\n const mIndex = match.index;\n const mLength = matched.length;\n\n const textPartIndex = prevMatchIndex + prevMatchLength;\n\n prevMatchIndex = mIndex;\n prevMatchLength = mLength;\n\n if (mIndex > textPartIndex) {\n children.push(u(`text`, value.substring(textPartIndex, mIndex)));\n }\n\n children.push(\n constructSubscriptNode([{ type: `text`, value: subscriptText.trim() }])\n );\n\n tempValue = value.slice(mIndex + mLength);\n }\n\n if (tempValue) {\n children.push(u(`text`, tempValue));\n }\n\n if (children.length) parent.children.splice(index, 1, ...children);\n };\n\n const visitorSecond: Visitor<Text, Parent> = (\n node,\n index,\n parent\n ): VisitorResult => {\n /* v8 ignore next */\n if (!parent || typeof index === `undefined`) return;\n\n if (!REGEX_STARTING.test(node.value)) return;\n\n const openingNode = node;\n\n const closingNode = findAfter(parent, openingNode, (n): n is Text => {\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n return n.type === `text` && REGEX_ENDING.test((n as Text).value);\n });\n\n if (!closingNode) return;\n\n // unist-util-find-all-* are generic over Parent; we know paragraph\n // siblings are PhrasingContent. The cast narrows the lib's `Node[]`\n // return to the concrete child type we know we're working with.\n /* oxlint-disable typescript/no-unsafe-type-assertion */\n const beforeChildren = findAllBefore(\n parent,\n openingNode\n ) as PhrasingContent[];\n const mainChildren = findAllBetween(\n parent,\n openingNode,\n closingNode\n ) as PhrasingContent[];\n const afterChildren = findAllAfter(\n parent,\n closingNode\n ) as PhrasingContent[];\n /* oxlint-enable typescript/no-unsafe-type-assertion */\n\n const value = openingNode.value;\n const match = Array.from(value.matchAll(REGEX_STARTING_GLOBAL))[0];\n const [matched] = match;\n const mIndex = match.index;\n const mLength = matched.length;\n\n if (mIndex > 0) {\n beforeChildren.push(u(`text`, value.substring(0, mIndex)));\n }\n\n if (value.length > mIndex + mLength) {\n mainChildren.unshift(u(`text`, value.slice(mIndex + mLength)));\n }\n\n const value_ = closingNode.value;\n const match_ = Array.from(value_.matchAll(REGEX_ENDING_GLOBAL))[0];\n const [matched_] = match_;\n const mIndex_ = match_.index;\n const mLength_ = matched_.length;\n\n if (mIndex_ > 0) {\n mainChildren.push(u(`text`, value_.substring(0, mIndex_)));\n }\n\n if (value_.length > mIndex_ + mLength_) {\n afterChildren.unshift(u(`text`, value_.slice(mIndex_ + mLength_)));\n }\n\n parent.children = [\n ...beforeChildren,\n constructSubscriptNode(mainChildren),\n ...afterChildren\n ];\n\n return index;\n };\n\n const transformer: Transformer<Root> = (tree) => {\n visit(tree, `text`, visitorFirst);\n visit(tree, `text`, visitorSecond);\n };\n\n return transformer;\n};\n"],"mappings":";;;;;;;AAoBA,MAAM,QAAQ;AACd,MAAM,eAAe;AAErB,MAAM,iBAAiB;AACvB,MAAM,wBAAwB;AAE9B,MAAM,eAAe;AACrB,MAAM,sBAAsB;;;;;AAM5B,MAAa,kBAAoC;CAC/C,MAAM,0BAA0B,cAA4C;EAC1E,MAAM;EACN;EACA,MAAM,EAAE,OAAO,OAAO;EACvB;CAED,MAAM,gBACJ,MACA,OACA,WACkB;;AAElB,MAAI,CAAC,UAAU,OAAO,UAAU,YAAa;AAE7C,MAAI,CAAC,MAAM,KAAK,KAAK,MAAM,CAAE;EAE7B,MAAM,WAA8B,EAAE;EACtC,MAAM,QAAQ,KAAK;EACnB,IAAI,YAAY;EAChB,IAAI,iBAAiB;EACrB,IAAI,kBAAkB;EAEtB,MAAM,UAAU,MAAM,KAAK,MAAM,SAAS,aAAa,CAAC;AAExD,OAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,CAAC,SAAS,iBAAiB;GACjC,MAAM,SAAS,MAAM;GACrB,MAAM,UAAU,QAAQ;GAExB,MAAM,gBAAgB,iBAAiB;AAEvC,oBAAiB;AACjB,qBAAkB;AAElB,OAAI,SAAS,cACX,UAAS,KAAK,EAAE,QAAQ,MAAM,UAAU,eAAe,OAAO,CAAC,CAAC;AAGlE,YAAS,KACP,uBAAuB,CAAC;IAAE,MAAM;IAAQ,OAAO,cAAc,MAAM;IAAE,CAAC,CAAC,CACxE;AAED,eAAY,MAAM,MAAM,SAAS,QAAQ;;AAG3C,MAAI,UACF,UAAS,KAAK,EAAE,QAAQ,UAAU,CAAC;AAGrC,MAAI,SAAS,OAAQ,QAAO,SAAS,OAAO,OAAO,GAAG,GAAG,SAAS;;CAGpE,MAAM,iBACJ,MACA,OACA,WACkB;;AAElB,MAAI,CAAC,UAAU,OAAO,UAAU,YAAa;AAE7C,MAAI,CAAC,eAAe,KAAK,KAAK,MAAM,CAAE;EAEtC,MAAM,cAAc;EAEpB,MAAM,cAAc,UAAU,QAAQ,cAAc,MAAiB;AAEnE,UAAO,EAAE,SAAS,UAAU,aAAa,KAAM,EAAW,MAAM;IAChE;AAEF,MAAI,CAAC,YAAa;EAMlB,MAAM,iBAAiB,cACrB,QACA,YACD;EACD,MAAM,eAAe,eACnB,QACA,aACA,YACD;EACD,MAAM,gBAAgB,aACpB,QACA,YACD;EAGD,MAAM,QAAQ,YAAY;EAC1B,MAAM,QAAQ,MAAM,KAAK,MAAM,SAAS,sBAAsB,CAAC,CAAC;EAChE,MAAM,CAAC,WAAW;EAClB,MAAM,SAAS,MAAM;EACrB,MAAM,UAAU,QAAQ;AAExB,MAAI,SAAS,EACX,gBAAe,KAAK,EAAE,QAAQ,MAAM,UAAU,GAAG,OAAO,CAAC,CAAC;AAG5D,MAAI,MAAM,SAAS,SAAS,QAC1B,cAAa,QAAQ,EAAE,QAAQ,MAAM,MAAM,SAAS,QAAQ,CAAC,CAAC;EAGhE,MAAM,SAAS,YAAY;EAC3B,MAAM,SAAS,MAAM,KAAK,OAAO,SAAS,oBAAoB,CAAC,CAAC;EAChE,MAAM,CAAC,YAAY;EACnB,MAAM,UAAU,OAAO;EACvB,MAAM,WAAW,SAAS;AAE1B,MAAI,UAAU,EACZ,cAAa,KAAK,EAAE,QAAQ,OAAO,UAAU,GAAG,QAAQ,CAAC,CAAC;AAG5D,MAAI,OAAO,SAAS,UAAU,SAC5B,eAAc,QAAQ,EAAE,QAAQ,OAAO,MAAM,UAAU,SAAS,CAAC,CAAC;AAGpE,SAAO,WAAW;GAChB,GAAG;GACH,uBAAuB,aAAa;GACpC,GAAG;GACJ;AAED,SAAO;;CAGT,MAAM,eAAkC,SAAS;AAC/C,QAAM,MAAM,QAAQ,aAAa;AACjC,QAAM,MAAM,QAAQ,cAAc;;AAGpC,QAAO"}
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 runs that cross each other leftmost-first. Use `remark-gfm` with `singleTilde: false`: with its single-tilde strikethrough on, whichever of the two plugins is added later takes `~text~`.\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,7 +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.1.3",
4
+ "version": "0.2.1",
5
5
  "license": "MIT",
6
6
  "author": "Drake Costa <drake@saeris.io> (https://saeris.gg)",
7
7
  "repository": {
@@ -20,12 +20,8 @@
20
20
  }
21
21
  },
22
22
  "dependencies": {
23
- "unist-builder": "^4.0.0",
24
- "unist-util-find-after": "^5.0.0",
25
- "unist-util-find-all-after": "^5.0.0",
26
- "unist-util-find-all-before": "^5.0.0",
27
- "unist-util-find-between-all": "^1.1.6",
28
- "unist-util-visit": "^5.1.0"
23
+ "@mirrordown/core": "^0.2.0",
24
+ "mdast-util-from-markdown": "^2.0.3"
29
25
  },
30
26
  "devDependencies": {
31
27
  "@types/mdast": "^4.0.4",