@quartz-community/remark-obsidian 1.0.0 → 2.0.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/LICENSE-THIRD-PARTY.md +162 -0
- package/README.md +129 -1
- package/dist/index.d.ts +275 -2
- package/dist/index.js +14387 -1095
- package/dist/index.js.map +1 -1
- package/package.json +51 -6
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Third-party licences
|
|
2
|
+
|
|
3
|
+
## obsidian-footnotes
|
|
4
|
+
|
|
5
|
+
Two things come from
|
|
6
|
+
[`obsidian-footnotes`](https://github.com/Comprehensive-Jason/obsidian-footnotes),
|
|
7
|
+
both contributed for this purpose.
|
|
8
|
+
|
|
9
|
+
`test/parity/corpus-hunt.ts` holds structural markdown fixtures harvested from that
|
|
10
|
+
project's `test/hunt/` regression pins. They cover block-structure edges a generated
|
|
11
|
+
corpus does not reach.
|
|
12
|
+
|
|
13
|
+
`test/parity/referee-answers/` is its `test/obsidian-answers/` directory vendored
|
|
14
|
+
verbatim — 6,818 documents with the `metadataCache` answers real Obsidian gave for
|
|
15
|
+
each. This IS that project's recorded measurement, not just its inputs, and it is
|
|
16
|
+
what `referee.mts` and eight sibling instruments compare against. Kept
|
|
17
|
+
byte-identical (see `.prettierignore`) so a diff against upstream shows answers
|
|
18
|
+
changing and nothing else. The only local change is that `refsTrustworthy` is
|
|
19
|
+
populated where upstream leaves it `null`, written by `recorder.mts`.
|
|
20
|
+
|
|
21
|
+
None of that is published to npm; `package.json` ships `dist` only.
|
|
22
|
+
|
|
23
|
+
A third thing IS published. `src/rp8/reader.ts`, the `legacy` preset's parser, ports the
|
|
24
|
+
Obsidian readers of that project's `src/parsing/obsidian-markdown.ts` -- `%%` comments, callout
|
|
25
|
+
titles, table pipe styles, wikilinks, frontmatter, `$$` inline math -- and `src/rp8/list.ts`
|
|
26
|
+
follows its `remark-parse-list.js` in changing remark-parse 8's list reader. Both are bundled
|
|
27
|
+
into `dist`, under this licence.
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
MIT License
|
|
31
|
+
|
|
32
|
+
Copyright (c) 2021-2026 Alexis Rondeau, Micha Brugger, Jason Qin, and contributors
|
|
33
|
+
|
|
34
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
35
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
36
|
+
in the Software without restriction, including without limitation the rights
|
|
37
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
38
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
39
|
+
furnished to do so, subject to the following conditions:
|
|
40
|
+
|
|
41
|
+
The above copyright notice and this permission notice shall be included in all
|
|
42
|
+
copies or substantial portions of the Software.
|
|
43
|
+
|
|
44
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
45
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
46
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
47
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
48
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
49
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
50
|
+
SOFTWARE.
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## micromark-extension-math
|
|
54
|
+
|
|
55
|
+
`src/lib/syntax/math-text.ts` is adapted from
|
|
56
|
+
[`micromark-extension-math`](https://github.com/micromark/micromark-extension-math).
|
|
57
|
+
Its tokenizer and resolver were vendored so Obsidian's inline-math rules could be
|
|
58
|
+
implemented directly; see the file header for the specific divergences.
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
(The MIT License)
|
|
62
|
+
|
|
63
|
+
Copyright (c) 2020 Titus Wormer <tituswormer@gmail.com>
|
|
64
|
+
|
|
65
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
66
|
+
a copy of this software and associated documentation files (the
|
|
67
|
+
'Software'), to deal in the Software without restriction, including
|
|
68
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
69
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
70
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
71
|
+
the following conditions:
|
|
72
|
+
|
|
73
|
+
The above copyright notice and this permission notice shall be
|
|
74
|
+
included in all copies or substantial portions of the Software.
|
|
75
|
+
|
|
76
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
77
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
78
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
79
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
80
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
81
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
82
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## micromark-extension-gfm-footnote
|
|
86
|
+
|
|
87
|
+
`src/lib/syntax/footnote.ts` is vendored from
|
|
88
|
+
[`micromark-extension-gfm-footnote`](https://github.com/micromark/micromark-extension-gfm-footnote)
|
|
89
|
+
2.1.0, the footnote syntax `remark-gfm` registers. `strict` uses it in place of upstream's with
|
|
90
|
+
Obsidian's label rule -- a `[` may sit inside a label and a backslash escapes nothing; the file
|
|
91
|
+
header has the details.
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
(The MIT License)
|
|
95
|
+
|
|
96
|
+
Copyright (c) 2021 Titus Wormer <tituswormer@gmail.com>
|
|
97
|
+
|
|
98
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
99
|
+
a copy of this software and associated documentation files (the
|
|
100
|
+
'Software'), to deal in the Software without restriction, including
|
|
101
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
102
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
103
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
104
|
+
the following conditions:
|
|
105
|
+
|
|
106
|
+
The above copyright notice and this permission notice shall be
|
|
107
|
+
included in all copies or substantial portions of the Software.
|
|
108
|
+
|
|
109
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
110
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
111
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
112
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
113
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
114
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
115
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## remark-parse 8 and its companions
|
|
119
|
+
|
|
120
|
+
`src/rp8/vendor/` vendors remark-parse 8.0.3, remark-footnotes 2.0.0, remark-math 3.0.1 and
|
|
121
|
+
parse-entities 2.0.0 with the v1 entity tables, converted to ESM; `src/rp8/vendor/helpers.ts`
|
|
122
|
+
rewrites the small packages they required (trim, repeat-string, xtend, is-whitespace-character,
|
|
123
|
+
is-word-character, is-decimal, is-alphabetical, is-hexadecimal, is-alphanumerical,
|
|
124
|
+
trim-trailing-lines, collapse-white-space, ccount, state-toggle, markdown-escapes, vfile-location,
|
|
125
|
+
unist-util-remove-position). `src/rp8/list.ts` and `src/rp8/remove-indentation.ts` are
|
|
126
|
+
remark-parse 8 files with Obsidian's changes. All are bundled into `dist`. Each is MIT:
|
|
127
|
+
|
|
128
|
+
- remark-parse 8.0.3 -- Copyright (c) 2014-2020 Titus Wormer <tituswormer@gmail.com>;
|
|
129
|
+
Copyright (c) 2011-2014, Christopher Jeffrey (https://github.com/chjj/)
|
|
130
|
+
- remark-footnotes 2.0.0 -- Copyright (c) 2020 Titus Wormer <tituswormer@gmail.com>
|
|
131
|
+
- remark-math 3.0.1 -- Junyoung Choi <fluke8259@gmail.com> (its `package.json`; the published
|
|
132
|
+
tarball carries no licence file)
|
|
133
|
+
- parse-entities 2.0.0 -- Copyright (c) 2015 Titus Wormer <tituswormer@gmail.com>
|
|
134
|
+
- character-entities 1.2.4, character-entities-legacy 1.1.4, character-reference-invalid 1.1.4
|
|
135
|
+
-- Copyright (c) 2015 Titus Wormer <tituswormer@gmail.com>
|
|
136
|
+
- the helper packages above: vfile-location, state-toggle, ccount, markdown-escapes and the
|
|
137
|
+
is-* predicates follow Titus Wormer's MIT sources closely; trim, repeat-string and xtend are
|
|
138
|
+
replaced by `String.prototype.trim`, `String.prototype.repeat` and a plain property copy, so
|
|
139
|
+
no code of theirs is included
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
(The MIT License)
|
|
143
|
+
|
|
144
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
145
|
+
a copy of this software and associated documentation files (the
|
|
146
|
+
'Software'), to deal in the Software without restriction, including
|
|
147
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
148
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
149
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
150
|
+
the following conditions:
|
|
151
|
+
|
|
152
|
+
The above copyright notice and this permission notice shall be
|
|
153
|
+
included in all copies or substantial portions of the Software.
|
|
154
|
+
|
|
155
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
156
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
157
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
158
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
159
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
160
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
161
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
162
|
+
```
|
package/README.md
CHANGED
|
@@ -1,3 +1,131 @@
|
|
|
1
1
|
# remark-obsidian
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A [remark](https://github.com/remarkjs/remark) plugin that parses Markdown the way
|
|
4
|
+
[Obsidian](https://obsidian.md) does: wikilinks and embeds, callouts, `==highlights==`,
|
|
5
|
+
`#tags`, `%%comments%%`, math, footnotes and inline footnotes, frontmatter and custom task
|
|
6
|
+
boxes — with Obsidian's tokens and positions, measured against the app itself. It is the
|
|
7
|
+
Markdown parser behind [Quartz](https://quartz.jzhao.xyz)'s Obsidian support.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @quartz-community/remark-obsidian
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { unified } from "unified";
|
|
19
|
+
import remarkParse from "remark-parse";
|
|
20
|
+
import remarkGfm from "remark-gfm";
|
|
21
|
+
import remarkObsidian from "@quartz-community/remark-obsidian";
|
|
22
|
+
|
|
23
|
+
const markdown = "A [[note|link]], ==a highlight== and a #tag.\n";
|
|
24
|
+
const processor = unified().use(remarkParse).use(remarkGfm).use(remarkObsidian);
|
|
25
|
+
const tree = processor.runSync(processor.parse(markdown), markdown);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Add the plugin **after** `remark-parse`: under `legacy` it replaces the processor's parser,
|
|
29
|
+
and a `remark-parse` added later would put micromark back. Under `legacy`, other plugins'
|
|
30
|
+
micromark syntax extensions (`remark-directive`, `remark-frontmatter`, …) are therefore not
|
|
31
|
+
consulted, though their transforms still run; use `strict` if you rely on one. Under `strict`,
|
|
32
|
+
pass the source to `run`, as above: its passes read it.
|
|
33
|
+
|
|
34
|
+
The result is ordinary mdast with this package's node types — `wikilink`, `highlight`, `tag`,
|
|
35
|
+
`comment`, `callout`, `calloutTitle`, `footnote` — so downstream remark and rehype plugins work
|
|
36
|
+
unchanged, and `remark-stringify` writes every one of them back. Rendering them to HTML is the
|
|
37
|
+
renderer's job: in Quartz, its `obsidian-flavored-markdown` transformer and
|
|
38
|
+
`@quartz-community/rehype-obsidian`. With plain `remark-rehype` they fall back to generic
|
|
39
|
+
elements.
|
|
40
|
+
|
|
41
|
+
## Two presets
|
|
42
|
+
|
|
43
|
+
`strict` is what Obsidian **intends**: the CommonMark, GFM and LaTeX it says it supports,
|
|
44
|
+
plus the syntax it documents adding. `legacy` is what Obsidian **delivers**, divergences
|
|
45
|
+
included:
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
.use(remarkObsidian) // legacy, the default
|
|
49
|
+
.use(remarkObsidian, { preset: "strict" }) // CommonMark/GFM/LaTeX + Obsidian's syntax
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
| | `legacy` (default) | `strict` |
|
|
53
|
+
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | -------- |
|
|
54
|
+
| Obsidian's documented syntax — wikilinks, embeds, callouts, tags, `%%`, `==`, `$`, frontmatter, task boxes holding any character, footnotes — each read as Obsidian reads it, inside quotes and lists too | on | **on** |
|
|
55
|
+
| What Obsidian delivers beyond the standards — emphasis, lists, entities, autolinks, code spans, html blocks, link labels, tab arithmetic | on | **off** |
|
|
56
|
+
| Its rendering — an undefined `[^x]` shown without its brackets, a line ending shown as a break | on | **off** |
|
|
57
|
+
|
|
58
|
+
**Use `legacy`** for an Obsidian plugin, or for Quartz rendering a vault: the point is that
|
|
59
|
+
the output matches what the author saw in the app. It parses with remark-parse 8 — the parser
|
|
60
|
+
Obsidian itself forks — plus Obsidian's own readers, so its tokens and positions are
|
|
61
|
+
Obsidian's rather than an approximation of them. The parser is vendored and bundled; nothing
|
|
62
|
+
extra is installed.
|
|
63
|
+
|
|
64
|
+
**Use `strict`** for what a note means rather than how one app shows it. Obsidian says it
|
|
65
|
+
supports CommonMark, GFM and LaTeX; its emphasis, list, entity, autolink, code-span,
|
|
66
|
+
html-block and link-label behaviour departs from them, inherited from remark-parse 8 and never
|
|
67
|
+
fixed. `strict` keeps the standards and Obsidian's documented syntax, and parses with
|
|
68
|
+
micromark, as `remark-parse` does. `*a**` is literal text under `legacy`, as in Obsidian, and
|
|
69
|
+
emphasis followed by `*` under `strict`, as in CommonMark.
|
|
70
|
+
|
|
71
|
+
## Options
|
|
72
|
+
|
|
73
|
+
Every option is a boolean, works under both presets, and wins over the preset's value for it.
|
|
74
|
+
|
|
75
|
+
| option | default | what it does |
|
|
76
|
+
| ------------------- | ------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
77
|
+
| `preset` | `"legacy"` | `"legacy"` or `"strict"`, as above |
|
|
78
|
+
| `wikilinks` | on | `[[target#heading\|alias]]` and `![[embed]]` as `wikilink` nodes |
|
|
79
|
+
| `highlights` | on | `==text==` as `highlight` |
|
|
80
|
+
| `tags` | on | `#tag` as `tag` |
|
|
81
|
+
| `math` | on | `$inline$` and `$$display$$` |
|
|
82
|
+
| `comments` | on | `%%comment%%` |
|
|
83
|
+
| `keepComments` | on | keep a comment as a `comment` node rather than deleting it; it renders as an empty `<obsidian-comment>`, which `rehype-obsidian` removes |
|
|
84
|
+
| `parseComments` | on | parse a kept comment's body into its `children`, so a reference inside one is a `footnoteReference` |
|
|
85
|
+
| `callouts` | on | `> [!type] Title` as a `callout` holding a `calloutTitle` |
|
|
86
|
+
| `inlineFootnotes` | on | `^[note]` as a `footnote` |
|
|
87
|
+
| `customTaskChars` | on | any one character in a task box is a checkbox (`- [-]`), kept as `data.taskChar` |
|
|
88
|
+
| `frontmatter` | on | a leading `---` block as a `yaml` node |
|
|
89
|
+
| `bareFootnoteRefs` | on under `legacy`, off under `strict` | Obsidian renders an undefined `[^x]` as `x`; the node stays a `footnoteReference`, and `rehype-obsidian` drops the delimiters when rendering |
|
|
90
|
+
| `positionedBreaks` | on under `legacy`, off under `strict` | a soft line ending becomes a positioned `break`, as `remark-breaks` would make it |
|
|
91
|
+
| `lineOffsets` | on | `root.data.lineOffsets`: how many columns each line's containers consume |
|
|
92
|
+
| `escapedLineBreaks` | off | write a `break` back as a trailing backslash rather than a newline, for a chain without `remark-breaks` |
|
|
93
|
+
|
|
94
|
+
## Upgrading from 1.x
|
|
95
|
+
|
|
96
|
+
2.0 is a major release, and [the changelog](CHANGELOG.md) lists every change. In short: add the
|
|
97
|
+
plugin after `remark-parse`, and expect the new node types (`callout`, `calloutTitle`,
|
|
98
|
+
`footnote`, `yaml`, kept `comment`s) and the positioned `break`s that the options above turn on
|
|
99
|
+
by default. Turn off any you do not want; `keepComments: false` restores 1.x's deleted
|
|
100
|
+
comments. Nothing was removed from the API.
|
|
101
|
+
|
|
102
|
+
## Obsidian parity
|
|
103
|
+
|
|
104
|
+
This plugin targets the **reading-mode and `metadataCache` semantics of a specific public
|
|
105
|
+
Obsidian release**, currently 1.14.5. A harness renders a generated corpus inside real Obsidian
|
|
106
|
+
and compares the result against ours, so the claim is measured rather than asserted —
|
|
107
|
+
including the divergences, which are enumerated rather than implied:
|
|
108
|
+
|
|
109
|
+
- **`legacy` matches Obsidian on all 3,469 recorded cases marked to match**, of 3,471. The other
|
|
110
|
+
two are a rendering difference between Obsidian's own two renderers and an embed that
|
|
111
|
+
resolves a note into itself.
|
|
112
|
+
- **On 6,844 notes whose footnote answers Obsidian's cache recorded**, `legacy` agrees on 6,830,
|
|
113
|
+
down to every definition's and reference's exact start and end offsets. The 14 left are
|
|
114
|
+
places where the cache misplaces a fact or the answers' recording added one.
|
|
115
|
+
- **`strict` matches `remark-parse` and `remark-gfm`** on every CommonMark and GFM spec example
|
|
116
|
+
except eight: six that hold Obsidian syntax, and two task lists where it adds
|
|
117
|
+
`data.taskChar`. It answers 513 live probes
|
|
118
|
+
about Obsidian's syntax and footnotes as Obsidian does, bar a few recorded exclusions.
|
|
119
|
+
|
|
120
|
+
## Development
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
npm test # unit tests and the Obsidian parity gates
|
|
124
|
+
npm run typecheck # both tsconfig projects
|
|
125
|
+
npm run lint # src only
|
|
126
|
+
npm run format # prettier check
|
|
127
|
+
npm run build
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`npm test` runs the gates against committed goldens and needs no Obsidian. Re-recording the
|
|
131
|
+
goldens does — see [`test/parity/README.md`](test/parity/README.md).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Literal, Parent, Root } from 'mdast';
|
|
1
|
+
import { Literal, Parent, RootContent, Root, Nodes } from 'mdast';
|
|
2
2
|
import { Extension } from 'micromark-util-types';
|
|
3
3
|
import { Extension as Extension$1 } from 'mdast-util-from-markdown';
|
|
4
4
|
import { Options } from 'mdast-util-to-markdown';
|
|
@@ -14,12 +14,51 @@ interface Wikilink extends Literal {
|
|
|
14
14
|
interface Highlight extends Parent {
|
|
15
15
|
type: "highlight";
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* A `%%` comment. `value` is the body as written; `children` is that same body
|
|
19
|
+
* parsed, when the `parseComments` option is on.
|
|
20
|
+
*
|
|
21
|
+
* Both, rather than one or the other. `value` is what the serialiser writes
|
|
22
|
+
* back, so it stays the source of truth for round-tripping -- and a comment is
|
|
23
|
+
* the one construct whose body Obsidian *indexes without rendering*, so a
|
|
24
|
+
* reference written inside one is live to `metadataCache` while nothing in the
|
|
25
|
+
* document shows it. A consumer that has to find such a reference, and place an
|
|
26
|
+
* edit on it, needs real nodes with real positions rather than a string it
|
|
27
|
+
* would have to re-scan.
|
|
28
|
+
*
|
|
29
|
+
* The children are block content for a comment that stands alone and phrasing
|
|
30
|
+
* for one inside a paragraph, matching the position the comment itself holds --
|
|
31
|
+
* a `comment` is registered in both content maps.
|
|
32
|
+
*/
|
|
17
33
|
interface Comment extends Literal {
|
|
18
34
|
type: "comment";
|
|
35
|
+
children?: RootContent[];
|
|
19
36
|
}
|
|
20
37
|
interface Tag extends Literal {
|
|
21
38
|
type: "tag";
|
|
22
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Obsidian's `^[body]`. `footnote` is the historical mdast type and the one
|
|
42
|
+
* `remark-footnotes` emits, which is what Obsidian parses with; `@types/mdast` v4
|
|
43
|
+
* dropped it when GFM footnotes landed, so it is declared here.
|
|
44
|
+
*/
|
|
45
|
+
interface InlineFootnote extends Parent {
|
|
46
|
+
type: "footnote";
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* `> [!type] Title`. `collapsed` is `null` when no fold marker is present, `true`
|
|
50
|
+
* for `-`, `false` for `+`. `title` is as written and may be empty; Obsidian then
|
|
51
|
+
* displays the capitalised type.
|
|
52
|
+
*/
|
|
53
|
+
interface CalloutTitle extends Parent {
|
|
54
|
+
type: "calloutTitle";
|
|
55
|
+
}
|
|
56
|
+
interface Callout extends Parent {
|
|
57
|
+
type: "callout";
|
|
58
|
+
calloutType: string;
|
|
59
|
+
title: string;
|
|
60
|
+
collapsed: boolean | null;
|
|
61
|
+
}
|
|
23
62
|
declare module "mdast" {
|
|
24
63
|
interface ListItemData {
|
|
25
64
|
taskChar?: string;
|
|
@@ -29,12 +68,27 @@ declare module "mdast" {
|
|
|
29
68
|
highlight: Highlight;
|
|
30
69
|
comment: Comment;
|
|
31
70
|
tag: Tag;
|
|
71
|
+
footnote: InlineFootnote;
|
|
72
|
+
callout: Callout;
|
|
73
|
+
calloutTitle: CalloutTitle;
|
|
74
|
+
}
|
|
75
|
+
interface RootData {
|
|
76
|
+
/**
|
|
77
|
+
* Characters consumed by containers on each line, keyed by one-based line
|
|
78
|
+
* number -- `remark-parse@8`'s `offset` table, which Obsidian's parser
|
|
79
|
+
* still keeps.
|
|
80
|
+
*
|
|
81
|
+
* A line no container owns is absent rather than zero, as it was there.
|
|
82
|
+
* Only present when the `lineOffsets` option is on.
|
|
83
|
+
*/
|
|
84
|
+
lineOffsets?: Record<number, number>;
|
|
32
85
|
}
|
|
33
86
|
interface PhrasingContentMap {
|
|
34
87
|
wikilink: Wikilink;
|
|
35
88
|
highlight: Highlight;
|
|
36
89
|
comment: Comment;
|
|
37
90
|
tag: Tag;
|
|
91
|
+
footnote: InlineFootnote;
|
|
38
92
|
}
|
|
39
93
|
}
|
|
40
94
|
declare module "micromark-util-types" {
|
|
@@ -47,15 +101,25 @@ declare module "micromark-util-types" {
|
|
|
47
101
|
wikilinkHeading: "wikilinkHeading";
|
|
48
102
|
wikilinkAliasMarker: "wikilinkAliasMarker";
|
|
49
103
|
wikilinkAlias: "wikilinkAlias";
|
|
104
|
+
wikilinkCloserCheck: "wikilinkCloserCheck";
|
|
50
105
|
highlight: "highlight";
|
|
51
106
|
highlightMarker: "highlightMarker";
|
|
52
107
|
highlightContent: "highlightContent";
|
|
108
|
+
highlightSequence: "highlightSequence";
|
|
109
|
+
highlightSequenceTemporary: "highlightSequenceTemporary";
|
|
110
|
+
highlightText: "highlightText";
|
|
53
111
|
comment: "comment";
|
|
54
112
|
commentMarker: "commentMarker";
|
|
55
113
|
commentContent: "commentContent";
|
|
56
114
|
tag: "tag";
|
|
57
115
|
tagMarker: "tagMarker";
|
|
58
116
|
tagContent: "tagContent";
|
|
117
|
+
inlineFootnote: "inlineFootnote";
|
|
118
|
+
inlineFootnoteMarker: "inlineFootnoteMarker";
|
|
119
|
+
inlineFootnoteContent: "inlineFootnoteContent";
|
|
120
|
+
legacyQuotedCloserAhead: "legacyQuotedCloserAhead";
|
|
121
|
+
legacyChunkScan: "legacyChunkScan";
|
|
122
|
+
legacyBacktickScan: "legacyBacktickScan";
|
|
59
123
|
}
|
|
60
124
|
}
|
|
61
125
|
|
|
@@ -67,6 +131,21 @@ declare function commentSyntax(): Extension;
|
|
|
67
131
|
|
|
68
132
|
declare function tagSyntax(): Extension;
|
|
69
133
|
|
|
134
|
+
/**
|
|
135
|
+
* `^[body]`, Obsidian's inline footnote. Not a GFM construct, so `remark-gfm`
|
|
136
|
+
* leaves it as literal text.
|
|
137
|
+
*
|
|
138
|
+
* Every rule here is measured against Obsidian 1.14.2 rather than reasoned about,
|
|
139
|
+
* after two guesses proved wrong: an **empty** body is still a footnote (`^[]`
|
|
140
|
+
* renders a marker), and the body **may span lines** (`^[a\nb]` is one footnote).
|
|
141
|
+
* The body also holds balanced brackets, so `^[body with [a link](u)]` closes on
|
|
142
|
+
* the final `]`; it swallows a reference-shaped string, making `^[^literal]`
|
|
143
|
+
* footnote text rather than a reference to `literal`; and an escaped caret is not
|
|
144
|
+
* an opener, so `\^[^x]` leaves a real reference — which stock `remark-footnotes`
|
|
145
|
+
* gets wrong.
|
|
146
|
+
*/
|
|
147
|
+
declare function inlineFootnoteSyntax(): Extension;
|
|
148
|
+
|
|
70
149
|
declare function wikilinkFromMarkdown(): Extension$1;
|
|
71
150
|
|
|
72
151
|
declare function highlightFromMarkdown(): Extension$1;
|
|
@@ -85,16 +164,210 @@ declare function tagToMarkdown(): Options;
|
|
|
85
164
|
|
|
86
165
|
declare function customTaskCharTransform(tree: Root, source?: string): void;
|
|
87
166
|
|
|
167
|
+
/**
|
|
168
|
+
* Obsidian treats any `$$`-delimited math as display, wherever it appears:
|
|
169
|
+
* `$$E=mc^2$$`, `- $$x^2$$` and `# $$x^2$$` all render as display math inside the
|
|
170
|
+
* surrounding block. `micromark-extension-math` classifies by position instead, so
|
|
171
|
+
* a `$$` run inside a paragraph arrives as inline.
|
|
172
|
+
*
|
|
173
|
+
* The node stays inline, because Obsidian's own output is an inline element
|
|
174
|
+
* carrying display styling (`<span class="math math-block">`) rather than a block.
|
|
175
|
+
* Only the classification and the rendered class change.
|
|
176
|
+
*/
|
|
177
|
+
declare function mathDisplayTransform(tree: Root, source: string): void;
|
|
178
|
+
|
|
179
|
+
declare function bareFootnoteRefTransform(tree: Root, source?: string, options?: {
|
|
180
|
+
/**
|
|
181
|
+
* Convert only references to these identifiers, as GFM would have: `strict`'s use, where a
|
|
182
|
+
* reference nothing defines stays literal, but a definition that a pass built from a
|
|
183
|
+
* re-parsed fragment -- a callout's title line, a comment's tail -- still has to be found.
|
|
184
|
+
* micromark resolved every reference before those definitions existed.
|
|
185
|
+
*/
|
|
186
|
+
readonly defined?: ReadonlySet<string>;
|
|
187
|
+
}): void;
|
|
188
|
+
|
|
189
|
+
declare function calloutTransform(tree: Root, source?: string, reparse?: (markdown: string) => Root): void;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Re-parse whatever follows a block comment's closing `%%` on the same line.
|
|
193
|
+
*
|
|
194
|
+
* Obsidian ends a comment at its closer wherever that falls and reads the rest of
|
|
195
|
+
* the line as a new block, so `%%\nhidden\n%% [^1]: def` is a comment plus a
|
|
196
|
+
* footnote definition. A flow construct in micromark owns whole lines and cannot
|
|
197
|
+
* stop mid-line, so the tokenizer absorbs that tail into the comment instead —
|
|
198
|
+
* deliberately, because rejecting there used to drop every later line of the note.
|
|
199
|
+
*
|
|
200
|
+
* This puts the block structure back without rewriting the source: the comment is
|
|
201
|
+
* trimmed to its closer and the tail is parsed on its own and spliced in after it.
|
|
202
|
+
* Positions therefore stay true to the document the author wrote.
|
|
203
|
+
*
|
|
204
|
+
* Inside a quote or list item too: `> %%` / `> hidden` / `> %% [^1]: freed` defines `1`.
|
|
205
|
+
*/
|
|
206
|
+
declare function commentTailTransform(tree: Root, source: string, reparse: (markdown: string) => Root): void;
|
|
207
|
+
|
|
88
208
|
declare function taskCharToMarkdown(): Options;
|
|
89
209
|
|
|
210
|
+
interface CollectWikilinksOptions {
|
|
211
|
+
/**
|
|
212
|
+
* Restrict results to embeds (`![[…]]`) or to plain links (`[[…]]`).
|
|
213
|
+
* Omit to collect both.
|
|
214
|
+
*/
|
|
215
|
+
embedded?: boolean;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Type guard for the `wikilink` node this plugin adds to mdast.
|
|
219
|
+
*/
|
|
220
|
+
declare function isWikilink(node: unknown): node is Wikilink;
|
|
221
|
+
/**
|
|
222
|
+
* Type guard for an embedded wikilink, written `![[target]]`.
|
|
223
|
+
*
|
|
224
|
+
* Embedding is the difference between transcluding a target and merely linking
|
|
225
|
+
* to it, and is the distinction consumers most often need. Keeping the rule
|
|
226
|
+
* here stops each consumer from re-deriving it.
|
|
227
|
+
*/
|
|
228
|
+
declare function isEmbed(node: unknown): node is Wikilink;
|
|
229
|
+
/**
|
|
230
|
+
* Collect wikilinks from a tree, in document order.
|
|
231
|
+
*/
|
|
232
|
+
declare function collectWikilinks(tree: Nodes | Root, options?: CollectWikilinksOptions): Wikilink[];
|
|
233
|
+
/**
|
|
234
|
+
* Collect the target of every embed in a tree, in document order and without
|
|
235
|
+
* duplicates.
|
|
236
|
+
*
|
|
237
|
+
* Obsidian embeds a target with either `![[target]]` or ``, so both
|
|
238
|
+
* the `wikilink` nodes this plugin adds and mdast's own `image` nodes count.
|
|
239
|
+
* Targets keep their original form, including any heading or block reference;
|
|
240
|
+
* resolving them to files is the caller's concern.
|
|
241
|
+
*
|
|
242
|
+
* Nodes inside fenced code are not embeds and are never returned: fenced code
|
|
243
|
+
* parses to a `code` node whose content is not traversed as phrasing content.
|
|
244
|
+
*/
|
|
245
|
+
declare function collectEmbedPaths(tree: Nodes | Root): string[];
|
|
246
|
+
|
|
247
|
+
/** Marker element a kept comment renders as, which `rehype-obsidian` removes. */
|
|
248
|
+
declare const COMMENT_ELEMENT = "obsidian-comment";
|
|
90
249
|
interface RemarkObsidianOptions {
|
|
250
|
+
/** Defaults to `legacy`. See {@link RemarkObsidianPreset}. */
|
|
251
|
+
preset?: RemarkObsidianPreset;
|
|
91
252
|
wikilinks?: boolean;
|
|
92
253
|
highlights?: boolean;
|
|
93
254
|
comments?: boolean;
|
|
94
255
|
tags?: boolean;
|
|
256
|
+
/**
|
|
257
|
+
* Read any one character between a task's brackets as a checkbox, completed unless it is a
|
|
258
|
+
* space: `- [-]`, `- [?]` and `- [>]` are tasks, with the character kept as `data.taskChar`.
|
|
259
|
+
* Obsidian documents this ("You can use any character inside the brackets to mark it as
|
|
260
|
+
* complete"), so it is on under both presets; off, only GFM's `[ ]` and `[x]` are boxes.
|
|
261
|
+
*/
|
|
95
262
|
customTaskChars?: boolean;
|
|
96
263
|
math?: boolean;
|
|
264
|
+
/**
|
|
265
|
+
* Parse a leading `---` block as YAML frontmatter. On by default because
|
|
266
|
+
* Obsidian always does, and leaving it off is not neutral: the `---` becomes a
|
|
267
|
+
* thematic break or setext heading and the YAML body leaks into the document as
|
|
268
|
+
* a list, so everything downstream sees blocks that are not there. Turn it off
|
|
269
|
+
* only when something earlier in the pipeline has already consumed it.
|
|
270
|
+
*/
|
|
271
|
+
frontmatter?: boolean;
|
|
272
|
+
/**
|
|
273
|
+
* Keep `comment` nodes in the tree instead of deleting them, so a consumer can
|
|
274
|
+
* see where `%%` comments are. A linter needs that, and it is what lets a
|
|
275
|
+
* block-level view report a comment at all.
|
|
276
|
+
*
|
|
277
|
+
* The body is still never rendered: each kept node carries `data.hChildren: []`,
|
|
278
|
+
* which makes `mdast-util-to-hast` emit an empty `<obsidian-comment>` element
|
|
279
|
+
* instead of its default for an unknown node with a `value` — a text node
|
|
280
|
+
* holding the comment body. `rehype-obsidian` removes the empty element; a chain
|
|
281
|
+
* without it shows a stray empty tag, never the comment text.
|
|
282
|
+
*/
|
|
283
|
+
keepComments?: boolean;
|
|
284
|
+
/**
|
|
285
|
+
* Parse a kept comment's body into `children`, beside the `value` it already
|
|
286
|
+
* carries. Obsidian indexes what a comment contains without rendering it, so
|
|
287
|
+
* a reference written inside one is live to `metadataCache` while nothing in
|
|
288
|
+
* the document shows it; this is what lets a consumer find and place an edit
|
|
289
|
+
* on such a node instead of re-scanning a string.
|
|
290
|
+
*
|
|
291
|
+
* Additive: `value` is untouched and the serialiser still writes from it, so
|
|
292
|
+
* round-tripping is unchanged. Needs `keepComments`, since there is no node
|
|
293
|
+
* to parse into otherwise.
|
|
294
|
+
*/
|
|
295
|
+
parseComments?: boolean;
|
|
296
|
+
/**
|
|
297
|
+
* Record `remark-parse@8`'s `offset` table on the root as
|
|
298
|
+
* `data.lineOffsets`: how many characters each line's containers consume,
|
|
299
|
+
* keyed by one-based line number, with a line no container owns absent.
|
|
300
|
+
*
|
|
301
|
+
* It is what converts a column inside a stripped line back into a column in
|
|
302
|
+
* the file, and no node position carries it for a continuation line -- `> b`
|
|
303
|
+
* below `> a` re-states the prefix without starting a node. Obsidian's own
|
|
304
|
+
* parser keeps the same table, so reproducing its reported columns needs it.
|
|
305
|
+
*/
|
|
306
|
+
lineOffsets?: boolean;
|
|
307
|
+
/**
|
|
308
|
+
* Strip the delimiters from a footnote reference nothing defines, so `see [^x]`
|
|
309
|
+
* reads `see x` as Obsidian renders it. GFM keeps an unmatched reference literal,
|
|
310
|
+
* so this is a deliberate divergence from the spec in favour of matching the app.
|
|
311
|
+
*/
|
|
312
|
+
bareFootnoteRefs?: boolean;
|
|
313
|
+
/** Parse Obsidian's `^[body]` inline footnote, which GFM has no form for. */
|
|
314
|
+
inlineFootnotes?: boolean;
|
|
315
|
+
/**
|
|
316
|
+
* Promote `> [!type] Title` blockquotes into `callout` nodes. Obsidian reports
|
|
317
|
+
* these as their own block type, so a blockquote here is a divergence rather
|
|
318
|
+
* than a neutral choice.
|
|
319
|
+
*/
|
|
320
|
+
callouts?: boolean;
|
|
321
|
+
/**
|
|
322
|
+
* Convert a soft line ending into a positioned `break`, so `remark-breaks` has
|
|
323
|
+
* nothing left to do.
|
|
324
|
+
*
|
|
325
|
+
* That package is four lines which throw positions away: `newlineToBreak` is
|
|
326
|
+
* `findAndReplace(tree, [/\r?\n|\r/g, replace])`, `replace` returns a bare
|
|
327
|
+
* `{type: "break"}`, and `findAndReplace` rebuilds the surrounding text without
|
|
328
|
+
* positions either. Doing the same conversion first leaves its regular expression
|
|
329
|
+
* nothing to match, so the tree is identical and every node keeps its place.
|
|
330
|
+
*
|
|
331
|
+
* On by default, because this package is built for a chain that includes
|
|
332
|
+
* `remark-breaks` and is ordered before it. Turn it off for a chain that has no
|
|
333
|
+
* `remark-breaks`, where a soft line ending is not a `break` at all.
|
|
334
|
+
*/
|
|
335
|
+
positionedBreaks?: boolean;
|
|
336
|
+
/**
|
|
337
|
+
* Write a line break as a trailing backslash rather than a newline.
|
|
338
|
+
*
|
|
339
|
+
* Off by default, because this package is built for a chain that includes
|
|
340
|
+
* `remark-breaks`, where every soft line ending becomes a `break` and a
|
|
341
|
+
* newline writes it back unchanged. Turn it on when your chain has no
|
|
342
|
+
* `remark-breaks` and a `break` really is a hard break.
|
|
343
|
+
*/
|
|
344
|
+
escapedLineBreaks?: boolean;
|
|
97
345
|
}
|
|
346
|
+
/**
|
|
347
|
+
* Which body of behaviour to follow where Obsidian and CommonMark disagree.
|
|
348
|
+
*
|
|
349
|
+
* `legacy` reproduces Obsidian, which is what an Obsidian plugin or a Quartz site
|
|
350
|
+
* rendering a vault needs: the whole point is that the output matches what the
|
|
351
|
+
* author saw in the app. It is the default, and it is every option at the value the
|
|
352
|
+
* parity corpus is measured against.
|
|
353
|
+
*
|
|
354
|
+
* `strict` keeps Obsidian's *syntax* -- wikilinks, embeds, callouts, tags, `%%`
|
|
355
|
+
* comments, `==highlights==`, `$math$`, frontmatter -- while parsing everything
|
|
356
|
+
* CommonMark and GFM already define the way they define it. That is what a consumer
|
|
357
|
+
* outside Obsidian usually wants: Obsidian's extensions are the reason to use this
|
|
358
|
+
* package, but its emphasis, list, entity, autolink, code-span, html-block and
|
|
359
|
+
* link-label divergences are bugs it inherited from `remark-parse@8` and has not
|
|
360
|
+
* fixed, and reproducing them off-platform helps nobody.
|
|
361
|
+
*
|
|
362
|
+
* In short, `strict` is what Obsidian INTENDS -- the CommonMark, GFM and LaTeX it says it
|
|
363
|
+
* supports, plus the syntax it documents adding -- and `legacy` is what it DELIVERS. `legacy`
|
|
364
|
+
* parses with remark-parse 8, the parser Obsidian forks; `strict` parses with micromark, as
|
|
365
|
+
* `remark-parse` does. The feature options below work under both, and an explicit one always
|
|
366
|
+
* wins over the preset's value for it.
|
|
367
|
+
*/
|
|
368
|
+
type RemarkObsidianPreset = "legacy" | "strict";
|
|
369
|
+
/** Every behaviour flag, with the preset selector itself excluded. */
|
|
370
|
+
type RemarkObsidianFlags = Required<Omit<RemarkObsidianOptions, "preset">>;
|
|
98
371
|
declare function remarkObsidian(userOpts?: RemarkObsidianOptions): undefined | ((tree: Root, file: any) => void);
|
|
99
372
|
|
|
100
|
-
export { type Comment, type Highlight, type RemarkObsidianOptions, type Tag, type Wikilink, commentFromMarkdown, commentSyntax, commentToMarkdown, customTaskCharTransform, remarkObsidian as default, highlightFromMarkdown, highlightSyntax, highlightToMarkdown, tagFromMarkdown, tagSyntax, tagToMarkdown, taskCharToMarkdown, wikilinkFromMarkdown, wikilinkSyntax, wikilinkToMarkdown };
|
|
373
|
+
export { COMMENT_ELEMENT, type Callout, type CalloutTitle, type CollectWikilinksOptions, type Comment, type Highlight, type InlineFootnote, type RemarkObsidianFlags, type RemarkObsidianOptions, type RemarkObsidianPreset, type Tag, type Wikilink, bareFootnoteRefTransform, calloutTransform, collectEmbedPaths, collectWikilinks, commentFromMarkdown, commentSyntax, commentTailTransform, commentToMarkdown, customTaskCharTransform, remarkObsidian as default, highlightFromMarkdown, highlightSyntax, highlightToMarkdown, inlineFootnoteSyntax, isEmbed, isWikilink, mathDisplayTransform, tagFromMarkdown, tagSyntax, tagToMarkdown, taskCharToMarkdown, wikilinkFromMarkdown, wikilinkSyntax, wikilinkToMarkdown };
|