[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();
|
||||
|
||||
function stringify(opts) {
|
||||
// Always sort keys before stringifying to make sure objects match regardless of parameter ordering
|
||||
return JSON.stringify(opts, Object.keys(opts).sort());
|
||||
// Always sort keys before stringifying to make sure objects match regardless of parameter ordering
|
||||
return JSON.stringify(opts, Object.keys(opts).sort());
|
||||
}
|
||||
|
||||
export function getHighlighter(opts) {
|
||||
const key = stringify(opts);
|
||||
const key = stringify(opts);
|
||||
|
||||
// Highlighter has already been requested, reuse the same instance
|
||||
if (_resolvedHighlighters.has(key)) { return _resolvedHighlighters.get(key) }
|
||||
// Highlighter has already been requested, reuse the same instance
|
||||
if (_resolvedHighlighters.has(key)) {
|
||||
return _resolvedHighlighters.get(key);
|
||||
}
|
||||
|
||||
// Start the async getHighlighter call and cache the Promise
|
||||
const highlighter = getShikiHighlighter(opts);
|
||||
_resolvedHighlighters.set(key, highlighter);
|
||||
// Start the async getHighlighter call and cache the Promise
|
||||
const highlighter = getShikiHighlighter(opts);
|
||||
_resolvedHighlighters.set(key, highlighter);
|
||||
|
||||
return highlighter;
|
||||
}
|
||||
return highlighter;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue