Skip to content

Commit f987a5f

Browse files
authored
fix: enable yaml frontmatter in bundled configs (#29)
- add `languageOptions.frontmatter = 'yaml'` to the recommended and all flat configs - align shared type imports and rename `WhiteSpaceReturn` to follow local naming conventions - broaden Han character detection and simplify node text extraction helpers
1 parent eeef78c commit f987a5f

6 files changed

Lines changed: 13 additions & 12 deletions

File tree

src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export const configs: PluginConfigMap = {
3232
'md-style': plugin,
3333
},
3434
language: 'md-style/gfm',
35+
languageOptions: {
36+
frontmatter: 'yaml',
37+
},
3538
rules: recommendedRules,
3639
},
3740
all: {
@@ -41,6 +44,9 @@ export const configs: PluginConfigMap = {
4144
'md-style': plugin,
4245
},
4346
language: 'md-style/gfm',
47+
languageOptions: {
48+
frontmatter: 'yaml',
49+
},
4450
rules: allRules,
4551
},
4652
}

src/types/inline-element.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Emphasis, Image, InlineCode, Link, Strong } from 'mdast'
22
import type { ValueOf } from '@/types/index'
3-
import type { INLINE_SPACE_MESSAGE_IDS } from '@/types/inline-element'
3+
import type { INLINE_SPACE_MESSAGE_IDS } from '@/utils/inline-element'
44

55
/**
66
* The Markdown inline element node types selected by space-around-inline-element.

src/types/space.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface SpaceContext {
1414
next?: AdjacentTextContext
1515
}
1616

17-
export interface whiteSpaceReturn {
17+
export interface WhiteSpaceReturn {
1818
count: number
1919
start: number
2020
end: number

src/utils/anchor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function isStrictAnchor(str: string): boolean {
4949
* Check whether the string contains CJK Han characters.
5050
*/
5151
export function hasChinese(str: string): boolean {
52-
return /[\u4E00-\u9FA5]/.test(str)
52+
return /\p{Script=Han}/u.test(str)
5353
}
5454

5555
/**

src/utils/ast.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,8 @@ export function getNodeValue(
9898
return
9999
if ('value' in node)
100100
return node.value
101-
if (hasChildren(node)) {
102-
const value = node.children
103-
.map(getNodeValue)
104-
.join('')
105-
106-
return value || undefined
107-
}
101+
if (hasChildren(node))
102+
return node.children.map(getNodeValue).join('')
108103
}
109104

110105
/**

src/utils/space.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { PhrasingContent } from 'mdast'
22
import type { NodeContextReturnType } from '@/types/ast'
33
import type { PositionOptions } from '@/types/inline-element'
4-
import type { SpaceContext, whiteSpaceReturn } from '@/types/space'
4+
import type { SpaceContext, WhiteSpaceReturn } from '@/types/space'
55
import { getAdjacentChar, getNodeValue } from './ast'
66
import { hasPunctuation, isFullwidthPunctuation } from './punctuation'
77

@@ -13,7 +13,7 @@ import { hasPunctuation, isFullwidthPunctuation } from './punctuation'
1313
export function getWhiteSpace(
1414
str: string | undefined,
1515
position: PositionOptions = 'head',
16-
): whiteSpaceReturn {
16+
): WhiteSpaceReturn {
1717
const defaultVal = { count: 0, start: 0, end: 0 }
1818
if (!str || str.length === 0)
1919
return defaultVal

0 commit comments

Comments
 (0)