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: mdx-js/mdx
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.18.1
Choose a base ref
...
head repository: mdx-js/mdx
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.18.2
Choose a head ref
  • 2 commits
  • 10 files changed
  • 1 contributor

Commits on Feb 28, 2019

  1. Better handle JSX block parsing in remark-mdx (#415)

    * Add failing test for inline jsx issue
    
    * Add repro test
    
    * Add and modify remark html block parser
    
    * Skip failing test that shouldn't pass yet
    johno authored Feb 28, 2019
    1

    Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    5fada56 View commit details
  2. v0.18.2

    johno committed Feb 28, 2019
    1
    Copy the full SHA
    5938d62 View commit details
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"lerna": "3.4.0",
"version": "0.18.1",
"version": "0.18.2",
"packages": [
"packages/*"
],
4 changes: 2 additions & 2 deletions packages/loader/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mdx-js/loader",
"version": "0.18.1",
"version": "0.18.2",
"description": "Loader for MDX",
"license": "MIT",
"keywords": [
@@ -27,7 +27,7 @@
"index.js"
],
"dependencies": {
"@mdx-js/mdx": "^0.18.1",
"@mdx-js/mdx": "^0.18.2",
"@mdx-js/tag": "^0.18.0",
"loader-utils": "^1.1.0"
},
2 changes: 1 addition & 1 deletion packages/mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mdx-js/mdx",
"version": "0.18.1",
"version": "0.18.2",
"description": "Parse MDX and transpile to JSX",
"license": "MIT",
"keywords": [
10 changes: 10 additions & 0 deletions packages/mdx/test/index.test.js
Original file line number Diff line number Diff line change
@@ -356,6 +356,16 @@ test('Should process filepath and pass it to the plugins', async () => {
expect(result).toMatch(/HELLO, WORLD!/)
})

test.skip('Should handle inline JSX', async () => {
const result = await mdx(
'Hello, <span style={{ color: "tomato" }}>world</span>'
)

expect(result).toContain(
'<MDXTag name="p" components={components}>Hello, <span style={{ color: "tomato" }}>world</span></MDXTag>'
)
})

test('Should parse and render footnotes', async () => {
const result = await mdx(
'This is a paragraph with a [^footnote]\n\n[^footnote]: Here is the footnote'
4 changes: 2 additions & 2 deletions packages/parcel-plugin-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mdx-js/parcel-plugin-mdx",
"version": "0.18.1",
"version": "0.18.2",
"description": "Parcel plugin for MDX",
"license": "MIT",
"keywords": [
@@ -27,7 +27,7 @@
"src"
],
"dependencies": {
"@mdx-js/mdx": "^0.18.1",
"@mdx-js/mdx": "^0.18.2",
"parcel-bundler": "^1.4.1"
},
"peerDependencies": {
113 changes: 113 additions & 0 deletions packages/remark-mdx/block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Source copied and then modified from
// https://github.com/remarkjs/remark/blob/master/packages/remark-parse/lib/tokenize/html-block.js
//
// MIT License https://github.com/remarkjs/remark/blob/master/license

const {openCloseTag} = require('./tag')

module.exports = blockHtml

const tab = '\t'
const space = ' '
const lineFeed = '\n'
const lessThan = '<'

const rawOpenExpression = /^<(script|pre|style)(?=(\s|>|$))/i
const rawCloseExpression = /<\/(script|pre|style)>/i
const commentOpenExpression = /^<!--/
const commentCloseExpression = /-->/
const instructionOpenExpression = /^<\?/
const instructionCloseExpression = /\?>/
const directiveOpenExpression = /^<![A-Za-z]/
const directiveCloseExpression = />/
const cdataOpenExpression = /^<!\[CDATA\[/
const cdataCloseExpression = /\]\]>/
const elementCloseExpression = /^$/
const otherElementOpenExpression = new RegExp(openCloseTag.source + '\\s*$')

function blockHtml(eat, value, silent) {
const blocks = '[a-z\\.]+(\\.){0,1}[a-z\\.]'
const elementOpenExpression = new RegExp(
'^</?(' + blocks + ')(?=(\\s|/?>|$))',
'i'
)
const length = value.length
let index = 0
let next
let line
let offset
let character
let count
let sequence
let subvalue

const sequences = [
[rawOpenExpression, rawCloseExpression, true],
[commentOpenExpression, commentCloseExpression, true],
[instructionOpenExpression, instructionCloseExpression, true],
[directiveOpenExpression, directiveCloseExpression, true],
[cdataOpenExpression, cdataCloseExpression, true],
[elementOpenExpression, elementCloseExpression, true],
[otherElementOpenExpression, elementCloseExpression, false]
]

// Eat initial spacing.
while (index < length) {
character = value.charAt(index)

if (character !== tab && character !== space) {
break
}

index++
}

if (value.charAt(index) !== lessThan) {
return
}

next = value.indexOf(lineFeed, index + 1)
next = next === -1 ? length : next
line = value.slice(index, next)
offset = -1
count = sequences.length

while (++offset < count) {
if (sequences[offset][0].test(line)) {
sequence = sequences[offset]
break
}
}

if (!sequence) {
return
}

if (silent) {
return sequence[2]
}

index = next

if (!sequence[1].test(line)) {
while (index < length) {
next = value.indexOf(lineFeed, index + 1)
next = next === -1 ? length : next
line = value.slice(index + 1, next)

if (sequence[1].test(line)) {
if (line) {
index = next
}

break
}

index = next
}
}

subvalue = value.slice(0, index)

return eat(subvalue)({type: 'html', value: subvalue})
}
5 changes: 3 additions & 2 deletions packages/remark-mdx/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const isAlphabetical = require('is-alphabetical')
const extractImportsAndExports = require('./extract-imports-and-exports')
const block = require('./block')
const {tag} = require('./tag')

const IMPORT_REGEX = /^import/
@@ -37,7 +38,7 @@ function attachParser(parser) {
const methods = parser.prototype.blockMethods

blocks.esSyntax = tokenizeEsSyntax
blocks.html = wrap(blocks.html)
blocks.html = wrap(block)
inlines.html = wrap(inlines.html, inlineJsx)

methods.splice(methods.indexOf('paragraph'), 0, 'esSyntax')
@@ -89,7 +90,7 @@ function attachCompiler(compiler) {
proto.visitors = Object.assign({}, proto.visitors, {
import: stringifyEsSyntax,
export: stringifyEsSyntax,
jsx: proto.visitors.html
jsx: stringifyEsSyntax
})
}

3 changes: 2 additions & 1 deletion packages/remark-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "remark-mdx",
"version": "0.18.0",
"version": "0.18.2",
"description": "Support import, export, and JSX in markdown",
"license": "MIT",
"keywords": [
@@ -24,6 +24,7 @@
"files": [
"index.js",
"tag.js",
"block.js",
"extract-imports-and-exports.js"
],
"dependencies": {
10 changes: 8 additions & 2 deletions packages/remark-mdx/test/fixtures/inline-parsing.js
Original file line number Diff line number Diff line change
@@ -65,10 +65,16 @@ module.exports = [
description: 'Handles links',
mdx: 'Hello, <Component>{props.world}</Component> and a moustache! }: <https://johno.com>'
},
{
description: 'Ignores links inside JSX blocks',
mdx: [
'# Hello, world!',
'<Component>from https://johno.com</Component>'
].join('\n\n')
},
{
description: 'Handles multiline JSX blocks',
mdx: `
<Image
mdx: `<Image
src={asset(\`\${SOME_CONSTANT}/some.png\`)}
width="123"
height="456"
4 changes: 2 additions & 2 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mdx-js/runtime",
"version": "0.18.1",
"version": "0.18.2",
"description": "Parse and render MDX in a runtime environment",
"license": "MIT",
"keywords": [
@@ -33,7 +33,7 @@
"src/"
],
"dependencies": {
"@mdx-js/mdx": "^0.18.1",
"@mdx-js/mdx": "^0.18.2",
"@mdx-js/tag": "^0.18.0",
"buble": "^0.19.6"
},