* Upgrade a bunch of packages * ...and upgrade highlightjs * ... and ajv-formats (but not ajv) * Revert graphql changes * Revert "Revert graphql changes" This reverts commit a5b8a34d52a48a7c2858415f6b1081c1d4902482. * Update build-changelog.js * Upgrade html-entities * Upgrade commander, following migration guide
23 lines
649 B
JavaScript
23 lines
649 B
JavaScript
import GithubSlugger from 'github-slugger'
|
|
import { encode } from 'html-entities'
|
|
const slugger = new GithubSlugger()
|
|
|
|
// replace translated IDs and links in headings with English
|
|
export default function useEnglishHeadings($, englishHeadings) {
|
|
$('h2, h3, h4').each((i, el) => {
|
|
slugger.reset()
|
|
|
|
// find English heading in the collection
|
|
const englishHeading = englishHeadings[encode($(el).text())]
|
|
|
|
// get English slug
|
|
const englishSlug = slugger.slug(englishHeading)
|
|
|
|
// use English slug for heading ID and link
|
|
$(el).attr('id', englishSlug)
|
|
$(el).children('a').attr('href', `#${englishSlug}`)
|
|
})
|
|
|
|
return $
|
|
}
|