@quartz-community/remark-obsidian 2.2.1 → 2.2.2
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/README.md +22 -0
- package/dist/index.d.ts +40 -2
- package/dist/index.js.map +1 -1
- package/dist/legacy.d.ts +1 -0
- package/dist/legacy.js.map +1 -1
- package/package.json +8 -5
package/README.md
CHANGED
|
@@ -38,6 +38,28 @@ renderer's job: in Quartz, its `obsidian-flavored-markdown` transformer and
|
|
|
38
38
|
`@quartz-community/rehype-obsidian`. With plain `remark-rehype` they fall back to generic
|
|
39
39
|
elements.
|
|
40
40
|
|
|
41
|
+
### TypeScript
|
|
42
|
+
|
|
43
|
+
The package ships its types, and importing the plugin is enough to register its node types on
|
|
44
|
+
`mdast`'s content maps, together with `math` and `inlineMath`, so a check on `node.type`
|
|
45
|
+
narrows to the right node:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import type { Root } from "mdast";
|
|
49
|
+
import { visit } from "unist-util-visit";
|
|
50
|
+
|
|
51
|
+
processor.use(() => (tree: Root) => {
|
|
52
|
+
visit(tree, (node) => {
|
|
53
|
+
if (node.type === "inlineMath") node.value = node.value.trim();
|
|
54
|
+
if (node.type === "wikilink") console.log(node.path, node.embedded);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Install `@types/mdast` yourself to name `Root` or any other mdast type in your own code, as with
|
|
60
|
+
every remark plugin. The node interfaces are exported too: `Wikilink`, `Callout`, `Math`,
|
|
61
|
+
`InlineMath` and the rest.
|
|
62
|
+
|
|
41
63
|
## Two presets
|
|
42
64
|
|
|
43
65
|
`strict` is what Obsidian **intends**: the CommonMark, GFM and LaTeX it says it supports,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Parent, Data, Literal, RootContent, Root, Nodes } from 'mdast';
|
|
2
2
|
import { Position, Point } from 'unist';
|
|
3
3
|
import { Extension } from 'micromark-util-types';
|
|
4
4
|
import { Extension as Extension$1 } from 'mdast-util-from-markdown';
|
|
5
5
|
import { Options } from 'mdast-util-to-markdown';
|
|
6
|
+
export { InlineMath, Math } from 'mdast-util-math';
|
|
6
7
|
|
|
8
|
+
/**
|
|
9
|
+
* A wikilink's parts as the author spelled them, where Obsidian's resolution changed them. The
|
|
10
|
+
* writer builds a wikilink from its parts and writes a spelling only while it still resolves to
|
|
11
|
+
* the part, so editing `path` or `heading` wins over these.
|
|
12
|
+
*/
|
|
13
|
+
interface WikilinkData extends Data {
|
|
14
|
+
/**
|
|
15
|
+
* `path` as written, where resolving changed it: a no-break space read as a space, NFC, or
|
|
16
|
+
* the backslash before `]]` and the whitespace before it dropped (`[[a \]]` links to `a`).
|
|
17
|
+
*/
|
|
18
|
+
spelledPath?: string;
|
|
19
|
+
/** `heading` as written, where resolving changed it, as for `spelledPath`. */
|
|
20
|
+
spelledHeading?: string;
|
|
21
|
+
/** Which part lost a backslash before `]]` (`[[a\]]` links to `a`), so it is written back. */
|
|
22
|
+
strippedBackslash?: "path" | "heading";
|
|
23
|
+
}
|
|
7
24
|
interface Wikilink extends Literal {
|
|
8
25
|
type: "wikilink";
|
|
9
26
|
value: string;
|
|
@@ -11,6 +28,7 @@ interface Wikilink extends Literal {
|
|
|
11
28
|
path: string;
|
|
12
29
|
heading: string;
|
|
13
30
|
alias: string;
|
|
31
|
+
data?: WikilinkData;
|
|
14
32
|
}
|
|
15
33
|
interface Highlight extends Parent {
|
|
16
34
|
type: "highlight";
|
|
@@ -82,10 +100,21 @@ declare module "mdast" {
|
|
|
82
100
|
interface LinkReferenceData {
|
|
83
101
|
/** `false` on a reference `keepUndefinedReferences` kept: this parse found no definition. */
|
|
84
102
|
defined?: false;
|
|
103
|
+
/**
|
|
104
|
+
* The label as written, under `legacy`, where decoding changed it (`[x][&]`). The writer
|
|
105
|
+
* uses it while it still decodes to `label`, since the identifier comes from the raw text.
|
|
106
|
+
*/
|
|
107
|
+
spelledLabel?: string;
|
|
85
108
|
}
|
|
86
109
|
interface ImageReferenceData {
|
|
87
110
|
/** `false` on a reference `keepUndefinedReferences` kept: this parse found no definition. */
|
|
88
111
|
defined?: false;
|
|
112
|
+
/** The label as written, as on a link reference. */
|
|
113
|
+
spelledLabel?: string;
|
|
114
|
+
}
|
|
115
|
+
interface BlockContentMap {
|
|
116
|
+
callout: Callout;
|
|
117
|
+
comment: Comment;
|
|
89
118
|
}
|
|
90
119
|
interface RootContentMap {
|
|
91
120
|
wikilink: Wikilink;
|
|
@@ -120,6 +149,15 @@ declare module "mdast" {
|
|
|
120
149
|
footnote: InlineFootnote;
|
|
121
150
|
}
|
|
122
151
|
}
|
|
152
|
+
declare module "mdast-util-math" {
|
|
153
|
+
interface InlineMathData {
|
|
154
|
+
/**
|
|
155
|
+
* `true` on inline math written with `$$` (`a $$x$$ b`), which Obsidian renders as display
|
|
156
|
+
* math inside the surrounding block. The node stays inline; `hProperties` carries the class.
|
|
157
|
+
*/
|
|
158
|
+
display?: boolean;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
123
161
|
declare module "micromark-util-types" {
|
|
124
162
|
interface TokenTypeMap {
|
|
125
163
|
wikilink: "wikilink";
|
|
@@ -465,4 +503,4 @@ type RemarkObsidianPreset = "legacy" | "strict";
|
|
|
465
503
|
type RemarkObsidianFlags = Required<Omit<RemarkObsidianOptions, "preset">>;
|
|
466
504
|
declare function remarkObsidian(userOpts?: RemarkObsidianOptions): undefined | ((tree: Root, file: any) => void);
|
|
467
505
|
|
|
468
|
-
export { COMMENT_ELEMENT, type Callout, type CalloutData, 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 };
|
|
506
|
+
export { COMMENT_ELEMENT, type Callout, type CalloutData, type CalloutTitle, type CollectWikilinksOptions, type Comment, type Highlight, type InlineFootnote, type RemarkObsidianFlags, type RemarkObsidianOptions, type RemarkObsidianPreset, type Tag, type Wikilink, type WikilinkData, 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 };
|