-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: better inline image handling * chore: break out the typings a bit more
- Loading branch information
Showing
17 changed files
with
1,533 additions
and
1,290 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
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
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
18 changes: 18 additions & 0 deletions
18
src/plugins/run/__tests__/__fixtures__/images/basic-inline.md
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,18 @@ | ||
Image in a paragraph: ![should have inline][ecologi_image]. | ||
|
||
![should NOT have inline][ecologi_image] | ||
|
||
[![should have inline][ecologi_image]][ecologi] | ||
|
||
<!-- type: tab --> | ||
|
||
Tab paragraph one. | ||
|
||
![should NOT have inline][ecologi_image] | ||
|
||
Tab paragraph two. | ||
|
||
<!-- type: tab-end --> | ||
|
||
[ecologi]: https://ecologi.com/stoplightinc | ||
[ecologi_image]: https://img.shields.io/badge/Buy%20us%20a%20tree-%F0%9F%8C%B3-lightgreen |
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,10 @@ | ||
Image in a paragraph: ![should NOT unwrap][ecologi_image]. | ||
|
||
![should unwrap][ecologi_image] | ||
|
||
[![should unwrap][ecologi_image]][ecologi] | ||
|
||
![should NOT unwrap][ecologi_image] [![should NOT unwrap][ecologi_image]][ecologi] | ||
|
||
[ecologi]: https://ecologi.com/stoplightinc | ||
[ecologi_image]: https://img.shields.io/badge/Buy%20us%20a%20tree-%F0%9F%8C%B3-lightgreen |
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,64 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import html from 'remark-html'; | ||
import remarkParse from 'remark-parse'; | ||
import unified from 'unified'; | ||
|
||
import { remarkParsePreset } from '../../../parse'; | ||
|
||
const prettier = require('prettier'); | ||
|
||
const prettyParse = (input: string) => { | ||
return prettier.format( | ||
`<>${unified() | ||
.use(remarkParse) | ||
.use(remarkParsePreset) | ||
.use(html, { closeSelfClosing: true }) | ||
.processSync(input)}</>`, | ||
{ | ||
parser: 'babel', | ||
}, | ||
); | ||
}; | ||
|
||
describe('inline-images plugin', () => { | ||
it('should support meta props like title and lineNumbers', () => { | ||
const input = fs.readFileSync(path.join(__dirname, '__fixtures__/images/basic-inline.md'), 'utf8'); | ||
|
||
expect(prettyParse(input)).toMatchInlineSnapshot(` | ||
"<> | ||
<p> | ||
Image in a paragraph:{\\" \\"} | ||
<img | ||
src=\\"https://img.shields.io/badge/Buy%20us%20a%20tree-%F0%9F%8C%B3-lightgreen\\" | ||
alt=\\"should have inline\\" | ||
inline=\\"true\\" | ||
/> | ||
. | ||
</p> | ||
<img | ||
src=\\"https://img.shields.io/badge/Buy%20us%20a%20tree-%F0%9F%8C%B3-lightgreen\\" | ||
alt=\\"should NOT have inline\\" | ||
/> | ||
<a href=\\"https://ecologi.com/stoplightinc\\"> | ||
<img | ||
src=\\"https://img.shields.io/badge/Buy%20us%20a%20tree-%F0%9F%8C%B3-lightgreen\\" | ||
alt=\\"should have inline\\" | ||
inline=\\"true\\" | ||
/> | ||
</a> | ||
<tabs> | ||
<tab type=\\"tab\\"> | ||
<p>Tab paragraph one.</p> | ||
<img | ||
src=\\"https://img.shields.io/badge/Buy%20us%20a%20tree-%F0%9F%8C%B3-lightgreen\\" | ||
alt=\\"should NOT have inline\\" | ||
/> | ||
<p>Tab paragraph two.</p> | ||
</tab> | ||
</tabs> | ||
</>; | ||
" | ||
`); | ||
}); | ||
}); |
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,68 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import html from 'remark-html'; | ||
import remarkParse from 'remark-parse'; | ||
import unified from 'unified'; | ||
|
||
import { remarkParsePreset } from '../../../parse'; | ||
|
||
const prettier = require('prettier'); | ||
|
||
const prettyParse = (input: string) => { | ||
return prettier.format( | ||
`<>${unified() | ||
.use(remarkParse) | ||
.use(remarkParsePreset) | ||
.use(html, { closeSelfClosing: true }) | ||
.processSync(input)}</>`, | ||
{ | ||
parser: 'babel', | ||
}, | ||
); | ||
}; | ||
|
||
describe('unwrap-images plugin', () => { | ||
it('should support meta props like title and lineNumbers', () => { | ||
const input = fs.readFileSync(path.join(__dirname, '__fixtures__/images/unwrap.md'), 'utf8'); | ||
|
||
expect(prettyParse(input)).toMatchInlineSnapshot(` | ||
"<> | ||
<p> | ||
Image in a paragraph:{\\" \\"} | ||
<img | ||
src=\\"https://img.shields.io/badge/Buy%20us%20a%20tree-%F0%9F%8C%B3-lightgreen\\" | ||
alt=\\"should NOT unwrap\\" | ||
inline=\\"true\\" | ||
/> | ||
. | ||
</p> | ||
<img | ||
src=\\"https://img.shields.io/badge/Buy%20us%20a%20tree-%F0%9F%8C%B3-lightgreen\\" | ||
alt=\\"should unwrap\\" | ||
/> | ||
<a href=\\"https://ecologi.com/stoplightinc\\"> | ||
<img | ||
src=\\"https://img.shields.io/badge/Buy%20us%20a%20tree-%F0%9F%8C%B3-lightgreen\\" | ||
alt=\\"should unwrap\\" | ||
inline=\\"true\\" | ||
/> | ||
</a> | ||
<p> | ||
<img | ||
src=\\"https://img.shields.io/badge/Buy%20us%20a%20tree-%F0%9F%8C%B3-lightgreen\\" | ||
alt=\\"should NOT unwrap\\" | ||
inline=\\"true\\" | ||
/>{\\" \\"} | ||
<a href=\\"https://ecologi.com/stoplightinc\\"> | ||
<img | ||
src=\\"https://img.shields.io/badge/Buy%20us%20a%20tree-%F0%9F%8C%B3-lightgreen\\" | ||
alt=\\"should NOT unwrap\\" | ||
inline=\\"true\\" | ||
/> | ||
</a> | ||
</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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export * from './annotations'; | ||
export * from './blockquote'; | ||
export * from './code'; | ||
export * from './inline-images'; | ||
export * from './resolver'; | ||
export * from './slug'; | ||
export * from './unwrap-images'; |
Oops, something went wrong.