@quartz-community/github-flavored-markdown 2.1.2 → 2.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 +7 -0
- package/README.md +27 -4
- package/dist/index.d.ts +11 -0
- package/dist/index.js +29 -3
- package/dist/index.js.map +1 -1
- package/package.json +13 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 63864df: `singleTilde` option, passed to remark-gfm: `false` strikes only `~~text~~`, as Obsidian does, so a `~` meaning "about" (`~20 W and (~€120)`) is no longer struck. On by default, as before (#2).
|
|
8
|
+
- 6b6704f: `replacements` option: text to replace as written, outside code and math, before SmartyPants (`{ "->": "→" }`). Empty by default. The README lists Quartz 4's `parseArrows` mapping, for sites that want their arrows back (obsidian-flavored-markdown#12).
|
|
9
|
+
|
|
3
10
|
## 2.1.2
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -26,10 +26,33 @@ This plugin must run before [obsidian-flavored-markdown](https://github.com/quar
|
|
|
26
26
|
|
|
27
27
|
## Configuration
|
|
28
28
|
|
|
29
|
-
| Option | Type | Default | Description
|
|
30
|
-
| ------------------- | --------- | ------- |
|
|
31
|
-
| `enableSmartyPants` | `boolean` | `true` | Typographic enhancements: curly quotes, en/em dashes, ellipses.
|
|
32
|
-
| `linkHeadings` | `boolean` | `true` | Gives headings their `id`s and adds an anchor link to each. `false` also turns off heading ids, so links to headings (`[[page#Heading]]`) and section embeds no longer reach them (the table of contents plugin still adds ids on pages that show it).
|
|
29
|
+
| Option | Type | Default | Description |
|
|
30
|
+
| ------------------- | --------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
31
|
+
| `enableSmartyPants` | `boolean` | `true` | Typographic enhancements: curly quotes, en/em dashes, ellipses. |
|
|
32
|
+
| `linkHeadings` | `boolean` | `true` | Gives headings their `id`s and adds an anchor link to each. `false` also turns off heading ids, so links to headings (`[[page#Heading]]`) and section embeds no longer reach them (the table of contents plugin still adds ids on pages that show it). |
|
|
33
|
+
| `singleTilde` | `boolean` | `true` | Strikes text between single tildes (`~text~`), as GitHub does. `false` strikes only `~~text~~`, as Obsidian does, so a `~` meaning "about" (`~20 W and (~€120)`) stays as written. Under obsidian-flavored-markdown's default `legacy` preset, which parses as Obsidian, single tildes never strike. |
|
|
34
|
+
| `replacements` | `object` | `{}` | Text to replace as written, outside code and math, before SmartyPants; the longest match wins. Empty: neither GitHub nor Obsidian replaces anything. See [Arrows](#arrows). |
|
|
35
|
+
|
|
36
|
+
## Arrows
|
|
37
|
+
|
|
38
|
+
Quartz 4's Obsidian Flavored Markdown turned typed arrows into arrow characters (`parseArrows`). Obsidian doesn't, so Quartz 5 leaves them as typed. To render them as Quartz 4 did:
|
|
39
|
+
|
|
40
|
+
```yaml title="quartz.config.yaml"
|
|
41
|
+
plugins:
|
|
42
|
+
- source: "@quartz-community/github-flavored-markdown"
|
|
43
|
+
options:
|
|
44
|
+
replacements:
|
|
45
|
+
"->": "→"
|
|
46
|
+
"-->": "⇒"
|
|
47
|
+
"=>": "⇒"
|
|
48
|
+
"==>": "⇒"
|
|
49
|
+
"<-": "←"
|
|
50
|
+
"<--": "⇐"
|
|
51
|
+
"<=": "⇐"
|
|
52
|
+
"<==": "⇐"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Text in code, inline code and math is left alone. Note that `<=` then also replaces a "less than or equal" written in prose.
|
|
33
56
|
|
|
34
57
|
## Heading ids
|
|
35
58
|
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,17 @@ export { QuartzTransformerPlugin } from '@quartz-community/types';
|
|
|
4
4
|
interface GfmOptions {
|
|
5
5
|
enableSmartyPants: boolean;
|
|
6
6
|
linkHeadings: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Text to replace as written, applied before SmartyPants, outside code and math:
|
|
9
|
+
* `{ "->": "→", "=>": "⇒" }` brings back Quartz 4's `parseArrows`. Empty by default: neither
|
|
10
|
+
* GitHub nor Obsidian replaces anything.
|
|
11
|
+
*/
|
|
12
|
+
replacements: Record<string, string>;
|
|
13
|
+
/**
|
|
14
|
+
* Strike text between single tildes (`~text~`), as GitHub does. `false` strikes only
|
|
15
|
+
* `~~text~~`, as Obsidian does, so `about ~20 W and (~€120)` stays as written.
|
|
16
|
+
*/
|
|
17
|
+
singleTilde: boolean;
|
|
7
18
|
}
|
|
8
19
|
declare const GitHubFlavoredMarkdown: QuartzTransformerPlugin<Partial<GfmOptions>>;
|
|
9
20
|
|
package/dist/index.js
CHANGED
|
@@ -6682,18 +6682,44 @@ function rehypeHeadingIds() {
|
|
|
6682
6682
|
};
|
|
6683
6683
|
}
|
|
6684
6684
|
|
|
6685
|
+
// src/textReplacements.ts
|
|
6686
|
+
function remarkTextReplacements(replacements) {
|
|
6687
|
+
const keys2 = Object.keys(replacements).filter((key) => key !== "").sort((a, b) => b.length - a.length);
|
|
6688
|
+
if (keys2.length === 0) return () => {
|
|
6689
|
+
};
|
|
6690
|
+
const pattern = new RegExp(
|
|
6691
|
+
keys2.map((key) => key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"),
|
|
6692
|
+
"g"
|
|
6693
|
+
);
|
|
6694
|
+
const walk = (node2) => {
|
|
6695
|
+
if (node2.type === "text") {
|
|
6696
|
+
node2.value = node2.value.replace(pattern, (match) => replacements[match] ?? match);
|
|
6697
|
+
return;
|
|
6698
|
+
}
|
|
6699
|
+
if ("children" in node2) for (const child of node2.children) walk(child);
|
|
6700
|
+
};
|
|
6701
|
+
return (tree) => walk(tree);
|
|
6702
|
+
}
|
|
6703
|
+
|
|
6685
6704
|
// src/transformer.ts
|
|
6686
6705
|
var defaultOptions = {
|
|
6687
6706
|
enableSmartyPants: true,
|
|
6688
|
-
linkHeadings: true
|
|
6707
|
+
linkHeadings: true,
|
|
6708
|
+
replacements: {},
|
|
6709
|
+
singleTilde: true
|
|
6689
6710
|
};
|
|
6690
6711
|
var GitHubFlavoredMarkdown = (userOpts) => {
|
|
6691
6712
|
const opts = { ...defaultOptions, ...userOpts };
|
|
6692
6713
|
return {
|
|
6693
6714
|
name: "GitHubFlavoredMarkdown",
|
|
6694
6715
|
markdownPlugins() {
|
|
6695
|
-
|
|
6696
|
-
|
|
6716
|
+
const gfm2 = [remarkGfm, { singleTilde: opts.singleTilde }];
|
|
6717
|
+
const rewrites = [];
|
|
6718
|
+
if (Object.keys(opts.replacements).length > 0)
|
|
6719
|
+
rewrites.push([remarkTextReplacements, opts.replacements]);
|
|
6720
|
+
if (opts.enableSmartyPants) rewrites.push(plugin_default);
|
|
6721
|
+
if (rewrites.length === 0) return [gfm2];
|
|
6722
|
+
return opts.linkHeadings ? [gfm2, remarkRememberHeadingText, ...rewrites, remarkRecordHeadingRewrites] : [gfm2, ...rewrites];
|
|
6697
6723
|
},
|
|
6698
6724
|
htmlPlugins() {
|
|
6699
6725
|
if (opts.linkHeadings) {
|