-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: port fixes to parseHeader utils from vuepress (#172)
- Loading branch information
Showing
4 changed files
with
130 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { deeplyParseHeader } from 'node/utils/parseHeader' | ||
|
||
test('deeplyParseHeader', () => { | ||
const asserts: Record<string, string> = { | ||
// Remove tail html | ||
'# `H1` <Comp></Comp>': '# H1', | ||
'# *H1* <Comp/>': '# H1', | ||
|
||
// Reserve code-wrapped tail html | ||
'# `H1` `<Comp></Comp>`': '# H1 <Comp></Comp>', | ||
'# *H1* `<Comp/>`': '# H1 <Comp/>', | ||
|
||
// Remove leading html | ||
'# <Comp></Comp> `H1`': '# H1', | ||
'# <Comp/> *H1*': '# H1', | ||
|
||
// Reserve code-wrapped leading html | ||
'# `<Comp></Comp>` `H1`': '# <Comp></Comp> H1', | ||
'# `<Comp/>` *H1*': '# <Comp/> H1', | ||
|
||
// Remove middle html | ||
'# `H1` <Comp></Comp> `H2`': '# H1 H2', | ||
'# `H1` <Comp/> `H2`': '# H1 H2', | ||
|
||
// Reserve middle html | ||
'# `H1` `<Comp></Comp>` `H2`': '# H1 <Comp></Comp> H2', | ||
'# `H1` `<Comp/>` `H2`': '# H1 <Comp/> H2' | ||
} | ||
|
||
Object.keys(asserts).forEach((input) => { | ||
expect(deeplyParseHeader(input)).toBe(asserts[input]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { parseHeader } from 'node/utils/parseHeader' | ||
|
||
describe('parseHeader', () => { | ||
test('should unescape html', () => { | ||
const input = `<div :id="'app'">` | ||
expect(parseHeader(input)).toBe(`<div :id="'app'">`) | ||
}) | ||
|
||
test('should remove markdown tokens correctly', () => { | ||
const asserts: Record<string, string> = { | ||
// vuepress #238 | ||
'[vue](vuejs.org)': 'vue', | ||
'`vue`': 'vue', | ||
'*vue*': 'vue', | ||
'**vue**': 'vue', | ||
'***vue***': 'vue', | ||
_vue_: 'vue', | ||
'\\_vue\\_': '_vue_', | ||
'\\*vue\\*': '*vue*', | ||
'\\!vue\\!': '!vue!', | ||
|
||
// vuepress #2688 | ||
'[vue](vuejs.org) / [vue](vuejs.org)': 'vue / vue', | ||
'[\\<ins>](vuejs.org)': '<ins>', | ||
|
||
// vuepress #564 For multiple markdown tokens | ||
'`a` and `b`': 'a and b', | ||
'***bold and italic***': 'bold and italic', | ||
'**bold** and *italic*': 'bold and italic', | ||
|
||
// escaping \$ | ||
'\\$vue': '$vue' | ||
} | ||
Object.keys(asserts).forEach((input) => { | ||
expect(parseHeader(input)).toBe(asserts[input]) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { removeNonCodeWrappedHTML } from 'node/utils/parseHeader' | ||
|
||
test('removeNonCodeWrappedHTML', () => { | ||
const asserts: Record<string, string> = { | ||
// Remove tail html | ||
'# H1 <Comp></Comp>': '# H1 ', | ||
'# H1<Comp></Comp>': '# H1', | ||
'# H1 <Comp a="b"></Comp>': '# H1 ', | ||
'# H1<Comp a="b"></Comp>': '# H1', | ||
'# H1 <Comp/>': '# H1 ', | ||
'# H1<Comp/>': '# H1', | ||
'# H1 <Comp a="b"/>': '# H1 ', | ||
'# H1<Comp a="b"/>': '# H1', | ||
|
||
// Reserve code-wrapped tail html | ||
'# H1 `<Comp></Comp>`': '# H1 `<Comp></Comp>`', | ||
'# H1 `<Comp a="b"></Comp>`': '# H1 `<Comp a="b"></Comp>`', | ||
'# H1 `<Comp/>`': '# H1 `<Comp/>`', | ||
'# H1 `<Comp a="b"/>`': '# H1 `<Comp a="b"/>`', | ||
|
||
// Remove leading html | ||
'# <Comp></Comp> H1': '# H1', | ||
'# <Comp></Comp>H1': '# H1', | ||
'# <Comp a="b"></Comp> H1': '# H1', | ||
'# <Comp a="b"></Comp>H1': '# H1', | ||
'# <Comp/> H1': '# H1', | ||
'# <Comp/>H1': '# H1', | ||
'# <Comp a="b"/> H1': '# H1', | ||
'# <Comp a="b"/>H1': '# H1', | ||
|
||
// Reserve code-wrapped leading html | ||
'# `<Comp></Comp>` H1': '# `<Comp></Comp>` H1', | ||
'# `<Comp a="b"></Comp>` H1': '# `<Comp a="b"></Comp>` H1', | ||
'# `<Comp/>` H1': '# `<Comp/>` H1', | ||
'# `<Comp a="b"/>` H1': '# `<Comp a="b"/>` H1', | ||
|
||
// Remove middle html | ||
'# H1 <Comp></Comp> H2': '# H1 H2', | ||
'# H1 <Comp a="b"></Comp> H2': '# H1 H2', | ||
'# H1 <Comp/> H2': '# H1 H2', | ||
'# H1 <Comp a="b"/> H2': '# H1 H2', | ||
|
||
// Reserve code-wrapped middle html | ||
'# H1 `<Comp></Comp>` H2': '# H1 `<Comp></Comp>` H2', | ||
'# H1 `<Comp a="b"></Comp>` H2': '# H1 `<Comp a="b"></Comp>` H2', | ||
'# H1 `<Comp/>` H2': '# H1 `<Comp/>` H2', | ||
'# H1 `<Comp a="b"/>` H2': '# H1 `<Comp a="b"/>` H2', | ||
|
||
// vuepress #2688 | ||
'# \\<ins>': '# \\<ins>' | ||
} | ||
|
||
Object.keys(asserts).forEach((input) => { | ||
expect(removeNonCodeWrappedHTML(input)).toBe(asserts[input]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dd312ce
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: