@mirrordown/remd-sub 0.2.0 → 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
@@ -4,6 +4,31 @@
4
4
 
5
5
 
6
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
+
7
32
  ## 0.2.0
8
33
  <sub>2026-10-28</sub>
9
34
 
package/README.md CHANGED
@@ -24,12 +24,18 @@ Carbon dioxide is CO~2~.
24
24
 
25
25
  ### Formatting inside
26
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.
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
28
 
29
29
  ````markdown
30
30
  x~n^2^~ and the ~*base* index~
31
31
  ````
32
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.
38
+
33
39
  ## Install
34
40
 
35
41
  ```sh
@@ -47,7 +53,7 @@ import { remarkSub } from "@mirrordown/remd-sub";
47
53
 
48
54
  const processor = unified()
49
55
  .use(remarkParse)
50
- // With GFM, turn off single-tilde strikethrough, which would take `~text~` first:
56
+ // With GFM, turn off single-tilde strikethrough. Left on, whichever of the two plugins is added later takes `~text~`:
51
57
  // .use(remarkGfm, { singleTilde: false })
52
58
  .use(remarkSub)
53
59
  .use(remarkRehype)
@@ -64,7 +70,7 @@ import { remarkSub } from "@mirrordown/remd-sub";
64
70
 
65
71
  export default defineConfig({
66
72
  markdown: {
67
- // Astro's own GFM uses single-tilde strikethrough, which takes `~text~` first.
73
+ // Astro's own GFM keeps single-tilde strikethrough on. Replacing it means `~text~` doesn't depend on the order plugins are added in.
68
74
  gfm: false,
69
75
  remarkPlugins: [[remarkGfm, { singleTilde: false }], remarkSub],
70
76
  },
package/dist/index.d.mts CHANGED
@@ -12,7 +12,7 @@ export interface Subscript extends Parent {
12
12
  /** mdast-util-from-markdown extension turning `subscript` tokens into {@link Subscript} nodes. */
13
13
  export declare const subscriptFromMarkdown: Extension;
14
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.
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
17
  export declare const remarkSub: Plugin<[], Root>;
18
18
  declare module "mdast" {
package/dist/index.mjs CHANGED
@@ -15,7 +15,7 @@ const subscriptFromMarkdown = {
15
15
  } }
16
16
  };
17
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.
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~`.
19
19
  */
20
20
  const remarkSub = function() {
21
21
  const data = this.data();
@@ -1 +1 @@
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"}
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.2.0",
4
+ "version": "0.2.1",
5
5
  "license": "MIT",
6
6
  "author": "Drake Costa <drake@saeris.io> (https://saeris.gg)",
7
7
  "repository": {
@@ -20,7 +20,7 @@
20
20
  }
21
21
  },
22
22
  "dependencies": {
23
- "@mirrordown/core": "^0.1.0",
23
+ "@mirrordown/core": "^0.2.0",
24
24
  "mdast-util-from-markdown": "^2.0.3"
25
25
  },
26
26
  "devDependencies": {