Skip to content

Commit b6114b4

Browse files
committed
fix: markdown plain parser
1 parent 921883a commit b6114b4

File tree

15 files changed

+270
-2
lines changed

15 files changed

+270
-2
lines changed

fixtures/input/mdx.mdx

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ export const foo = {
99
]
1010
}
1111

12+
export const hello = 'hello'
13+
1214
# Hello, world!
1315

1416

1517
I'm an awesome paragraph.
1618

17-
<!-- I'm a comment -->
19+
{ /* I'm a comment */ }
1820

1921
<Foo bg='red'>
2022
<Bar >hi </Bar>

fixtures/output/all/markdown.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Jane Roe|JFK|314
2727
+ with a [link] (/to/somewhere)
2828
+ and [another one]
2929

30+
3031
[another one]: http://example.com 'Example title'
3132

3233
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

fixtures/output/all/mdx.mdx

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Baz } from './Fixture'
2+
3+
export const foo = {
4+
hi: `Fudge ${Baz.displayName || 'Baz'}`,
5+
authors: [
6+
'fred',
7+
'sally'
8+
]
9+
}
10+
11+
export const hello = 'hello'
12+
13+
# Hello, world!
14+
15+
16+
I'm an awesome paragraph.
17+
18+
{ /* I'm a comment */ }
19+
20+
<Foo bg='red'>
21+
<Bar >hi </Bar>
22+
{ hello }
23+
{ /* another comment */}
24+
</Foo>
25+
26+
```
27+
test codeblock
28+
```
29+
30+
```js
31+
module.exports = 'test'
32+
```
33+
34+
```sh
35+
npm i -g foo
36+
```
37+
38+
| Test | Table |
39+
| :--- | :---- |
40+
| Col1 | Col2 |
41+
42+
export default ({children }) => < div>{ children}</div>

fixtures/output/js/markdown.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Jane Roe|JFK|314
2727
+ with a [link] (/to/somewhere)
2828
+ and [another one]
2929

30+
3031
[another one]: http://example.com 'Example title'
3132

3233
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

fixtures/output/js/mdx.mdx

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Baz } from './Fixture'
2+
3+
export const foo = {
4+
hi: `Fudge ${Baz.displayName || 'Baz'}`,
5+
authors: [
6+
'fred',
7+
'sally'
8+
]
9+
}
10+
11+
export const hello = 'hello'
12+
13+
# Hello, world!
14+
15+
16+
I'm an awesome paragraph.
17+
18+
{ /* I'm a comment */ }
19+
20+
<Foo bg='red'>
21+
<Bar >hi </Bar>
22+
{ hello }
23+
{ /* another comment */}
24+
</Foo>
25+
26+
```
27+
test codeblock
28+
```
29+
30+
```js
31+
module.exports = 'test'
32+
```
33+
34+
```sh
35+
npm i -g foo
36+
```
37+
38+
| Test | Table |
39+
| :--- | :---- |
40+
| Col1 | Col2 |
41+
42+
export default ({children }) => < div>{ children}</div>

fixtures/output/no-style/mdx.mdx

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Baz } from './Fixture'
2+
3+
export const foo = {
4+
hi: `Fudge ${Baz.displayName || 'Baz'}`,
5+
authors: [
6+
'fred',
7+
'sally'
8+
]
9+
}
10+
11+
export const hello = 'hello'
12+
13+
# Hello, world!
14+
15+
16+
I'm an awesome paragraph.
17+
18+
{ /* I'm a comment */ }
19+
20+
<Foo bg='red'>
21+
<Bar >hi </Bar>
22+
{ hello }
23+
{ /* another comment */}
24+
</Foo>
25+
26+
```
27+
test codeblock
28+
```
29+
30+
```js
31+
module.exports = 'test'
32+
```
33+
34+
```sh
35+
npm i -g foo
36+
```
37+
38+
| Test | Table |
39+
| :--- | :---- |
40+
| Col1 | Col2 |
41+
42+
export default ({children }) => < div>{ children}</div>

fixtures/output/tab-double-quotes/markdown.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Jane Roe|JFK|314
2727
+ with a [link] (/to/somewhere)
2828
+ and [another one]
2929

30+
3031
[another one]: http://example.com 'Example title'
3132

3233
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Baz } from './Fixture'
2+
3+
export const foo = {
4+
hi: `Fudge ${Baz.displayName || 'Baz'}`,
5+
authors: [
6+
'fred',
7+
'sally'
8+
]
9+
}
10+
11+
export const hello = 'hello'
12+
13+
# Hello, world!
14+
15+
16+
I'm an awesome paragraph.
17+
18+
{ /* I'm a comment */ }
19+
20+
<Foo bg='red'>
21+
<Bar >hi </Bar>
22+
{ hello }
23+
{ /* another comment */}
24+
</Foo>
25+
26+
```
27+
test codeblock
28+
```
29+
30+
```js
31+
module.exports = "test"
32+
```
33+
34+
```sh
35+
npm i -g foo
36+
```
37+
38+
| Test | Table |
39+
| :--- | :---- |
40+
| Col1 | Col2 |
41+
42+
export default ({children }) => < div>{ children}</div>

fixtures/output/ts-override/markdown.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Jane Roe|JFK|314
2727
+ with a [link] (/to/somewhere)
2828
+ and [another one]
2929

30+
3031
[another one]: http://example.com 'Example title'
3132

3233
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

fixtures/output/ts-override/mdx.mdx

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Baz } from './Fixture'
2+
3+
export const foo = {
4+
hi: `Fudge ${Baz.displayName || 'Baz'}`,
5+
authors: [
6+
'fred',
7+
'sally'
8+
]
9+
}
10+
11+
export const hello = 'hello'
12+
13+
# Hello, world!
14+
15+
16+
I'm an awesome paragraph.
17+
18+
{ /* I'm a comment */ }
19+
20+
<Foo bg='red'>
21+
<Bar >hi </Bar>
22+
{ hello }
23+
{ /* another comment */}
24+
</Foo>
25+
26+
```
27+
test codeblock
28+
```
29+
30+
```js
31+
module.exports = 'test'
32+
```
33+
34+
```sh
35+
npm i -g foo
36+
```
37+
38+
| Test | Table |
39+
| :--- | :---- |
40+
| Col1 | Col2 |
41+
42+
export default ({children }) => < div>{ children}</div>
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Baz } from './Fixture'
2+
3+
export const foo = {
4+
hi: `Fudge ${Baz.displayName || 'Baz'}`,
5+
authors: [
6+
'fred',
7+
'sally'
8+
]
9+
}
10+
11+
export const hello = 'hello'
12+
13+
# Hello, world!
14+
15+
I'm an awesome paragraph.
16+
17+
{/* I'm a comment */}
18+
19+
<Foo bg='red'>
20+
<Bar >hi </Bar>
21+
{ hello }
22+
{ /* another comment */}
23+
</Foo>
24+
25+
```
26+
test codeblock
27+
```
28+
29+
```js
30+
module.exports = 'test'
31+
```
32+
33+
```sh
34+
npm i -g foo
35+
```
36+
37+
| Test | Table |
38+
| :--- | :---- |
39+
| Col1 | Col2 |
40+
41+
export default ({children }) => < div>{ children}</div>

src/configs/formatters.ts

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { StylisticConfigDefaults } from './stylistic'
88
export async function formatters(
99
options: OptionsFormatters | true = {},
1010
stylistic: StylisticConfig = {},
11+
markdownParserEnabled = true,
1112
): Promise<FlatConfigItem[]> {
1213
await ensurePackages([
1314
'eslint-plugin-format',
@@ -143,6 +144,9 @@ export async function formatters(
143144

144145
configs.push({
145146
files: [GLOB_MARKDOWN],
147+
languageOptions: markdownParserEnabled
148+
? {}
149+
: { parser: parserPlain },
146150
name: 'antfu:formatter:markdown',
147151
rules: {
148152
[`format/${formatter}`]: [
@@ -165,6 +169,9 @@ export async function formatters(
165169
if (options.mdx) {
166170
configs.push({
167171
files: [GLOB_MDX],
172+
languageOptions: markdownParserEnabled
173+
? {}
174+
: { parser: parserPlain },
168175
name: 'antfu:formatter:mdx',
169176
rules: {
170177
'format/prettier': [

src/configs/markdown.ts

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export async function markdown(
3333
rules: {
3434
'mdx/remark': 'warn',
3535
'no-unused-expressions': 'error',
36-
'style/indent': 'off',
3736
},
3837
},
3938
{

src/configs/stylistic.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { GLOB_MARKDOWN_OR_MDX } from '../globs'
12
import { interopDefault } from '../utils'
23
import type { FlatConfigItem, StylisticConfig } from '../types'
34
import { pluginAntfu } from '../plugins'
@@ -33,6 +34,9 @@ export async function stylistic(options: StylisticConfig = {}): Promise<FlatConf
3334

3435
return [
3536
{
37+
ignores: [
38+
GLOB_MARKDOWN_OR_MDX,
39+
],
3640
name: 'antfu:stylistic',
3741
plugins: {
3842
antfu: pluginAntfu,

src/factory.ts

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export async function antfu(
191191
configs.push(formatters(
192192
options.formatters,
193193
typeof stylisticOptions === 'boolean' ? {} : stylisticOptions,
194+
options.markdown !== false,
194195
))
195196
}
196197

0 commit comments

Comments
 (0)