1
0
mirror of synced 2025-12-23 11:54:18 -05:00
Files
docs/lib/use-english-headings.js
Kevin Heis 43158e8392 Upgrade NPM packages (#21480)
* 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
2021-09-13 23:31:43 +00:00

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 $
}