🎨 Improve readability by reformatting theme assignment logic in highlight directive
This commit is contained in:
@@ -64,7 +64,8 @@ function createHighlightObserver(el, theme) {
|
||||
export const vHighlight = {
|
||||
mounted(el, binding) {
|
||||
const config = binding.value || {};
|
||||
const theme = typeof config === 'string' ? config : (config.theme || 'github-dark');
|
||||
const theme =
|
||||
typeof config === 'string' ? config : config.theme || 'github-dark';
|
||||
|
||||
// Store observer on element for cleanup
|
||||
el._highlightObserver = createHighlightObserver(el, theme);
|
||||
@@ -72,9 +73,15 @@ export const vHighlight = {
|
||||
|
||||
updated(el, binding) {
|
||||
const newConfig = binding.value || {};
|
||||
const newTheme = typeof newConfig === 'string' ? newConfig : (newConfig.theme || 'github-dark');
|
||||
const newTheme =
|
||||
typeof newConfig === 'string'
|
||||
? newConfig
|
||||
: newConfig.theme || 'github-dark';
|
||||
const oldConfig = binding.oldValue || {};
|
||||
const oldTheme = typeof oldConfig === 'string' ? oldConfig : (oldConfig.theme || 'github-dark');
|
||||
const oldTheme =
|
||||
typeof oldConfig === 'string'
|
||||
? oldConfig
|
||||
: oldConfig.theme || 'github-dark';
|
||||
|
||||
// If theme changed, re-highlight
|
||||
if (newTheme !== oldTheme && el.classList.contains('hljs')) {
|
||||
|
||||
Reference in New Issue
Block a user