1
0
mirror of synced 2025-12-22 03:16:52 -05:00
Files
docs/lib/use-english-headings.js
Vanessa Yuen 3df90fc9b8 Hello git history spelunker!
Are you looking for something? Here is all of the GitHub Docs history in one single commit. Enjoy! 🎉
2020-09-27 14:10:11 +02:00

24 lines
713 B
JavaScript

const GithubSlugger = require('github-slugger')
const slugger = new GithubSlugger()
const Entities = require('html-entities').XmlEntities
const entities = new Entities()
// replace translated IDs and links in headings with English
module.exports = function useEnglishHeadings ($, englishHeadings) {
$('h2, h3, h4').each((i, el) => {
slugger.reset()
// find English heading in the collection
const englishHeading = englishHeadings[entities.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 $
}