-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
| [![PR App][icn]][demo] | Fix RM-9827 | | :--------------------: | :---------: | ## 🧰 Changes Adds backwards compatibility with variables, glossary, and reusable content. When we're trying to update a document from markdown to MDX, we first parse the document to an mdast using the old markdown library. Then we serialize it back to MDX with this version. Basically: ``` const mdx = rmdx.mdx(rdmd.mdast(doc)) ``` But, because these types are now completely represented in JSX, we didn't have any custom compilers to handle them. This adds some compilers to write their nodes back out as JSX. ### Callouts Also, refactors how callouts are represented. Adds a prop to the node `empty` to represent if there's a heading a not. It's a bit more plumbing to get mdx to parse and execute props, so this leaves the heading as a child. ### HTML Comments To be able to migrate away, we need to replace html comments with JSX comments. ## 🧬 QA & Testing - [Broken on production][prod]. - [Working in this PR app][demo]. [demo]: https://markdown-pr-PR_NUMBER.herokuapp.com [prod]: https://SUBDOMAIN.readme.io [icn]: https://user-images.githubusercontent.com/886627/160426047-1bee9488-305a-4145-bb2b-09d8b757d38a.svg
- Loading branch information
1 parent
6d8dbdc
commit 6432be8
Showing
18 changed files
with
135 additions
and
54 deletions.
There are no files selected for viewing
Binary file modified
BIN
+1.41 KB
(110%)
...regression-tests-rdmd-syntax-renders-callout-tests-without-surprises-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+8.18 KB
(110%)
...visual-regression-tests-rdmd-syntax-renders-embeds-without-surprises-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,49 @@ | ||
import { mdx } from '../../index'; | ||
|
||
describe('compatability with RDMD', () => { | ||
it('compiles variable nodes', () => { | ||
const ast = { | ||
type: 'readme-variable', | ||
text: 'parliament', | ||
data: { | ||
hName: 'readme-variable', | ||
hProperties: { | ||
variable: 'parliament', | ||
}, | ||
}, | ||
}; | ||
|
||
expect(mdx(ast).trim()).toBe('<Variable name="parliament" />'); | ||
}); | ||
|
||
it('compiles glossary nodes', () => { | ||
const ast = { | ||
type: 'readme-glossary-item', | ||
data: { | ||
hProperties: { | ||
term: 'parliament', | ||
}, | ||
}, | ||
}; | ||
|
||
expect(mdx(ast).trim()).toBe('<Glossary>parliament</Glossary>'); | ||
}); | ||
|
||
it('compiles reusable-content nodes', () => { | ||
const ast = { | ||
type: 'reusable-content', | ||
tag: 'Parliament', | ||
}; | ||
|
||
expect(mdx(ast).trim()).toBe('<Parliament />'); | ||
}); | ||
|
||
it('compiles html comments to JSX comments', () => { | ||
const ast = { | ||
type: 'html', | ||
value: '<!-- commentable -->', | ||
}; | ||
|
||
expect(mdx(ast).trim()).toBe('{/* commentable */}'); | ||
}); | ||
}); |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,25 @@ | ||
import { Html } from 'mdast'; | ||
import { NodeTypes } from '../../enums'; | ||
|
||
type CompatNodes = | ||
| { type: NodeTypes.variable; text: string } | ||
| { type: NodeTypes.glossary; data: { hProperties: { term: string } } } | ||
| { type: NodeTypes.reusableContent; tag: string } | ||
| Html; | ||
|
||
const compatibility = (node: CompatNodes) => { | ||
switch (node.type) { | ||
case NodeTypes.variable: | ||
return `<Variable name="${node.text}" />`; | ||
case NodeTypes.glossary: | ||
return `<Glossary>${node.data.hProperties.term}</Glossary>`; | ||
case NodeTypes.reusableContent: | ||
return `<${node.tag} />`; | ||
case 'html': | ||
return node.value.replaceAll(/<!--(.*)-->/g, '{/*$1*/}'); | ||
default: | ||
throw new Error('Unhandled node type!'); | ||
} | ||
}; | ||
|
||
export default compatibility; |
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