Skip to content

Commit

Permalink
docs: replace spaces following wrapped up nerdfont icons with narrow …
Browse files Browse the repository at this point in the history
…ones, for much nicer aesthetics
  • Loading branch information
Omnikron13 committed May 18, 2024
1 parent 6ba72cd commit e0d4b36
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion docs/assets/scripts/add_accents.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
// Description: This script adds the classes 'accent' and 'nerd-font' to the first character of the selected elements,
// if said character is part of the NerdFont glyph set.

// Replace a space following the NerdFont 'icon' with e.g. a thinner one, which tends to look nicer.
// Some options, in descending order or width, include:
// Medium Space - \u205f
// Thin Space - \u2009
// Narrow no-break - \u202f (same width as thin space)
// 'six-per-em' - \u2006
// Hair Space - \u200a
// (to not replace, honestly just replace the space with a space...)
const trailingSpace = '\u202f'

window.addEventListener('DOMContentLoaded', () => {
const accentify = [
...document.querySelectorAll('h1, h2, a, em, .md-ellipsis'),
Expand Down Expand Up @@ -30,7 +40,7 @@ window.addEventListener('DOMContentLoaded', () => {
const firstChar = text.codePointAt(0)
if (nerdRanges.map(r => r.ranges).flat().some(r => firstChar >= r.first && firstChar <= r.last)) {
const glyph = String.fromCodePoint(firstChar)
const tail = text.substring(glyph.length)
const tail = text.substring(glyph.length).replace(/^ /, trailingSpace)
const accentSpan = document.createElement('span')
accentSpan.classList.add('accent', 'nerd-font')
accentSpan.innerText = glyph
Expand Down

0 comments on commit e0d4b36

Please sign in to comment.