Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

use-english-headings.js 713 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  1. const GithubSlugger = require('github-slugger')
  2. const slugger = new GithubSlugger()
  3. const Entities = require('html-entities').XmlEntities
  4. const entities = new Entities()
  5. // replace translated IDs and links in headings with English
  6. module.exports = function useEnglishHeadings ($, englishHeadings) {
  7. $('h2, h3, h4').each((i, el) => {
  8. slugger.reset()
  9. // find English heading in the collection
  10. const englishHeading = englishHeadings[entities.encode($(el).text())]
  11. // get English slug
  12. const englishSlug = slugger.slug(englishHeading)
  13. // use English slug for heading ID and link
  14. $(el).attr('id', englishSlug)
  15. $(el).children('a').attr('href', `#${englishSlug}`)
  16. })
  17. return $
  18. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...