-
Notifications
You must be signed in to change notification settings - Fork 15
feat: jsx variables #899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: jsx variables #899
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dd1b959
variables?
kellyjosephprice ee448d4
Merge branch 'beta' into kp/variables
kellyjosephprice 934a9c6
compiling
kellyjosephprice 9340e9c
docs
kellyjosephprice 1083b36
wip
kellyjosephprice 3d1f4db
update deps
kellyjosephprice 7af5e71
Merge branch 'beta' into kp/variables
kellyjosephprice 7fba670
turn on mdx mode
kellyjosephprice f28dcb7
snaps
kellyjosephprice 23c2714
Merge branch 'beta' into kp/variables
kellyjosephprice File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Binary file modified
BIN
+145 KB
(250%)
...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.
Binary file modified
BIN
+2.65 KB
(110%)
...ual-regression-tests-rdmd-syntax-renders-vars-test-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 hidden or 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 hidden or 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,16 @@ | ||
| import * as rmdx from '../../index'; | ||
|
|
||
| describe('variable compiler', () => { | ||
| it('compiles back to the ', () => { | ||
| const mdx = ` | ||
| ## Hello! | ||
|
|
||
| {user.name} | ||
|
|
||
| ### Bye bye! | ||
| `; | ||
| const tree = rmdx.mdast(mdx); | ||
|
|
||
| expect(rmdx.mdx(tree).trim()).toStrictEqual(mdx.trim()); | ||
| }); | ||
| }); |
This file contains hidden or 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,55 @@ | ||
| import React from 'react'; | ||
| import * as rmdx from '../../index'; | ||
| import { execute } from '../helpers'; | ||
| import { render, screen } from '@testing-library/react'; | ||
|
|
||
| describe('variables transformer', () => { | ||
| it('renders user variables', async () => { | ||
| const mdx = '{user.name}'; | ||
| const variables = { | ||
| user: { | ||
| name: 'Test User', | ||
| }, | ||
| }; | ||
| const Content = await execute(mdx, { variables }); | ||
|
|
||
| render(<Content />); | ||
|
|
||
| expect(screen.findByText('Test User')).toBeDefined(); | ||
| }); | ||
|
|
||
| it('renders user variables in a phrasing context', async () => { | ||
| const mdx = 'Hello, {user.name}!'; | ||
| const variables = { | ||
| user: { | ||
| name: 'Test User', | ||
| }, | ||
| }; | ||
| const Content = await execute(mdx, { variables }); | ||
|
|
||
| render(<Content />); | ||
|
|
||
| expect(screen.findByText('Test User')).toBeDefined(); | ||
| }); | ||
|
|
||
| it('parses variables into the mdast', () => { | ||
| const mdx = `{user.name}`; | ||
|
|
||
| // @ts-ignore | ||
| expect(rmdx.mdast(mdx)).toStrictEqualExceptPosition({ | ||
| children: [ | ||
| { | ||
| children: [], | ||
| data: { | ||
| hName: 'Variable', | ||
| hProperties: { | ||
| name: 'name', | ||
| }, | ||
| }, | ||
| type: 'readme-variable', | ||
| }, | ||
| ], | ||
| type: 'root', | ||
| }); | ||
| }); | ||
| }); |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -11,20 +11,22 @@ const components = { | |
|
|
||
| > 📘 It can render JSX components! | ||
| `, | ||
| Test: ` | ||
| export const Test = ({ color = 'thistle' } = {}) => { | ||
| return <div style={{ backgroundColor: color }}> | ||
| Hello, World! | ||
| </div>; | ||
| }; | ||
|
|
||
| export default Test; | ||
| `, | ||
| }; | ||
|
|
||
| const executedComponents = {}; | ||
| Object.entries(components).forEach(async ([tag, body]) => { | ||
| executedComponents[tag] = await mdx.run(mdx.compile(body)); | ||
| }); | ||
|
|
||
| const variables = { | ||
| user: { | ||
| email: '[email protected]', | ||
| }, | ||
| defaults: [], | ||
| }; | ||
|
|
||
| const terms = [ | ||
| { | ||
| term: 'demo', | ||
|
|
@@ -40,6 +42,19 @@ const terms = [ | |
| }, | ||
| ]; | ||
|
|
||
| const variables = { | ||
| user: { | ||
| email: '[email protected]', | ||
| name: 'kelly joseph price', | ||
| }, | ||
| defaults: [ | ||
| { | ||
| name: 'defvar', | ||
| default: '(default value for defvar)', | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const Doc = () => { | ||
| const { fixture } = useParams(); | ||
| const [searchParams] = useSearchParams(); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
i hate this snap