-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove trailing hyphen from generated id (#124)
- Loading branch information
1 parent
b9acd9d
commit 60475df
Showing
3 changed files
with
11 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,14 @@ | ||
const separators = /[\s\][!"#$%&'()*+,./:;<=>?@\\^_{|}~-]/g; | ||
|
||
export const generate = { | ||
/** | ||
* @param {'clipboard' | 'list'} name | ||
* @param {string} tooltip | ||
*/ | ||
icon(name, tooltip) { | ||
const span = `<span data-mrq="tooltip" class="mrq">${tooltip}</span>`; | ||
return `<button data-mrq-toolbar="${name}" class="mrq">${span}</button>`; | ||
}, | ||
/** @param {string} title */ | ||
id(title) { | ||
title = title.toLowerCase().replace(separators, '-'); | ||
title = title.replace(/`/g, '').replace(/-+/g, '-'); | ||
return title.replace(/^-*(.+)-*$/, '$1'); | ||
}, | ||
}; | ||
|
||
/** @param {string} source */ | ||
export function escape(source) { | ||
const symbols = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }; | ||
return source.replace(/[&<>"']/g, (s) => symbols[/** @type {keyof typeof symbols} */ (s)]); | ||
} | ||
|
||
/** @param {string} title */ | ||
export function uhi(title) { | ||
const cleaned = title.toLowerCase().replace(separators, '-'); | ||
const normalized = cleaned.replace(/`/g, '').replace(/-+/g, '-'); | ||
return normalized.replace(/^-*(.+?)-*$/, '$1'); // hyphen at the sides | ||
} |