Skip to content

Commit

Permalink
Use hast-util-to-string to get heading text (github#17576)
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonEtco authored Jan 29, 2021
1 parent 4f0f4cc commit 53ad15c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/render-content/plugins/use-english-headings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const GithubSlugger = require('github-slugger')
const Entities = require('html-entities').XmlEntities
const toString = require('hast-util-to-string')
const visit = require('unist-util-visit')
const slugger = new GithubSlugger()
const entities = new Entities()
Expand All @@ -14,7 +15,8 @@ module.exports = function useEnglishHeadings ({ englishHeadings }) {
if (!englishHeadings) return
return tree => {
visit(tree, matcher, node => {
const text = node.children.find(n => n.type === 'text').value
// Get the plain text content of the heading node
const text = toString(node)
// find English heading in the collection
const englishHeading = englishHeadings[entities.encode(text)]
// get English slug
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"hast-util-from-parse5": "^6.0.1",
"hast-util-parse-selector": "^2.2.5",
"hast-util-select": "^4.0.2",
"hast-util-to-string": "^1.0.4",
"hastscript": "^6.0.0",
"helmet": "^3.21.2",
"highlightjs-graphql": "^1.0.2",
Expand Down Expand Up @@ -162,7 +163,7 @@
"website-scraper": "^4.2.0"
},
"scripts": {
"start": "cross-env NODE_ENV=development ENABLED_LANGUAGES='en,ja' nodemon server.js",
"start": "cross-env NODE_ENV=development ENABLED_LANGUAGES='en,cn' nodemon server.js",
"dev": "npm start",
"debug": "cross-env NODE_ENV=development ENABLED_LANGUAGES='en,ja' nodemon --inspect server.js",
"rest-dev": "script/rest/update-files.js && npm run dev",
Expand Down

0 comments on commit 53ad15c

Please sign in to comment.