Skip to content

Commit

Permalink
[gatsby-transformer-remark] Reparse raw nodes in htmlAst (#3731)
Browse files Browse the repository at this point in the history
Preprocessing via `gatsby-remark-*` transformations introduces `raw`
nodes into the AST. Adding this step fully enables the client to render
the AST as React components, finishing the work started in #3596.
  • Loading branch information
ryaninvents authored and KyleAMathews committed Jan 27, 2018
1 parent 0896e85 commit 22fe988
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/gatsby-transformer-remark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"bluebird": "^3.5.0",
"graphql-type-json": "^0.1.4",
"gray-matter": "^3.0.0",
"hast-util-raw": "^2.0.2",
"hast-util-to-html": "^3.0.0",
"lodash": "^4.17.4",
"mdast-util-to-hast": "^2.4.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/gatsby-transformer-remark/src/extend-node-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const english = require(`retext-english`)
const remark2retext = require(`remark-retext`)
const GraphQlJson = require(`graphql-type-json`)
const stripPosition = require(`unist-util-remove-position`)
const hastReparseRaw = require(`hast-util-raw`)

let pluginsCacheStr = ``
const astCacheKey = node =>
Expand Down Expand Up @@ -292,7 +293,7 @@ module.exports = (
resolve(markdownNode) {
return getHTMLAst(markdownNode).then(ast => {
const strippedAst = stripPosition(_.clone(ast), true)
return strippedAst
return hastReparseRaw(strippedAst)
})
},
},
Expand Down
81 changes: 79 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
version "3.0.1"
resolved "https://registry.yarnpkg.com/@types/inline-style-prefixer/-/inline-style-prefixer-3.0.1.tgz#8541e636b029124b747952e9a28848286d2b5bf6"

"@types/node@*":
version "9.4.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.4.0.tgz#b85a0bcf1e1cc84eb4901b7e96966aedc6f078d1"

"@types/node@^6.0.46":
version "6.0.90"
resolved "https://registry.yarnpkg.com/@types/node/-/node-6.0.90.tgz#0ed74833fa1b73dcdb9409dcb1c97ec0a8b13b02"
Expand Down Expand Up @@ -3340,7 +3344,7 @@ defaults@^1.0.3:
dependencies:
clone "^1.0.2"

define-properties@^1.1.2:
define-properties@^1.1.1, define-properties@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.2.tgz#83a73f2fea569898fb737193c8f873caf6d45c94"
dependencies:
Expand Down Expand Up @@ -5560,6 +5564,18 @@ hash.js@^1.0.0, hash.js@^1.0.3:
inherits "^2.0.3"
minimalistic-assert "^1.0.0"

hast-to-hyperscript@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/hast-to-hyperscript/-/hast-to-hyperscript-3.1.0.tgz#58ef4af5344f4da22f0622e072a8d5fa062693d3"
dependencies:
comma-separated-tokens "^1.0.0"
is-nan "^1.2.1"
kebab-case "^1.0.0"
property-information "^3.0.0"
space-separated-tokens "^1.0.0"
trim "0.0.1"
unist-util-is "^2.0.0"

hast-util-embedded@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/hast-util-embedded/-/hast-util-embedded-1.0.0.tgz#49d6114b40933a9d0bd708a3b012378f2cd6e86c"
Expand All @@ -5576,6 +5592,15 @@ hast-util-from-parse5@^1.0.0:
property-information "^3.1.0"
vfile-location "^2.0.0"

hast-util-from-parse5@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/hast-util-from-parse5/-/hast-util-from-parse5-2.1.0.tgz#f6123d83d3689630b097e13e430d16d9d1bd8884"
dependencies:
camelcase "^3.0.0"
hastscript "^3.0.0"
property-information "^3.1.0"
vfile-location "^2.0.0"

hast-util-has-property@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/hast-util-has-property/-/hast-util-has-property-1.0.1.tgz#ac08c40bcbf27b80a85aaae91e4f6250a53e802f"
Expand All @@ -5595,6 +5620,18 @@ hast-util-parse-selector@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/hast-util-parse-selector/-/hast-util-parse-selector-2.1.0.tgz#b55c0f4bb7bb2040c889c325ef87ab29c38102b4"

hast-util-raw@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/hast-util-raw/-/hast-util-raw-2.0.2.tgz#20674cfb45428213917a54ec929e6774df0642d8"
dependencies:
hast-util-from-parse5 "^2.0.0"
hast-util-to-parse5 "^2.0.0"
html-void-elements "^1.0.1"
parse5 "^3.0.3"
unist-util-position "^3.0.0"
web-namespaces "^1.0.0"
zwitch "^1.0.0"

hast-util-sanitize@^1.0.0:
version "1.1.2"
resolved "https://registry.yarnpkg.com/hast-util-sanitize/-/hast-util-sanitize-1.1.2.tgz#d10bd6757a21e59c13abc8ae3530dd3b6d7d679e"
Expand Down Expand Up @@ -5629,6 +5666,16 @@ hast-util-to-mdast@^1.1.0:
unist-util-visit "^1.1.1"
xtend "^4.0.1"

hast-util-to-parse5@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/hast-util-to-parse5/-/hast-util-to-parse5-2.2.0.tgz#48c8f7f783020c04c3625db06109d02017033cbc"
dependencies:
hast-to-hyperscript "^3.0.0"
mapz "^1.0.0"
web-namespaces "^1.0.0"
xtend "^4.0.1"
zwitch "^1.0.0"

hast-util-to-string@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/hast-util-to-string/-/hast-util-to-string-1.0.1.tgz#b28055cdca012d3c8fd048757c8483d0de0d002c"
Expand Down Expand Up @@ -5762,7 +5809,7 @@ html-minifier@^3.2.3:
relateurl "0.2.x"
uglify-js "3.3.x"

html-void-elements@^1.0.0:
html-void-elements@^1.0.0, html-void-elements@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/html-void-elements/-/html-void-elements-1.0.2.tgz#9d22e0ca32acc95b3f45b8d5b4f6fbdc05affd55"

Expand Down Expand Up @@ -6271,6 +6318,12 @@ is-lower-case@^1.1.0:
dependencies:
lower-case "^1.1.0"

is-nan@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/is-nan/-/is-nan-1.2.1.tgz#9faf65b6fb6db24b7f5c0628475ea71f988401e2"
dependencies:
define-properties "^1.1.1"

is-natural-number@^2.0.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/is-natural-number/-/is-natural-number-2.1.1.tgz#7d4c5728377ef386c3e194a9911bf57c6dc335e7"
Expand Down Expand Up @@ -7915,6 +7968,12 @@ map-visit@^1.0.0:
dependencies:
object-visit "^1.0.0"

mapz@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/mapz/-/mapz-1.0.1.tgz#9ecec757d3c3fe0a8a6f363e328eaee69a428441"
dependencies:
x-is-array "^0.1.0"

markdown-escapes@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/markdown-escapes/-/markdown-escapes-1.0.1.tgz#1994df2d3af4811de59a6714934c2b2292734518"
Expand Down Expand Up @@ -9218,6 +9277,12 @@ parse5@^3.0.1:
dependencies:
"@types/node" "^6.0.46"

parse5@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/parse5/-/parse5-3.0.3.tgz#042f792ffdd36851551cf4e9e066b3874ab45b5c"
dependencies:
"@types/node" "*"

[email protected]:
version "0.0.5"
resolved "https://registry.yarnpkg.com/parseqs/-/parseqs-0.0.5.tgz#d5208a3738e46766e291ba2ea173684921a8b89d"
Expand Down Expand Up @@ -13893,6 +13958,10 @@ wcwidth@^1.0.0:
dependencies:
defaults "^1.0.3"

web-namespaces@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/web-namespaces/-/web-namespaces-1.1.1.tgz#742d9fff61ff84f4164f677244f42d29c10c451d"

webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
Expand Down Expand Up @@ -14204,6 +14273,10 @@ ws@~2.3.1:
safe-buffer "~5.0.1"
ultron "~1.1.0"

x-is-array@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/x-is-array/-/x-is-array-0.1.0.tgz#de520171d47b3f416f5587d629b89d26b12dc29d"

x-is-function@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/x-is-function/-/x-is-function-1.0.4.tgz#5d294dc3d268cbdd062580e0c5df77a391d1fa1e"
Expand Down Expand Up @@ -14476,3 +14549,7 @@ yurnalist@^0.2.1:
rimraf "^2.5.0"
semver "^5.1.0"
strip-bom "^3.0.0"

zwitch@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/zwitch/-/zwitch-1.0.2.tgz#9b059541bfa844799fe2d903bde609de2503a041"

0 comments on commit 22fe988

Please sign in to comment.