-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a27d0ab
commit 34aa884
Showing
8 changed files
with
271 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testMatch: ['**/tests/**/*.ts?(x)', '**/?(*.)+(spec|test).ts?(x)'], | ||
testMatch: ['**/?(*.)+(spec|test).ts?(x)'], | ||
testPathIgnorePatterns: ['lib'], | ||
}; |
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
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,47 @@ | ||
import { stripIndent } from 'common-tags'; | ||
import { buildProcessorTestingCode } from '../utils'; | ||
|
||
it( | ||
'allows markdown context in new paragraph', | ||
buildProcessorTestingCode( | ||
stripIndent` | ||
<div> | ||
**Markdown inside HTML** | ||
</div> | ||
`, | ||
stripIndent` | ||
root[3] | ||
├─0 html "<div>" | ||
├─1 paragraph[1] | ||
│ └─0 strong[1] | ||
│ └─0 text "Markdown inside HTML" | ||
└─2 html "</div>" | ||
`, | ||
stripIndent` | ||
<div> | ||
<p><strong>Markdown inside HTML</strong></p> | ||
</div> | ||
`, | ||
), | ||
); | ||
|
||
it( | ||
'same paragraph', | ||
buildProcessorTestingCode( | ||
stripIndent` | ||
<div> | ||
**Markdown inside HTML** | ||
</div> | ||
`, | ||
stripIndent` | ||
root[1] | ||
└─0 html "<div>\\n**Markdown inside HTML**\\n</div>" | ||
`, | ||
stripIndent` | ||
<div> | ||
**Markdown inside HTML** | ||
</div> | ||
`, | ||
), | ||
); |
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,87 @@ | ||
import { stripIndent } from 'common-tags'; | ||
import { buildProcessorTestingCode } from '../utils'; | ||
|
||
it( | ||
'simple inlineMath', | ||
buildProcessorTestingCode( | ||
`$x$`, | ||
stripIndent` | ||
root[1] | ||
└─0 paragraph[1] | ||
└─0 inlineMath "x" | ||
data: {"hName":"span","hProperties":{"className":["math","math-inline"]},"hChildren":[{"type":"text","value":"x"}]} | ||
`, | ||
`<p><span class="math math-inline"><span class="katex"><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathdefault">x</span></span></span></span></span></p>`, | ||
), | ||
); | ||
|
||
it( | ||
"isn't greedy", | ||
buildProcessorTestingCode( | ||
`$x$y$`, | ||
stripIndent` | ||
root[1] | ||
└─0 paragraph[2] | ||
├─0 inlineMath "x" | ||
│ data: {"hName":"span","hProperties":{"className":["math","math-inline"]},"hChildren":[{"type":"text","value":"x"}]} | ||
└─1 text "y$" | ||
`, | ||
`<p><span class="math math-inline"><span class="katex"><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathdefault">x</span></span></span></span></span>y$</p>`, | ||
), | ||
); | ||
|
||
it( | ||
'double dollar', | ||
buildProcessorTestingCode( | ||
`$$x$$`, | ||
stripIndent` | ||
root[1] | ||
└─0 paragraph[1] | ||
└─0 inlineMath "x" | ||
data: {"hName":"span","hProperties":{"className":["math","math-inline"]},"hChildren":[{"type":"text","value":"x"}]} | ||
`, | ||
`<p><span class="math math-inline"><span class="katex"><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathdefault">x</span></span></span></span></span></p>`, | ||
), | ||
); | ||
|
||
it( | ||
'empty math', | ||
buildProcessorTestingCode( | ||
`$$`, | ||
stripIndent` | ||
root[1] | ||
└─0 paragraph[1] | ||
└─0 text "$$" | ||
`, | ||
`<p>$$</p>`, | ||
), | ||
); | ||
|
||
it( | ||
'nested math', | ||
buildProcessorTestingCode( | ||
`$$a$b$$c$`, | ||
stripIndent` | ||
root[1] | ||
└─0 paragraph[2] | ||
├─0 inlineMath "a$b" | ||
│ data: {"hName":"span","hProperties":{"className":["math","math-inline"]},"hChildren":[{"type":"text","value":"a$b"}]} | ||
└─1 text "c$" | ||
`, | ||
`<p><span class="math math-inline"><span class="katex-error" title="ParseError: KaTeX parse error: Can't use function '$' in math mode at position 2: a$̲b" style="color:#cc0000">a$b</span></span>c$</p>`, | ||
), | ||
); | ||
|
||
it( | ||
'math with newline', | ||
buildProcessorTestingCode( | ||
`$x\ny$`, | ||
stripIndent` | ||
root[1] | ||
└─0 paragraph[1] | ||
└─0 inlineMath "x\\ny" | ||
data: {"hName":"span","hProperties":{"className":["math","math-inline"]},"hChildren":[{"type":"text","value":"x\\ny"}]} | ||
`, | ||
`<p><span class="math math-inline"><span class="katex"><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.19444em;"></span><span class="mord mathdefault">x</span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span></span></span></span></span></p>`, | ||
), | ||
); |
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,78 @@ | ||
import { stripIndent } from 'common-tags'; | ||
import { buildProcessorTestingCode } from '../utils'; | ||
|
||
it( | ||
'simple ruby', | ||
buildProcessorTestingCode( | ||
`{a|b}`, | ||
stripIndent` | ||
root[1] | ||
└─0 paragraph[1] | ||
└─0 ruby[1] | ||
│ data: {"hName":"ruby","rubyText":"b"} | ||
└─0 text "a" | ||
`, | ||
`<p><ruby>a<rt>b</rt></ruby></p>`, | ||
), | ||
); | ||
|
||
it( | ||
'enables escape in ruby body', | ||
buildProcessorTestingCode( | ||
`{a\\|b|c}`, | ||
stripIndent` | ||
root[1] | ||
└─0 paragraph[1] | ||
└─0 ruby[1] | ||
│ data: {"hName":"ruby","rubyText":"b|c"} | ||
└─0 text "a\\\\" | ||
`, | ||
`<p><ruby>a\\<rt>b|c</rt></ruby></p>`, | ||
), | ||
); | ||
|
||
it( | ||
'disables any inline rule in <rt>', | ||
buildProcessorTestingCode( | ||
`{a|*b*}`, | ||
stripIndent` | ||
root[1] | ||
└─0 paragraph[1] | ||
└─0 ruby[1] | ||
│ data: {"hName":"ruby","rubyText":"*b*"} | ||
└─0 text "a" | ||
`, | ||
`<p><ruby>a<rt>*b*</rt></ruby></p>`, | ||
), | ||
); | ||
|
||
it( | ||
'nested ruby', | ||
buildProcessorTestingCode( | ||
`{{a|b}|c}`, | ||
stripIndent` | ||
root[1] | ||
└─0 paragraph[2] | ||
├─0 ruby[1] | ||
│ │ data: {"hName":"ruby","rubyText":"b"} | ||
│ └─0 text "{a" | ||
└─1 text "|c}" | ||
`, | ||
`<p><ruby>{a<rt>b</rt></ruby>|c}</p>`, | ||
), | ||
); | ||
|
||
it( | ||
'ruby with newline', | ||
buildProcessorTestingCode( | ||
`{a\nb|c}`, | ||
stripIndent` | ||
root[1] | ||
└─0 paragraph[3] | ||
├─0 text "{a" | ||
├─1 break | ||
└─2 text "b|c}" | ||
`, | ||
`<p>{a<br>\nb|c}</p>`, | ||
), | ||
); |
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,34 @@ | ||
import { stripIndent } from 'common-tags'; | ||
import { buildProcessorTestingCode } from '../utils'; | ||
|
||
it( | ||
'simple figure output', | ||
buildProcessorTestingCode( | ||
`![caption](./img.png)`, | ||
stripIndent` | ||
root[1] | ||
└─0 paragraph[1] | ||
└─0 image | ||
title: null | ||
url: "./img.png" | ||
alt: "caption" | ||
`, | ||
`<p><figure><img src="./img.png" alt="caption"><figcaption>caption</figcaption></figure></p>`, | ||
), | ||
); | ||
|
||
it( | ||
'image without caption', | ||
buildProcessorTestingCode( | ||
`![](./img.png)`, | ||
stripIndent` | ||
root[1] | ||
└─0 paragraph[1] | ||
└─0 image | ||
title: null | ||
url: "./img.png" | ||
alt: null | ||
`, | ||
`<p><img src="./img.png"></p>`, | ||
), | ||
); |
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,12 @@ | ||
import unistInspect from 'unist-util-inspect'; | ||
import { VFM } from '../src'; | ||
|
||
export const buildProcessorTestingCode = ( | ||
input: string, | ||
expectedMdast: string, | ||
expectedHtml: string, | ||
) => (): any => { | ||
const vfm = VFM({ partial: true }).freeze(); | ||
expect(unistInspect.noColor(vfm.parse(input))).toBe(expectedMdast.trim()); | ||
expect(String(vfm.processSync(input))).toBe(expectedHtml); | ||
}; |
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