@quartz-community/github-flavored-markdown 2.1.1 → 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 +13 -0
- package/README.md +43 -15
- package/dist/index.d.ts +11 -0
- package/dist/index.js +33 -4
- package/dist/index.js.map +1 -1
- package/package.json +13 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
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
|
+
|
|
10
|
+
## 2.1.2
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 5a1722a: Heading anchor links render `aria-hidden="true"` instead of a bare `aria-hidden`, which assistive technology doesn't read as "true". The icon-only link was exposed as a link with no name and an unknown role (`role="anchor"`, kept as a styling hook).
|
|
15
|
+
|
|
3
16
|
## 2.1.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,38 +1,66 @@
|
|
|
1
1
|
# @quartz-community/github-flavored-markdown
|
|
2
2
|
|
|
3
|
-
Adds GitHub Flavored Markdown support including
|
|
3
|
+
Adds GitHub Flavored Markdown support including autolink literals, footnotes, strikethrough, tables, task lists, SmartyPants typography and linked headings.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npx quartz plugin add
|
|
8
|
+
npx quartz plugin add @quartz-community/github-flavored-markdown
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
+
This plugin is already enabled in the default `quartz.config.yaml`:
|
|
14
|
+
|
|
13
15
|
```yaml title="quartz.config.yaml"
|
|
14
16
|
plugins:
|
|
15
|
-
- source:
|
|
17
|
+
- source: "@quartz-community/github-flavored-markdown"
|
|
16
18
|
enabled: true
|
|
19
|
+
options:
|
|
20
|
+
enableSmartyPants: true
|
|
21
|
+
linkHeadings: true
|
|
22
|
+
order: 30
|
|
17
23
|
```
|
|
18
24
|
|
|
19
|
-
|
|
25
|
+
This plugin must run before [obsidian-flavored-markdown](https://github.com/quartz-community/obsidian-flavored-markdown) (order `30` and `40` in the default config). If you set `order` on either plugin, keep this one first.
|
|
26
|
+
|
|
27
|
+
## Configuration
|
|
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). |
|
|
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
|
|
20
37
|
|
|
21
|
-
|
|
22
|
-
import * as ExternalPlugin from "./.quartz/plugins";
|
|
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:
|
|
23
39
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
+
"<==": "⇐"
|
|
28
53
|
```
|
|
29
54
|
|
|
30
|
-
|
|
55
|
+
Text in code, inline code and math is left alone. Note that `<=` then also replaces a "less than or equal" written in prose.
|
|
56
|
+
|
|
57
|
+
## Heading ids
|
|
58
|
+
|
|
59
|
+
Heading ids are made from the heading as written, with the same slug function that links and the table of contents use, and match GitHub's and Obsidian's:
|
|
31
60
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
| `linkHeadings` | `boolean` | `true` | Whether to link headings. |
|
|
61
|
+
- With SmartyPants on, a heading containing `--` keeps it in its id: `## Range 1--2` → `range-1--2` (before Quartz 5.1: `range-12`). `[[page#Range 1--2]]` keeps working.
|
|
62
|
+
- Headings containing `:`, `|`, `^`, `#` or `\` get an extra anchor with the id Obsidian links use (spaces instead of those characters), so such links and section embeds reach them.
|
|
63
|
+
- A same-page link written as a heading's text, such as `[x](<#My Heading>)`, points at the heading's id.
|
|
36
64
|
|
|
37
65
|
## Documentation
|
|
38
66
|
|
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) {
|
|
@@ -6705,7 +6731,10 @@ var GitHubFlavoredMarkdown = (userOpts) => {
|
|
|
6705
6731
|
behavior: "append",
|
|
6706
6732
|
properties: {
|
|
6707
6733
|
role: "anchor",
|
|
6708
|
-
|
|
6734
|
+
// A string: `true` renders as a bare `aria-hidden`, which isn't
|
|
6735
|
+
// "true", so the icon link was exposed as a link without a name
|
|
6736
|
+
// and an unknown role.
|
|
6737
|
+
ariaHidden: "true",
|
|
6709
6738
|
tabIndex: -1,
|
|
6710
6739
|
"data-no-popover": true
|
|
6711
6740
|
},
|