Skip to content

Commit 0c5d4fa

Browse files
authored
fix: allow using # in class name (#116)
1 parent d917f1a commit 0c5d4fa

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

src/micromark-extension/factory-attributes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export default function createAttributes(
117117
return nok(code)
118118
}
119119

120-
if (code === Codes.hash || code === Codes.dot || code === Codes.closingCurlyBracket || markdownLineEndingOrSpace(code)) {
120+
if (code === Codes.dot || code === Codes.closingCurlyBracket || markdownLineEndingOrSpace(code)) {
121121
effects.exit(type + 'Value' as keyof TokenTypeMap)
122122
effects.exit(type)
123123
effects.exit(attributeType)

src/to-markdown.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type { Container } from './micromark-extension/types'
1414

1515
type NodeContainerComponent = Parents & { name: string, fmAttributes?: Record<string, any> }
1616

17-
const shortcut = /^[^\t\n\r "#'.<=>`}]+$/
17+
const shortcut = /^[^\t\n\r "'.<=>`}]+$/
1818
const baseFence = 2
1919

2020
// import { defaultHandlers } from 'mdast-util-to-markdown/lib/util/compile-pattern'

test/__snapshots__/attributes.test.ts.snap

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,62 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3+
exports[`Attributes > # in class 1`] = `
4+
{
5+
"children": [
6+
{
7+
"children": [
8+
{
9+
"attributes": {
10+
"class": "bg-[#E74249]",
11+
"id": "id",
12+
},
13+
"position": {
14+
"end": {
15+
"column": 7,
16+
"line": 1,
17+
"offset": 6,
18+
},
19+
"start": {
20+
"column": 1,
21+
"line": 1,
22+
"offset": 0,
23+
},
24+
},
25+
"type": "inlineCode",
26+
"value": "code",
27+
},
28+
],
29+
"position": {
30+
"end": {
31+
"column": 26,
32+
"line": 1,
33+
"offset": 25,
34+
},
35+
"start": {
36+
"column": 1,
37+
"line": 1,
38+
"offset": 0,
39+
},
40+
},
41+
"type": "paragraph",
42+
},
43+
],
44+
"position": {
45+
"end": {
46+
"column": 26,
47+
"line": 1,
48+
"offset": 25,
49+
},
50+
"start": {
51+
"column": 1,
52+
"line": 1,
53+
"offset": 0,
54+
},
55+
},
56+
"type": "root",
57+
}
58+
`;
59+
360
exports[`Attributes > boolean 1`] = `
461
{
562
"children": [

test/attributes.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ describe('Attributes', () => {
4949
'code': {
5050
markdown: '`code`{#id .class}',
5151
},
52+
'# in class': {
53+
markdown: '`code`{#id .bg-[#E74249]}',
54+
},
5255
'strong': {
5356
markdown: '**strong**{#id .class}',
5457
},

0 commit comments

Comments
 (0)