Skip to content

Commit

Permalink
fix: markdown plain parser
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Dec 11, 2023
1 parent 921883a commit b6114b4
Show file tree
Hide file tree
Showing 15 changed files with 270 additions and 2 deletions.
4 changes: 3 additions & 1 deletion fixtures/input/mdx.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ export const foo = {
]
}

export const hello = 'hello'

# Hello, world!


I'm an awesome paragraph.

<!-- I'm a comment -->
{ /* I'm a comment */ }

<Foo bg='red'>
<Bar >hi </Bar>
Expand Down
1 change: 1 addition & 0 deletions fixtures/output/all/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Jane Roe|JFK|314
+ with a [link] (/to/somewhere)
+ and [another one]


[another one]: http://example.com 'Example title'

Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Expand Down
42 changes: 42 additions & 0 deletions fixtures/output/all/mdx.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Baz } from './Fixture'

export const foo = {
hi: `Fudge ${Baz.displayName || 'Baz'}`,
authors: [
'fred',
'sally'
]
}

export const hello = 'hello'

# Hello, world!


I'm an awesome paragraph.

{ /* I'm a comment */ }

<Foo bg='red'>
<Bar >hi </Bar>
{ hello }
{ /* another comment */}
</Foo>

```
test codeblock
```

```js
module.exports = 'test'
```

```sh
npm i -g foo
```

| Test | Table |
| :--- | :---- |
| Col1 | Col2 |

export default ({children }) => < div>{ children}</div>
1 change: 1 addition & 0 deletions fixtures/output/js/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Jane Roe|JFK|314
+ with a [link] (/to/somewhere)
+ and [another one]


[another one]: http://example.com 'Example title'

Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Expand Down
42 changes: 42 additions & 0 deletions fixtures/output/js/mdx.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Baz } from './Fixture'

export const foo = {
hi: `Fudge ${Baz.displayName || 'Baz'}`,
authors: [
'fred',
'sally'
]
}

export const hello = 'hello'

# Hello, world!


I'm an awesome paragraph.

{ /* I'm a comment */ }

<Foo bg='red'>
<Bar >hi </Bar>
{ hello }
{ /* another comment */}
</Foo>

```
test codeblock
```

```js
module.exports = 'test'
```

```sh
npm i -g foo
```

| Test | Table |
| :--- | :---- |
| Col1 | Col2 |

export default ({children }) => < div>{ children}</div>
42 changes: 42 additions & 0 deletions fixtures/output/no-style/mdx.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Baz } from './Fixture'

export const foo = {
hi: `Fudge ${Baz.displayName || 'Baz'}`,
authors: [
'fred',
'sally'
]
}

export const hello = 'hello'

# Hello, world!


I'm an awesome paragraph.

{ /* I'm a comment */ }

<Foo bg='red'>
<Bar >hi </Bar>
{ hello }
{ /* another comment */}
</Foo>

```
test codeblock
```

```js
module.exports = 'test'
```

```sh
npm i -g foo
```

| Test | Table |
| :--- | :---- |
| Col1 | Col2 |

export default ({children }) => < div>{ children}</div>
1 change: 1 addition & 0 deletions fixtures/output/tab-double-quotes/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Jane Roe|JFK|314
+ with a [link] (/to/somewhere)
+ and [another one]


[another one]: http://example.com 'Example title'

Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Expand Down
42 changes: 42 additions & 0 deletions fixtures/output/tab-double-quotes/mdx.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Baz } from './Fixture'

export const foo = {
hi: `Fudge ${Baz.displayName || 'Baz'}`,
authors: [
'fred',
'sally'
]
}

export const hello = 'hello'

# Hello, world!


I'm an awesome paragraph.

{ /* I'm a comment */ }

<Foo bg='red'>
<Bar >hi </Bar>
{ hello }
{ /* another comment */}
</Foo>

```
test codeblock
```

```js
module.exports = "test"
```

```sh
npm i -g foo
```

| Test | Table |
| :--- | :---- |
| Col1 | Col2 |

export default ({children }) => < div>{ children}</div>
1 change: 1 addition & 0 deletions fixtures/output/ts-override/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Jane Roe|JFK|314
+ with a [link] (/to/somewhere)
+ and [another one]


[another one]: http://example.com 'Example title'

Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Expand Down
42 changes: 42 additions & 0 deletions fixtures/output/ts-override/mdx.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Baz } from './Fixture'

export const foo = {
hi: `Fudge ${Baz.displayName || 'Baz'}`,
authors: [
'fred',
'sally'
]
}

export const hello = 'hello'

# Hello, world!


I'm an awesome paragraph.

{ /* I'm a comment */ }

<Foo bg='red'>
<Bar >hi </Bar>
{ hello }
{ /* another comment */}
</Foo>

```
test codeblock
```

```js
module.exports = 'test'
```

```sh
npm i -g foo
```

| Test | Table |
| :--- | :---- |
| Col1 | Col2 |

export default ({children }) => < div>{ children}</div>
41 changes: 41 additions & 0 deletions fixtures/output/with-formatters/mdx.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Baz } from './Fixture'

export const foo = {
hi: `Fudge ${Baz.displayName || 'Baz'}`,
authors: [
'fred',
'sally'
]
}

export const hello = 'hello'

# Hello, world!

I'm an awesome paragraph.

{/* I'm a comment */}

<Foo bg='red'>
<Bar >hi </Bar>
{ hello }
{ /* another comment */}
</Foo>

```
test codeblock
```

```js
module.exports = 'test'
```

```sh
npm i -g foo
```

| Test | Table |
| :--- | :---- |
| Col1 | Col2 |

export default ({children }) => < div>{ children}</div>
7 changes: 7 additions & 0 deletions src/configs/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { StylisticConfigDefaults } from './stylistic'
export async function formatters(
options: OptionsFormatters | true = {},
stylistic: StylisticConfig = {},
markdownParserEnabled = true,
): Promise<FlatConfigItem[]> {
await ensurePackages([
'eslint-plugin-format',
Expand Down Expand Up @@ -143,6 +144,9 @@ export async function formatters(

configs.push({
files: [GLOB_MARKDOWN],
languageOptions: markdownParserEnabled
? {}
: { parser: parserPlain },
name: 'antfu:formatter:markdown',
rules: {
[`format/${formatter}`]: [
Expand All @@ -165,6 +169,9 @@ export async function formatters(
if (options.mdx) {
configs.push({
files: [GLOB_MDX],
languageOptions: markdownParserEnabled
? {}
: { parser: parserPlain },
name: 'antfu:formatter:mdx',
rules: {
'format/prettier': [
Expand Down
1 change: 0 additions & 1 deletion src/configs/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export async function markdown(
rules: {
'mdx/remark': 'warn',
'no-unused-expressions': 'error',
'style/indent': 'off',
},
},
{
Expand Down
4 changes: 4 additions & 0 deletions src/configs/stylistic.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { GLOB_MARKDOWN_OR_MDX } from '../globs'
import { interopDefault } from '../utils'
import type { FlatConfigItem, StylisticConfig } from '../types'
import { pluginAntfu } from '../plugins'
Expand Down Expand Up @@ -33,6 +34,9 @@ export async function stylistic(options: StylisticConfig = {}): Promise<FlatConf

return [
{
ignores: [
GLOB_MARKDOWN_OR_MDX,
],
name: 'antfu:stylistic',
plugins: {
antfu: pluginAntfu,
Expand Down
1 change: 1 addition & 0 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export async function antfu(
configs.push(formatters(
options.formatters,
typeof stylisticOptions === 'boolean' ? {} : stylisticOptions,
options.markdown !== false,
))
}

Expand Down

0 comments on commit b6114b4

Please sign in to comment.