-
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
feat: jsx variables #899
Changes from 4 commits
dd1b959
ee448d4
934a9c6
9340e9c
1083b36
3d1f4db
7af5e71
7fba670
f28dcb7
23c2714
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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()); | ||
| }); | ||
| }); |
| 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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,16 +4,14 @@ category: 5fdf9fc9c2a7ef443e937315 | |
| hidden: true | ||
| --- | ||
|
|
||
| <Variable variable="defvar" /> and `<Variable variable="defvar" />` and: | ||
| This is the variable `defvar`: {user.defvar} | ||
|
|
||
| ``` | ||
| <Variable variable="defvar" /> | ||
| ``` | ||
| Ok, but this one is defined: {user.email} | ||
|
|
||
| and | ||
| It does not render in code blocks: | ||
|
|
||
| ```js | ||
| const xyz = "<Variable variable="defvar" />"; | ||
| ``` | ||
| {user.defvar} | ||
| ``` | ||
|
||
|
|
||
| ## Glossary Items | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,13 +18,6 @@ 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 +33,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(); | ||
|
|
||
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