[ci] format
This commit is contained in:
parent
394ab90547
commit
dfa1042f2b
1 changed files with 12 additions and 10 deletions
|
@ -4,19 +4,21 @@ import { getHighlighter as getShikiHighlighter } from 'shiki';
|
||||||
const _resolvedHighlighters = new Map();
|
const _resolvedHighlighters = new Map();
|
||||||
|
|
||||||
function stringify(opts) {
|
function stringify(opts) {
|
||||||
// Always sort keys before stringifying to make sure objects match regardless of parameter ordering
|
// Always sort keys before stringifying to make sure objects match regardless of parameter ordering
|
||||||
return JSON.stringify(opts, Object.keys(opts).sort());
|
return JSON.stringify(opts, Object.keys(opts).sort());
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getHighlighter(opts) {
|
export function getHighlighter(opts) {
|
||||||
const key = stringify(opts);
|
const key = stringify(opts);
|
||||||
|
|
||||||
// Highlighter has already been requested, reuse the same instance
|
// Highlighter has already been requested, reuse the same instance
|
||||||
if (_resolvedHighlighters.has(key)) { return _resolvedHighlighters.get(key) }
|
if (_resolvedHighlighters.has(key)) {
|
||||||
|
return _resolvedHighlighters.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
// Start the async getHighlighter call and cache the Promise
|
// Start the async getHighlighter call and cache the Promise
|
||||||
const highlighter = getShikiHighlighter(opts);
|
const highlighter = getShikiHighlighter(opts);
|
||||||
_resolvedHighlighters.set(key, highlighter);
|
_resolvedHighlighters.set(key, highlighter);
|
||||||
|
|
||||||
return highlighter;
|
return highlighter;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue