starlight-obsidian 0.9.0 → 0.10.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 +14 -0
- package/index.ts +14 -0
- package/libs/integration.ts +2 -1
- package/libs/markdown.ts +13 -7
- package/libs/remark.ts +19 -0
- package/libs/starlight.ts +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# starlight-obsidian
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#61](https://github.com/HiDeoo/starlight-obsidian/pull/61) [`c4150ef`](https://github.com/HiDeoo/starlight-obsidian/commit/c4150ef713e327f218c5ee0023ba3831e51cfccd) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Adds a new configuration option `math.singleDollarTextMath` to control whether or not inline math expressions using single dollar signs should be supported or not.
|
|
8
|
+
|
|
9
|
+
This option can be useful to disable support for single dollar inline math expressions which can conflict with “normal” dollars in CommonMark.
|
|
10
|
+
|
|
11
|
+
## 0.9.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#56](https://github.com/HiDeoo/starlight-obsidian/pull/56) [`ff18bbd`](https://github.com/HiDeoo/starlight-obsidian/commit/ff18bbd6b2614e5e817fdca2005825ea1841e0a0) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fixes a potential syntax issue when converting Obsidian vault files containing void elements to MDX format.
|
|
16
|
+
|
|
3
17
|
## 0.9.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
package/index.ts
CHANGED
|
@@ -45,6 +45,20 @@ const starlightObsidianConfigSchema = z.object({
|
|
|
45
45
|
* @see https://help.obsidian.md/Files+and+folders/Accepted+file+formats
|
|
46
46
|
*/
|
|
47
47
|
ignore: z.array(z.string()).default([]),
|
|
48
|
+
/**
|
|
49
|
+
* Configures math processing options.
|
|
50
|
+
*/
|
|
51
|
+
math: z
|
|
52
|
+
.object({
|
|
53
|
+
/**
|
|
54
|
+
* Whether or not to support inline math expressions using single dollar signs.
|
|
55
|
+
*
|
|
56
|
+
* @default true
|
|
57
|
+
* @see https://github.com/micromark/micromark-extension-math/issues/6#issuecomment-1938838687
|
|
58
|
+
*/
|
|
59
|
+
singleDollarTextMath: z.boolean().default(true),
|
|
60
|
+
})
|
|
61
|
+
.default({}),
|
|
48
62
|
/**
|
|
49
63
|
* The name of the output directory containing the generated Obsidian vault pages relative to the `src/content/docs/`
|
|
50
64
|
* directory.
|
package/libs/integration.ts
CHANGED
|
@@ -15,7 +15,8 @@ export function starlightObsidianIntegration(config: StarlightObsidianConfig): A
|
|
|
15
15
|
updateConfig({
|
|
16
16
|
markdown: {
|
|
17
17
|
rehypePlugins: [rehypeStarlightObsidian, rehypeKatex],
|
|
18
|
-
|
|
18
|
+
|
|
19
|
+
remarkPlugins: [[remarkMath, { singleDollarTextMath: config.math.singleDollarTextMath }]],
|
|
19
20
|
},
|
|
20
21
|
vite: {
|
|
21
22
|
plugins: [vitePluginStarlightObsidianConfig(config)],
|
package/libs/markdown.ts
CHANGED
|
@@ -7,19 +7,14 @@ import { VFile } from 'vfile'
|
|
|
7
7
|
|
|
8
8
|
import { remarkStarlightObsidian, type TransformContext } from './remark'
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
.data('settings', { resourceLink: true })
|
|
12
|
-
.use(remarkGfm)
|
|
13
|
-
.use(remarkMath)
|
|
14
|
-
.use(remarkFrontmatter)
|
|
15
|
-
.use(remarkStarlightObsidian)
|
|
10
|
+
let processor: ReturnType<typeof remark> | undefined
|
|
16
11
|
|
|
17
12
|
export async function transformMarkdownToString(
|
|
18
13
|
filePath: string,
|
|
19
14
|
markdown: string,
|
|
20
15
|
context: TransformContext,
|
|
21
16
|
): Promise<TransformResult> {
|
|
22
|
-
const file = await
|
|
17
|
+
const file = await getProcessor(context).process(getVFile(filePath, markdown, context))
|
|
23
18
|
|
|
24
19
|
return {
|
|
25
20
|
aliases: file.data.aliases,
|
|
@@ -35,6 +30,17 @@ export async function transformMarkdownToAST(filePath: string, markdown: string,
|
|
|
35
30
|
return fromMarkdown(content)
|
|
36
31
|
}
|
|
37
32
|
|
|
33
|
+
function getProcessor(context: TransformContext): ReturnType<typeof remark> {
|
|
34
|
+
processor ??= remark()
|
|
35
|
+
.data('settings', { resourceLink: true })
|
|
36
|
+
.use(remarkGfm)
|
|
37
|
+
.use(remarkMath, { singleDollarTextMath: context.singleDollarTextMath })
|
|
38
|
+
.use(remarkFrontmatter)
|
|
39
|
+
.use(remarkStarlightObsidian)
|
|
40
|
+
|
|
41
|
+
return processor
|
|
42
|
+
}
|
|
43
|
+
|
|
38
44
|
function getVFile(filePath: string, markdown: string, context: TransformContext) {
|
|
39
45
|
return new VFile({
|
|
40
46
|
data: { ...context },
|
package/libs/remark.ts
CHANGED
|
@@ -50,6 +50,7 @@ const wikilinkReplacementRegex = /!?\[\[(?<url>(?:(?![[\]|]).)+)(?:\|(?<maybeTex
|
|
|
50
50
|
const tagReplacementRegex = /(?:^|\s)#(?<tag>[\w/-]+)/g
|
|
51
51
|
const calloutRegex = /^\[!(?<type>\w+)][+-]? ?(?<title>.*)$/
|
|
52
52
|
const imageSizeRegex = /^(?:(?<altText>.*)\|)?(?:(?<widthOnly>\d+)|(?:(?<width>\d+)x(?<height>\d+)))$/
|
|
53
|
+
const mdxNonClosingVoidElementRegex = /<(?<tag>br|hr)(?<attrs>[^/>]*)>/g
|
|
53
54
|
|
|
54
55
|
const asideDelimiter = ':::'
|
|
55
56
|
|
|
@@ -88,6 +89,10 @@ export function remarkStarlightObsidian() {
|
|
|
88
89
|
|
|
89
90
|
handleFrontmatter(tree, file, obsidianFrontmatter)
|
|
90
91
|
handleImports(tree, file)
|
|
92
|
+
|
|
93
|
+
if (file.data.isMdx) {
|
|
94
|
+
closeVoidElements(tree)
|
|
95
|
+
}
|
|
91
96
|
}
|
|
92
97
|
}
|
|
93
98
|
|
|
@@ -750,6 +755,19 @@ function createMdxNode(value: string): Html {
|
|
|
750
755
|
return { type: 'html', value }
|
|
751
756
|
}
|
|
752
757
|
|
|
758
|
+
// We are not using `remark-mdx` due to the fact that it makes the parsing step way more strict. During our inital
|
|
759
|
+
// testing round, we found out that a few users had pretty poorly formatted Markdown files (usually the result of
|
|
760
|
+
// various Obisidian migration tools) and we wanted to make sure that they could still use Starlight Obsidian.
|
|
761
|
+
// In MDX files, if the source content contains non-closing void elements, we need to convert them to self-closing
|
|
762
|
+
// ones, e.g. `<br>` to `<br/>`.
|
|
763
|
+
// At the moment, we only support `br` and `hr` elements, but based on feedback, we can eventually support all of them.
|
|
764
|
+
function closeVoidElements(tree: Root) {
|
|
765
|
+
visit(tree, 'html', (node) => {
|
|
766
|
+
node.value = node.value.replaceAll(mdxNonClosingVoidElementRegex, '<$<tag>$<attrs>/>')
|
|
767
|
+
return SKIP
|
|
768
|
+
})
|
|
769
|
+
}
|
|
770
|
+
|
|
753
771
|
function ensureTransformContext(file: VFile): asserts file is VFile & { data: TransformContext; dirname: string } {
|
|
754
772
|
if (!file.dirname || !file.data.files || file.data.output === undefined || !file.data.vault) {
|
|
755
773
|
throw new Error('Invalid transform context.')
|
|
@@ -767,6 +785,7 @@ export interface TransformContext {
|
|
|
767
785
|
includeYoutubeComponent?: boolean
|
|
768
786
|
isMdx?: true
|
|
769
787
|
output: StarlightObsidianConfig['output']
|
|
788
|
+
singleDollarTextMath: StarlightObsidianConfig['math']['singleDollarTextMath']
|
|
770
789
|
skip?: true
|
|
771
790
|
vault: Vault
|
|
772
791
|
}
|
package/libs/starlight.ts
CHANGED