Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: syntax-tree/mdast-util-mdx-expression
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8f987cb
Choose a base ref
...
head repository: syntax-tree/mdast-util-mdx-expression
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e87a677
Choose a head ref
  • 5 commits
  • 4 files changed
  • 1 contributor

Commits on Sep 23, 2021

  1. Verified

    This commit was signed with the committer’s verified signature.
    wooorm Titus
    Copy the full SHA
    89e9bee View commit details

Commits on Oct 2, 2021

  1. Update dev-dependencies

    wooorm committed Oct 2, 2021

    Verified

    This commit was signed with the committer’s verified signature.
    wooorm Titus
    Copy the full SHA
    8a2fb0c View commit details

Commits on Jan 31, 2022

  1. Update dev-dependencies

    wooorm committed Jan 31, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    wooorm Titus
    Copy the full SHA
    bebeaf4 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    wooorm Titus
    Copy the full SHA
    73d1d52 View commit details
  3. 1.2.0

    wooorm committed Jan 31, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    wooorm Titus
    Copy the full SHA
    e87a677 View commit details
Showing with 70 additions and 11 deletions.
  1. +16 −4 complex-types.d.ts
  2. +7 −2 index.js
  3. +7 −5 package.json
  4. +40 −0 test.js
20 changes: 16 additions & 4 deletions complex-types.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {Literal} from 'mdast'
import {Program} from 'estree-jsx'

export interface MDXFlowExpression extends Literal {
export interface MdxFlowExpression extends Literal {
type: 'mdxFlowExpression'
data?: {
estree?: Program
} & Literal['data']
}

export interface MDXTextExpression extends Literal {
export interface MdxTextExpression extends Literal {
type: 'mdxTextExpression'
data?: {
estree?: Program
@@ -17,10 +17,22 @@ export interface MDXTextExpression extends Literal {

declare module 'mdast' {
interface StaticPhrasingContentMap {
mdxTextExpression: MDXTextExpression
mdxTextExpression: MdxTextExpression
}

interface BlockContentMap {
mdxFlowExpression: MDXFlowExpression
mdxFlowExpression: MdxFlowExpression
}
}

declare module 'hast' {
interface RootContentMap {
mdxTextExpression: MdxTextExpression
mdxFlowExpression: MdxFlowExpression
}

interface ElementContentMap {
mdxFlowExpression: MdxFlowExpression
mdxFlowExpression: MdxFlowExpression
}
}
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -4,8 +4,13 @@
* @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension
* @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle
* @typedef {import('estree-jsx').Program} Program
* @typedef {import('./complex-types').MDXFlowExpression} MDXFlowExpression
* @typedef {import('./complex-types').MDXTextExpression} MDXTextExpression
* @typedef {import('./complex-types').MdxFlowExpression} MdxFlowExpression
* @typedef {import('./complex-types').MdxTextExpression} MdxTextExpression
*/

/**
* @typedef {MdxFlowExpression} MDXFlowExpression
* @typedef {MdxTextExpression} MDXTextExpression
*/

/** @type {FromMarkdownExtension} */
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mdast-util-mdx-expression",
"version": "1.1.1",
"version": "1.2.0",
"description": "mdast extension to parse and serialize MDX (or MDX.js) expressions",
"license": "MIT",
"keywords": [
@@ -36,15 +36,17 @@
"index.js"
],
"dependencies": {
"@types/estree-jsx": "^0.0.1"
"@types/estree-jsx": "^0.0.1",
"@types/hast": "^2.0.0",
"@types/mdast": "^3.0.0",
"mdast-util-from-markdown": "^1.0.0",
"mdast-util-to-markdown": "^1.0.0"
},
"devDependencies": {
"@types/acorn": "^4.0.0",
"@types/tape": "^4.0.0",
"acorn": "^8.0.0",
"c8": "^7.0.0",
"mdast-util-from-markdown": "^1.0.0",
"mdast-util-to-markdown": "^1.0.0",
"micromark-extension-mdx-expression": "^1.0.0",
"prettier": "^2.0.0",
"remark-cli": "^10.0.0",
@@ -54,7 +56,7 @@
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"unist-util-remove-position": "^4.0.0",
"xo": "^0.44.0"
"xo": "^0.47.0"
},
"scripts": {
"build": "rimraf \"{index,test}.d.ts\" && tsc && type-coverage",
40 changes: 40 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -471,3 +471,43 @@ test('mdast -> markdown', (t) => {

t.end()
})

test('markdown -> mdast -> markdown', (t) => {
t.deepEqual(
toMarkdown(
fromMarkdown(' {`\n a\n `}', {
extensions: [mdxExpression()],
mdastExtensions: [mdxExpressionFromMarkdown]
}),
{extensions: [mdxExpressionToMarkdown]}
),
'{`\na\n`}\n',
'should strip superfluous whitespace as much as the opening prefix, or less, when roundtripping expressions (flow)'
)

t.deepEqual(
toMarkdown(
fromMarkdown(' {`\n a\n `}', {
extensions: [mdxExpression()],
mdastExtensions: [mdxExpressionFromMarkdown]
}),
{extensions: [mdxExpressionToMarkdown]}
),
'{`\n a\n`}\n',
'should strip superfluous whitespace (but not more) when roundtripping expressions (flow)'
)

t.deepEqual(
toMarkdown(
fromMarkdown('a {`\n b\n `} c', {
extensions: [mdxExpression()],
mdastExtensions: [mdxExpressionFromMarkdown]
}),
{extensions: [mdxExpressionToMarkdown]}
),
'a {`\n b\n `} c\n',
'should not strip consecutive lines in expressions (text)'
)

t.end()
})