starlight-obsidian 0.9.0 → 0.9.1
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 +6 -0
- package/libs/remark.ts +18 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# starlight-obsidian
|
|
2
2
|
|
|
3
|
+
## 0.9.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#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.
|
|
8
|
+
|
|
3
9
|
## 0.9.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
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.')
|