starlight-obsidian 0.7.0 → 0.7.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 +44 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# starlight-obsidian
|
|
2
2
|
|
|
3
|
+
## 0.7.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#41](https://github.com/HiDeoo/starlight-obsidian/pull/41) [`ab86671`](https://github.com/HiDeoo/starlight-obsidian/commit/ab8667139930cad8322ed494a760547e896e7a27) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fixes an issue with custom aside titles including links.
|
|
8
|
+
|
|
3
9
|
## 0.7.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/libs/remark.ts
CHANGED
|
@@ -5,7 +5,18 @@ import twitterMatcher from '@astro-community/astro-embed-twitter/matcher'
|
|
|
5
5
|
import youtubeMatcher from '@astro-community/astro-embed-youtube/matcher'
|
|
6
6
|
import { toHtml } from 'hast-util-to-html'
|
|
7
7
|
import isAbsoluteUrl from 'is-absolute-url'
|
|
8
|
-
import type {
|
|
8
|
+
import type {
|
|
9
|
+
BlockContent,
|
|
10
|
+
Blockquote,
|
|
11
|
+
Code,
|
|
12
|
+
Html,
|
|
13
|
+
Image,
|
|
14
|
+
Link,
|
|
15
|
+
Parent,
|
|
16
|
+
PhrasingContent,
|
|
17
|
+
Root,
|
|
18
|
+
RootContent,
|
|
19
|
+
} from 'mdast'
|
|
9
20
|
import { findAndReplace } from 'mdast-util-find-and-replace'
|
|
10
21
|
import { toHast } from 'mdast-util-to-hast'
|
|
11
22
|
import { customAlphabet } from 'nanoid'
|
|
@@ -385,7 +396,23 @@ function handleBlockquotes(node: Blockquote, context: VisitorContext) {
|
|
|
385
396
|
return SKIP
|
|
386
397
|
}
|
|
387
398
|
|
|
388
|
-
const
|
|
399
|
+
const hasTitle = title && title.length > 0
|
|
400
|
+
const asideTitle = hasTitle ? `[${title.trim()}` : ''
|
|
401
|
+
let didEndAsideTitle = false
|
|
402
|
+
|
|
403
|
+
let asideFirstLine = `${asideDelimiter}${getStarlightCalloutType(type)}${asideTitle}`
|
|
404
|
+
if (otherLines.length > 0) {
|
|
405
|
+
if (hasTitle) {
|
|
406
|
+
asideFirstLine += ']'
|
|
407
|
+
didEndAsideTitle = true
|
|
408
|
+
}
|
|
409
|
+
asideFirstLine += `\n${otherLines.join('\n')}`
|
|
410
|
+
} else if (otherGrandChildren.length === 0) {
|
|
411
|
+
asideFirstLine += ']\n'
|
|
412
|
+
didEndAsideTitle = true
|
|
413
|
+
} else {
|
|
414
|
+
asideFirstLine += ' '
|
|
415
|
+
}
|
|
389
416
|
|
|
390
417
|
const aside: RootContent[] = [
|
|
391
418
|
{
|
|
@@ -393,9 +420,22 @@ function handleBlockquotes(node: Blockquote, context: VisitorContext) {
|
|
|
393
420
|
children: [
|
|
394
421
|
{
|
|
395
422
|
type: 'html',
|
|
396
|
-
value:
|
|
423
|
+
value: asideFirstLine,
|
|
397
424
|
},
|
|
398
|
-
...
|
|
425
|
+
...(hasTitle
|
|
426
|
+
? otherGrandChildren.flatMap<PhrasingContent>((otherGrandChild) => {
|
|
427
|
+
if (didEndAsideTitle) return otherGrandChild
|
|
428
|
+
if (otherGrandChild.type !== 'text') return otherGrandChild
|
|
429
|
+
const containsNewLine = /\r?\n/.test(otherGrandChild.value)
|
|
430
|
+
if (!containsNewLine) return otherGrandChild
|
|
431
|
+
const [firstLine, ...otherLines] = otherGrandChild.value.split(/\r?\n/)
|
|
432
|
+
didEndAsideTitle = true
|
|
433
|
+
return [
|
|
434
|
+
{ type: 'text', value: `${firstLine}]\n` },
|
|
435
|
+
{ type: 'text', value: otherLines.join('\n') },
|
|
436
|
+
]
|
|
437
|
+
})
|
|
438
|
+
: otherGrandChildren),
|
|
399
439
|
...(otherChildren.length === 0 ? [{ type: 'html', value: `\n${asideDelimiter}` } satisfies RootContent] : []),
|
|
400
440
|
],
|
|
401
441
|
},
|