starlight-obsidian 0.4.0 → 0.4.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/libs/obsidian.ts CHANGED
@@ -9,7 +9,7 @@ import yaml from 'yaml'
9
9
  import type { StarlightObsidianConfig } from '..'
10
10
 
11
11
  import { isDirectory, isFile } from './fs'
12
- import { getExtension, isAnchor, slugifyPath, stripExtension } from './path'
12
+ import { getExtension, isAnchor, slashify, slugifyPath, stripExtension } from './path'
13
13
  import { throwUserError } from './plugin'
14
14
  import { isAssetFile } from './starlight'
15
15
 
@@ -56,7 +56,7 @@ export async function getVault(config: StarlightObsidianConfig): Promise<Vault>
56
56
 
57
57
  return {
58
58
  options,
59
- path: vaultPath,
59
+ path: slashify(vaultPath),
60
60
  }
61
61
  }
62
62
 
package/libs/path.ts CHANGED
@@ -37,3 +37,18 @@ export function slugifyPath(filePath: string) {
37
37
  })
38
38
  .join('/')
39
39
  }
40
+
41
+ // https://github.com/sindresorhus/slash
42
+ export function slashify(filePath: string) {
43
+ const isExtendedLengthPath = filePath.startsWith('\\\\?\\')
44
+
45
+ if (isExtendedLengthPath) {
46
+ return filePath
47
+ }
48
+
49
+ return filePath.replaceAll('\\', '/')
50
+ }
51
+
52
+ export function osPath(filePath: string) {
53
+ return filePath.replaceAll('/', path.sep)
54
+ }
package/libs/remark.ts CHANGED
@@ -38,7 +38,7 @@ const commentReplacementRegex = /%%(?<comment>(?:(?!%%).)+)%%/gs
38
38
  const wikilinkReplacementRegex = /!?\[\[(?<url>(?:(?![[\]|]).)+)(?:\|(?<maybeText>(?:(?![[\]]).)+))?]]/g
39
39
  const tagReplacementRegex = /(?:^|\s)#(?<tag>[\w/-]+)/g
40
40
  const calloutRegex = /^\[!(?<type>\w+)][+-]? ?(?<title>.*)$/
41
- const imageSizeRegex = /^(?<altText>.*)\|(?:(?<widthOnly>\d+)|(?:(?<width>\d+)x(?<height>\d+)))$/
41
+ const imageSizeRegex = /^(?:(?<altText>.*)\|)?(?:(?<widthOnly>\d+)|(?:(?<width>\d+)x(?<height>\d+)))$/
42
42
 
43
43
  const asideDelimiter = ':::'
44
44
 
@@ -358,7 +358,7 @@ function handleBlockquotes(node: Blockquote, context: VisitorContext) {
358
358
  return SKIP
359
359
  }
360
360
 
361
- const [firstLine, ...otherLines] = firstGrandChild.value.split('\n')
361
+ const [firstLine, ...otherLines] = firstGrandChild.value.split(/\r?\n/)
362
362
 
363
363
  if (!firstLine) {
364
364
  return SKIP
@@ -485,7 +485,7 @@ function getRelativeFilePath(file: VFile, relativePath: string) {
485
485
  function getAssetPath(file: VFile, relativePath: string) {
486
486
  ensureTransformContext(file)
487
487
 
488
- return path.posix.join('../../..', path.relative(file.dirname, file.data.vault.path), 'assets', relativePath)
488
+ return path.posix.join('../../..', path.posix.relative(file.dirname, file.data.vault.path), 'assets', relativePath)
489
489
  }
490
490
 
491
491
  function getFilePathFromVaultFile(vaultFile: VaultFile, url: string) {
@@ -534,6 +534,7 @@ function handleImagesWithSize(node: Image, context: VisitorContext, type: 'asset
534
534
  return
535
535
  }
536
536
 
537
+ const imgAltText = altText ?? ''
537
538
  const imgWidth = widthOnly ?? width
538
539
  const imgHeight = height ?? 'auto'
539
540
  // Workaround Starlight `auto` height default style.
@@ -542,7 +543,7 @@ function handleImagesWithSize(node: Image, context: VisitorContext, type: 'asset
542
543
  if (type === 'external') {
543
544
  replaceNode(context, {
544
545
  type: 'html',
545
- value: `<img src="${node.url}" alt="${altText}" width="${imgWidth}" height="${imgHeight}"${imgStyle} />`,
546
+ value: `<img src="${node.url}" alt="${imgAltText}" width="${imgWidth}" height="${imgHeight}"${imgStyle} />`,
546
547
  })
547
548
  } else {
548
549
  const importId = generateAssetImportId()
@@ -556,7 +557,7 @@ function handleImagesWithSize(node: Image, context: VisitorContext, type: 'asset
556
557
  replaceNode(
557
558
  context,
558
559
  createMdxNode(
559
- `<Image src={${importId}} alt="${altText}" width="${imgWidth}" height="${imgHeight}"${imgStyle} />`,
560
+ `<Image src={${importId}} alt="${imgAltText}" width="${imgWidth}" height="${imgHeight}"${imgStyle} />`,
560
561
  ),
561
562
  )
562
563
  }
@@ -594,8 +595,9 @@ function getMarkdownFileNode(file: VFile, fileUrl: string): RootContent {
594
595
  file.data.vault.options.linkFormat === 'relative' ? getRelativeFilePath(file, fileUrl) : fileUrl,
595
596
  )
596
597
  const url = path.posix.join(path.posix.sep, `${filePath}${fileExt}`)
597
-
598
- const matchingFile = file.data.files.find((vaultFile) => vaultFile.path === url)
598
+ const matchingFile = file.data.files.find(
599
+ (vaultFile) => vaultFile.path === url || vaultFile.isEqualStem(filePath) || vaultFile.isEqualFileName(filePath),
600
+ )
599
601
 
600
602
  if (!matchingFile) {
601
603
  return { type: 'text', value: '' }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-obsidian",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "license": "MIT",
5
5
  "description": "Starlight plugin to publish Obsidian vaults.",
6
6
  "author": "HiDeoo <github@hideoo.dev> (https://hideoo.dev)",