fix: raw shortcode content rendering in another shortcode

This commit is contained in:
Dillon
2022-05-07 01:20:39 +08:00
parent eb924ead82
commit 28bc034af0
5 changed files with 164 additions and 96 deletions

View File

@@ -94,6 +94,15 @@ var Theme = /*#__PURE__*/function () {
} }
_createClass(Theme, [{ _createClass(Theme, [{
key: "initRaw",
value: function initRaw() {
var _this = this;
this.util.forEach(document.querySelectorAll('[data-raw]'), function ($raw) {
$raw.innerHTML = _this.data[$raw.id];
});
}
}, {
key: "initSVGIcon", key: "initSVGIcon",
value: function initSVGIcon() { value: function initSVGIcon() {
this.util.forEach(document.querySelectorAll('[data-svg-src]'), function ($icon) { this.util.forEach(document.querySelectorAll('[data-svg-src]'), function ($icon) {
@@ -139,15 +148,15 @@ var Theme = /*#__PURE__*/function () {
}, { }, {
key: "initSwitchTheme", key: "initSwitchTheme",
value: function initSwitchTheme() { value: function initSwitchTheme() {
var _this = this; var _this2 = this;
this.util.forEach(document.getElementsByClassName('theme-switch'), function ($themeSwitch) { this.util.forEach(document.getElementsByClassName('theme-switch'), function ($themeSwitch) {
$themeSwitch.addEventListener('click', function () { $themeSwitch.addEventListener('click', function () {
if (document.body.getAttribute('theme') === 'dark') document.body.setAttribute('theme', 'light');else document.body.setAttribute('theme', 'dark'); if (document.body.getAttribute('theme') === 'dark') document.body.setAttribute('theme', 'light');else document.body.setAttribute('theme', 'dark');
_this.isDark = !_this.isDark; _this2.isDark = !_this2.isDark;
window.localStorage && localStorage.setItem('theme', _this.isDark ? 'dark' : 'light'); window.localStorage && localStorage.setItem('theme', _this2.isDark ? 'dark' : 'light');
var _iterator = _createForOfIteratorHelper(_this.switchThemeEventSet), var _iterator = _createForOfIteratorHelper(_this2.switchThemeEventSet),
_step; _step;
try { try {
@@ -166,7 +175,7 @@ var Theme = /*#__PURE__*/function () {
}, { }, {
key: "initSearch", key: "initSearch",
value: function initSearch() { value: function initSearch() {
var _this2 = this; var _this3 = this;
var searchConfig = this.config.search; var searchConfig = this.config.search;
var isMobile = this.util.isMobile(); var isMobile = this.util.isMobile();
@@ -194,18 +203,18 @@ var Theme = /*#__PURE__*/function () {
document.getElementById('menu-mobile').classList.remove('active'); document.getElementById('menu-mobile').classList.remove('active');
$searchLoading.style.display = 'none'; $searchLoading.style.display = 'none';
$searchClear.style.display = 'none'; $searchClear.style.display = 'none';
_this2._searchMobile && _this2._searchMobile.autocomplete.setVal(''); _this3._searchMobile && _this3._searchMobile.autocomplete.setVal('');
}, false); }, false);
$searchClear.addEventListener('click', function () { $searchClear.addEventListener('click', function () {
$searchClear.style.display = 'none'; $searchClear.style.display = 'none';
_this2._searchMobile && _this2._searchMobile.autocomplete.setVal(''); _this3._searchMobile && _this3._searchMobile.autocomplete.setVal('');
}, false); }, false);
this._searchMobileOnClickMask = this._searchMobileOnClickMask || function () { this._searchMobileOnClickMask = this._searchMobileOnClickMask || function () {
$header.classList.remove('open'); $header.classList.remove('open');
$searchLoading.style.display = 'none'; $searchLoading.style.display = 'none';
$searchClear.style.display = 'none'; $searchClear.style.display = 'none';
_this2._searchMobile && _this2._searchMobile.autocomplete.setVal(''); _this3._searchMobile && _this3._searchMobile.autocomplete.setVal('');
}; };
this.clickMaskEventSet.add(this._searchMobileOnClickMask); this.clickMaskEventSet.add(this._searchMobileOnClickMask);
@@ -218,14 +227,14 @@ var Theme = /*#__PURE__*/function () {
}, false); }, false);
$searchClear.addEventListener('click', function () { $searchClear.addEventListener('click', function () {
$searchClear.style.display = 'none'; $searchClear.style.display = 'none';
_this2._searchDesktop && _this2._searchDesktop.autocomplete.setVal(''); _this3._searchDesktop && _this3._searchDesktop.autocomplete.setVal('');
}, false); }, false);
this._searchDesktopOnClickMask = this._searchDesktopOnClickMask || function () { this._searchDesktopOnClickMask = this._searchDesktopOnClickMask || function () {
$header.classList.remove('open'); $header.classList.remove('open');
$searchLoading.style.display = 'none'; $searchLoading.style.display = 'none';
$searchClear.style.display = 'none'; $searchClear.style.display = 'none';
_this2._searchDesktop && _this2._searchDesktop.autocomplete.setVal(''); _this3._searchDesktop && _this3._searchDesktop.autocomplete.setVal('');
}; };
this.clickMaskEventSet.add(this._searchDesktopOnClickMask); this.clickMaskEventSet.add(this._searchDesktopOnClickMask);
@@ -262,10 +271,10 @@ var Theme = /*#__PURE__*/function () {
if (lunr.queryHandler) query = lunr.queryHandler(query); if (lunr.queryHandler) query = lunr.queryHandler(query);
var results = {}; var results = {};
_this2._index.search(query).forEach(function (_ref) { _this3._index.search(query).forEach(function (_ref) {
var ref = _ref.ref, var ref = _ref.ref,
metadata = _ref.matchData.metadata; metadata = _ref.matchData.metadata;
var matchData = _this2._indexData[ref]; var matchData = _this3._indexData[ref];
var uri = matchData.uri, var uri = matchData.uri,
title = matchData.title, title = matchData.title,
context = matchData.content; context = matchData.content;
@@ -303,13 +312,13 @@ var Theme = /*#__PURE__*/function () {
return Object.values(results).slice(0, maxResultLength); return Object.values(results).slice(0, maxResultLength);
}; };
if (!_this2._index) { if (!_this3._index) {
fetch(searchConfig.lunrIndexURL).then(function (response) { fetch(searchConfig.lunrIndexURL).then(function (response) {
return response.json(); return response.json();
}).then(function (data) { }).then(function (data) {
var indexData = {}; var indexData = {};
_this2._index = lunr(function () { _this3._index = lunr(function () {
var _this3 = this; var _this4 = this;
if (searchConfig.lunrLanguageCode) this.use(lunr[searchConfig.lunrLanguageCode]); if (searchConfig.lunrLanguageCode) this.use(lunr[searchConfig.lunrLanguageCode]);
this.ref('objectID'); this.ref('objectID');
@@ -329,10 +338,10 @@ var Theme = /*#__PURE__*/function () {
data.forEach(function (record) { data.forEach(function (record) {
indexData[record.objectID] = record; indexData[record.objectID] = record;
_this3.add(record); _this4.add(record);
}); });
}); });
_this2._indexData = indexData; _this3._indexData = indexData;
finish(search()); finish(search());
}).catch(function (err) { }).catch(function (err) {
console.error(err); console.error(err);
@@ -340,9 +349,9 @@ var Theme = /*#__PURE__*/function () {
}); });
} else finish(search()); } else finish(search());
} else if (searchConfig.type === 'algolia') { } else if (searchConfig.type === 'algolia') {
_this2._algoliaIndex = _this2._algoliaIndex || algoliasearch(searchConfig.algoliaAppID, searchConfig.algoliaSearchKey).initIndex(searchConfig.algoliaIndex); _this3._algoliaIndex = _this3._algoliaIndex || algoliasearch(searchConfig.algoliaAppID, searchConfig.algoliaSearchKey).initIndex(searchConfig.algoliaIndex);
_this2._algoliaIndex.search(query, { _this3._algoliaIndex.search(query, {
offset: 0, offset: 0,
length: maxResultLength * 8, length: maxResultLength * 8,
attributesToHighlight: ['title'], attributesToHighlight: ['title'],
@@ -406,7 +415,7 @@ var Theme = /*#__PURE__*/function () {
autosearch.on('autocomplete:selected', function (_event, suggestion, _dataset, _context) { autosearch.on('autocomplete:selected', function (_event, suggestion, _dataset, _context) {
window.location.assign(suggestion.uri); window.location.assign(suggestion.uri);
}); });
if (isMobile) _this2._searchMobile = autosearch;else _this2._searchDesktop = autosearch; if (isMobile) _this3._searchMobile = autosearch;else _this3._searchDesktop = autosearch;
}; };
if (searchConfig.lunrSegmentitURL && !document.getElementById('lunr-segmentit')) { if (searchConfig.lunrSegmentitURL && !document.getElementById('lunr-segmentit')) {
@@ -450,7 +459,7 @@ var Theme = /*#__PURE__*/function () {
}, { }, {
key: "initHighlight", key: "initHighlight",
value: function initHighlight() { value: function initHighlight() {
var _this4 = this; var _this5 = this;
this.util.forEach(document.querySelectorAll('.highlight > pre.chroma'), function ($preChroma) { this.util.forEach(document.querySelectorAll('.highlight > pre.chroma'), function ($preChroma) {
var $chroma = document.createElement('div'); var $chroma = document.createElement('div');
@@ -491,14 +500,14 @@ var Theme = /*#__PURE__*/function () {
$copy.insertAdjacentHTML('afterbegin', '<i class="far fa-copy fa-fw"></i>'); $copy.insertAdjacentHTML('afterbegin', '<i class="far fa-copy fa-fw"></i>');
$copy.classList.add('copy'); $copy.classList.add('copy');
var code = $code.innerText; var code = $code.innerText;
if (_this4.config.code.maxShownLines < 0 || code.split('\n').length < _this4.config.code.maxShownLines + 2) $chroma.classList.add('open'); if (_this5.config.code.maxShownLines < 0 || code.split('\n').length < _this5.config.code.maxShownLines + 2) $chroma.classList.add('open');
if (_this4.config.code.copyTitle) { if (_this5.config.code.copyTitle) {
$copy.setAttribute('data-clipboard-text', code); $copy.setAttribute('data-clipboard-text', code);
$copy.title = _this4.config.code.copyTitle; $copy.title = _this5.config.code.copyTitle;
var clipboard = new ClipboardJS($copy); var clipboard = new ClipboardJS($copy);
clipboard.on('success', function (_e) { clipboard.on('success', function (_e) {
_this4.util.animateCSS($code, 'flash'); _this5.util.animateCSS($code, 'flash');
}); });
$header.appendChild($copy); $header.appendChild($copy);
} }
@@ -530,7 +539,7 @@ var Theme = /*#__PURE__*/function () {
}, { }, {
key: "initToc", key: "initToc",
value: function initToc() { value: function initToc() {
var _this5 = this; var _this6 = this;
var $tocCore = document.getElementById('TableOfContents'); var $tocCore = document.getElementById('TableOfContents');
if ($tocCore === null) return; if ($tocCore === null) return;
@@ -572,10 +581,10 @@ var Theme = /*#__PURE__*/function () {
var maxTocTop = footerTop - $toc.getBoundingClientRect().height; var maxTocTop = footerTop - $toc.getBoundingClientRect().height;
var maxScrollTop = maxTocTop - TOP_SPACING + (headerIsFixed ? 0 : headerHeight); var maxScrollTop = maxTocTop - TOP_SPACING + (headerIsFixed ? 0 : headerHeight);
if (_this5.newScrollTop < minScrollTop) { if (_this6.newScrollTop < minScrollTop) {
$toc.style.position = 'absolute'; $toc.style.position = 'absolute';
$toc.style.top = "".concat(minTocTop, "px"); $toc.style.top = "".concat(minTocTop, "px");
} else if (_this5.newScrollTop > maxScrollTop) { } else if (_this6.newScrollTop > maxScrollTop) {
$toc.style.position = 'absolute'; $toc.style.position = 'absolute';
$toc.style.top = "".concat(maxTocTop, "px"); $toc.style.top = "".concat(maxTocTop, "px");
} else { } else {
@@ -583,11 +592,11 @@ var Theme = /*#__PURE__*/function () {
$toc.style.top = "".concat(TOP_SPACING, "px"); $toc.style.top = "".concat(TOP_SPACING, "px");
} }
_this5.util.forEach($tocLinkElements, function ($tocLink) { _this6.util.forEach($tocLinkElements, function ($tocLink) {
$tocLink.classList.remove('active'); $tocLink.classList.remove('active');
}); });
_this5.util.forEach($tocLiElements, function ($tocLi) { _this6.util.forEach($tocLiElements, function ($tocLi) {
$tocLi.classList.remove('has-active'); $tocLi.classList.remove('has-active');
}); });
@@ -628,7 +637,7 @@ var Theme = /*#__PURE__*/function () {
}, { }, {
key: "initMermaid", key: "initMermaid",
value: function initMermaid() { value: function initMermaid() {
var _this6 = this; var _this7 = this;
var $mermaidElements = document.getElementsByClassName('mermaid'); var $mermaidElements = document.getElementsByClassName('mermaid');
@@ -638,7 +647,7 @@ var Theme = /*#__PURE__*/function () {
theme: 'null' theme: 'null'
}); });
this.util.forEach($mermaidElements, function ($mermaid) { this.util.forEach($mermaidElements, function ($mermaid) {
mermaid.mermaidAPI.render('svg-' + $mermaid.id, _this6.data[$mermaid.id], function (svgCode) { mermaid.mermaidAPI.render('svg-' + $mermaid.id, _this7.data[$mermaid.id], function (svgCode) {
$mermaid.insertAdjacentHTML('afterbegin', svgCode); $mermaid.insertAdjacentHTML('afterbegin', svgCode);
}, $mermaid); }, $mermaid);
}); });
@@ -647,24 +656,24 @@ var Theme = /*#__PURE__*/function () {
}, { }, {
key: "initEcharts", key: "initEcharts",
value: function initEcharts() { value: function initEcharts() {
var _this7 = this; var _this8 = this;
this._echartsOnSwitchTheme = this._echartsOnSwitchTheme || function () { this._echartsOnSwitchTheme = this._echartsOnSwitchTheme || function () {
_this7._echartsArr = _this7._echartsArr || []; _this8._echartsArr = _this8._echartsArr || [];
for (var i = 0; i < _this7._echartsArr.length; i++) { for (var i = 0; i < _this8._echartsArr.length; i++) {
_this7._echartsArr[i].dispose(); _this8._echartsArr[i].dispose();
} }
_this7._echartsArr = []; _this8._echartsArr = [];
_this7.util.forEach(document.getElementsByClassName('echarts'), function ($echarts) { _this8.util.forEach(document.getElementsByClassName('echarts'), function ($echarts) {
var chart = echarts.init($echarts, _this7.isDark ? 'dark' : 'macarons', { var chart = echarts.init($echarts, _this8.isDark ? 'dark' : 'macarons', {
renderer: 'svg' renderer: 'svg'
}); });
chart.setOption(JSON.parse(_this7.data[$echarts.id])); chart.setOption(JSON.parse(_this8.data[$echarts.id]));
_this7._echartsArr.push(chart); _this8._echartsArr.push(chart);
}); });
}; };
@@ -673,8 +682,8 @@ var Theme = /*#__PURE__*/function () {
this._echartsOnSwitchTheme(); this._echartsOnSwitchTheme();
this._echartsOnResize = this._echartsOnResize || function () { this._echartsOnResize = this._echartsOnResize || function () {
for (var i = 0; i < _this7._echartsArr.length; i++) { for (var i = 0; i < _this8._echartsArr.length; i++) {
_this7._echartsArr[i].resize(); _this8._echartsArr[i].resize();
} }
}; };
@@ -683,30 +692,30 @@ var Theme = /*#__PURE__*/function () {
}, { }, {
key: "initMapbox", key: "initMapbox",
value: function initMapbox() { value: function initMapbox() {
var _this8 = this; var _this9 = this;
if (this.config.mapbox) { if (this.config.mapbox) {
mapboxgl.accessToken = this.config.mapbox.accessToken; mapboxgl.accessToken = this.config.mapbox.accessToken;
mapboxgl.setRTLTextPlugin(this.config.mapbox.RTLTextPlugin); mapboxgl.setRTLTextPlugin(this.config.mapbox.RTLTextPlugin);
this._mapboxArr = this._mapboxArr || []; this._mapboxArr = this._mapboxArr || [];
this.util.forEach(document.getElementsByClassName('mapbox'), function ($mapbox) { this.util.forEach(document.getElementsByClassName('mapbox'), function ($mapbox) {
var _this8$data$$mapbox$i = _this8.data[$mapbox.id], var _this9$data$$mapbox$i = _this9.data[$mapbox.id],
lng = _this8$data$$mapbox$i.lng, lng = _this9$data$$mapbox$i.lng,
lat = _this8$data$$mapbox$i.lat, lat = _this9$data$$mapbox$i.lat,
zoom = _this8$data$$mapbox$i.zoom, zoom = _this9$data$$mapbox$i.zoom,
lightStyle = _this8$data$$mapbox$i.lightStyle, lightStyle = _this9$data$$mapbox$i.lightStyle,
darkStyle = _this8$data$$mapbox$i.darkStyle, darkStyle = _this9$data$$mapbox$i.darkStyle,
marked = _this8$data$$mapbox$i.marked, marked = _this9$data$$mapbox$i.marked,
navigation = _this8$data$$mapbox$i.navigation, navigation = _this9$data$$mapbox$i.navigation,
geolocate = _this8$data$$mapbox$i.geolocate, geolocate = _this9$data$$mapbox$i.geolocate,
scale = _this8$data$$mapbox$i.scale, scale = _this9$data$$mapbox$i.scale,
fullscreen = _this8$data$$mapbox$i.fullscreen; fullscreen = _this9$data$$mapbox$i.fullscreen;
var mapbox = new mapboxgl.Map({ var mapbox = new mapboxgl.Map({
container: $mapbox, container: $mapbox,
center: [lng, lat], center: [lng, lat],
zoom: zoom, zoom: zoom,
minZoom: .2, minZoom: .2,
style: _this8.isDark ? darkStyle : lightStyle, style: _this9.isDark ? darkStyle : lightStyle,
attributionControl: false attributionControl: false
}); });
@@ -738,16 +747,16 @@ var Theme = /*#__PURE__*/function () {
mapbox.addControl(new MapboxLanguage()); mapbox.addControl(new MapboxLanguage());
_this8._mapboxArr.push(mapbox); _this9._mapboxArr.push(mapbox);
}); });
this._mapboxOnSwitchTheme = this._mapboxOnSwitchTheme || function () { this._mapboxOnSwitchTheme = this._mapboxOnSwitchTheme || function () {
_this8.util.forEach(_this8._mapboxArr, function (mapbox) { _this9.util.forEach(_this9._mapboxArr, function (mapbox) {
var $mapbox = mapbox.getContainer(); var $mapbox = mapbox.getContainer();
var _this8$data$$mapbox$i2 = _this8.data[$mapbox.id], var _this9$data$$mapbox$i2 = _this9.data[$mapbox.id],
lightStyle = _this8$data$$mapbox$i2.lightStyle, lightStyle = _this9$data$$mapbox$i2.lightStyle,
darkStyle = _this8$data$$mapbox$i2.darkStyle; darkStyle = _this9$data$$mapbox$i2.darkStyle;
mapbox.setStyle(_this8.isDark ? darkStyle : lightStyle); mapbox.setStyle(_this9.isDark ? darkStyle : lightStyle);
mapbox.addControl(new MapboxLanguage()); mapbox.addControl(new MapboxLanguage());
}); });
}; };
@@ -758,7 +767,7 @@ var Theme = /*#__PURE__*/function () {
}, { }, {
key: "initTypeit", key: "initTypeit",
value: function initTypeit() { value: function initTypeit() {
var _this9 = this; var _this10 = this;
if (this.config.typeit) { if (this.config.typeit) {
var typeitConfig = this.config.typeit; var typeitConfig = this.config.typeit;
@@ -769,7 +778,7 @@ var Theme = /*#__PURE__*/function () {
var typeone = function typeone(i) { var typeone = function typeone(i) {
var id = group[i]; var id = group[i];
var instance = new TypeIt("#".concat(id), { var instance = new TypeIt("#".concat(id), {
strings: _this9.data[id], strings: _this10.data[id],
speed: speed, speed: speed,
lifeLike: true, lifeLike: true,
cursorSpeed: cursorSpeed, cursorSpeed: cursorSpeed,
@@ -796,7 +805,7 @@ var Theme = /*#__PURE__*/function () {
}, { }, {
key: "initComment", key: "initComment",
value: function initComment() { value: function initComment() {
var _this10 = this; var _this11 = this;
if (this.config.comment) { if (this.config.comment) {
if (this.config.comment.gitalk) { if (this.config.comment.gitalk) {
@@ -823,7 +832,7 @@ var Theme = /*#__PURE__*/function () {
this._utterancesOnSwitchTheme = this._utterancesOnSwitchTheme || function () { this._utterancesOnSwitchTheme = this._utterancesOnSwitchTheme || function () {
var message = { var message = {
type: 'set-theme', type: 'set-theme',
theme: _this10.isDark ? utterancesConfig.darkTheme : utterancesConfig.lightTheme theme: _this11.isDark ? utterancesConfig.darkTheme : utterancesConfig.lightTheme
}; };
var iframe = document.querySelector('.utterances-frame'); var iframe = document.querySelector('.utterances-frame');
iframe.contentWindow.postMessage(message, 'https://utteranc.es'); iframe.contentWindow.postMessage(message, 'https://utteranc.es');
@@ -851,7 +860,7 @@ var Theme = /*#__PURE__*/function () {
}, { }, {
key: "onScroll", key: "onScroll",
value: function onScroll() { value: function onScroll() {
var _this11 = this; var _this12 = this;
var $headers = []; var $headers = [];
if (document.body.getAttribute('data-header-desktop') === 'auto') $headers.push(document.getElementById('header-desktop')); if (document.body.getAttribute('data-header-desktop') === 'auto') $headers.push(document.getElementById('header-desktop'));
@@ -867,45 +876,45 @@ var Theme = /*#__PURE__*/function () {
var ACCURACY = 20, var ACCURACY = 20,
MINIMUM = 100; MINIMUM = 100;
window.addEventListener('scroll', function () { window.addEventListener('scroll', function () {
_this11.newScrollTop = _this11.util.getScrollTop(); _this12.newScrollTop = _this12.util.getScrollTop();
var scroll = _this11.newScrollTop - _this11.oldScrollTop; var scroll = _this12.newScrollTop - _this12.oldScrollTop;
var isMobile = _this11.util.isMobile(); var isMobile = _this12.util.isMobile();
_this11.util.forEach($headers, function ($header) { _this12.util.forEach($headers, function ($header) {
if (scroll > ACCURACY) { if (scroll > ACCURACY) {
$header.classList.remove('fadeInDown'); $header.classList.remove('fadeInDown');
_this11.util.animateCSS($header, ['fadeOutUp', 'faster'], true); _this12.util.animateCSS($header, ['fadeOutUp', 'faster'], true);
} else if (scroll < -ACCURACY) { } else if (scroll < -ACCURACY) {
$header.classList.remove('fadeOutUp'); $header.classList.remove('fadeOutUp');
_this11.util.animateCSS($header, ['fadeInDown', 'faster'], true); _this12.util.animateCSS($header, ['fadeInDown', 'faster'], true);
} }
}); });
if (_this11.newScrollTop > MINIMUM) { if (_this12.newScrollTop > MINIMUM) {
if (isMobile && scroll > ACCURACY) { if (isMobile && scroll > ACCURACY) {
$fixedButtons.classList.remove('fadeIn'); $fixedButtons.classList.remove('fadeIn');
_this11.util.animateCSS($fixedButtons, ['fadeOut', 'faster'], true); _this12.util.animateCSS($fixedButtons, ['fadeOut', 'faster'], true);
} else if (!isMobile || scroll < -ACCURACY) { } else if (!isMobile || scroll < -ACCURACY) {
$fixedButtons.style.display = 'block'; $fixedButtons.style.display = 'block';
$fixedButtons.classList.remove('fadeOut'); $fixedButtons.classList.remove('fadeOut');
_this11.util.animateCSS($fixedButtons, ['fadeIn', 'faster'], true); _this12.util.animateCSS($fixedButtons, ['fadeIn', 'faster'], true);
} }
} else { } else {
if (!isMobile) { if (!isMobile) {
$fixedButtons.classList.remove('fadeIn'); $fixedButtons.classList.remove('fadeIn');
_this11.util.animateCSS($fixedButtons, ['fadeOut', 'faster'], true); _this12.util.animateCSS($fixedButtons, ['fadeOut', 'faster'], true);
} }
$fixedButtons.style.display = 'none'; $fixedButtons.style.display = 'none';
} }
var _iterator2 = _createForOfIteratorHelper(_this11.scrollEventSet), var _iterator2 = _createForOfIteratorHelper(_this12.scrollEventSet),
_step2; _step2;
try { try {
@@ -919,20 +928,20 @@ var Theme = /*#__PURE__*/function () {
_iterator2.f(); _iterator2.f();
} }
_this11.oldScrollTop = _this11.newScrollTop; _this12.oldScrollTop = _this12.newScrollTop;
}, false); }, false);
} }
}, { }, {
key: "onResize", key: "onResize",
value: function onResize() { value: function onResize() {
var _this12 = this; var _this13 = this;
window.addEventListener('resize', function () { window.addEventListener('resize', function () {
if (!_this12._resizeTimeout) { if (!_this13._resizeTimeout) {
_this12._resizeTimeout = window.setTimeout(function () { _this13._resizeTimeout = window.setTimeout(function () {
_this12._resizeTimeout = null; _this13._resizeTimeout = null;
var _iterator3 = _createForOfIteratorHelper(_this12.resizeEventSet), var _iterator3 = _createForOfIteratorHelper(_this13.resizeEventSet),
_step3; _step3;
try { try {
@@ -946,11 +955,11 @@ var Theme = /*#__PURE__*/function () {
_iterator3.f(); _iterator3.f();
} }
_this12.initToc(); _this13.initToc();
_this12.initMermaid(); _this13.initMermaid();
_this12.initSearch(); _this13.initSearch();
}, 100); }, 100);
} }
}, false); }, false);
@@ -958,10 +967,10 @@ var Theme = /*#__PURE__*/function () {
}, { }, {
key: "onClickMask", key: "onClickMask",
value: function onClickMask() { value: function onClickMask() {
var _this13 = this; var _this14 = this;
document.getElementById('mask').addEventListener('click', function () { document.getElementById('mask').addEventListener('click', function () {
var _iterator4 = _createForOfIteratorHelper(_this13.clickMaskEventSet), var _iterator4 = _createForOfIteratorHelper(_this14.clickMaskEventSet),
_step4; _step4;
try { try {
@@ -981,9 +990,10 @@ var Theme = /*#__PURE__*/function () {
}, { }, {
key: "init", key: "init",
value: function init() { value: function init() {
var _this14 = this; var _this15 = this;
try { try {
this.initRaw();
this.initSVGIcon(); this.initSVGIcon();
this.initTwemoji(); this.initTwemoji();
this.initMenuMobile(); this.initMenuMobile();
@@ -1006,15 +1016,15 @@ var Theme = /*#__PURE__*/function () {
} }
window.setTimeout(function () { window.setTimeout(function () {
_this14.initToc(); _this15.initToc();
_this14.initComment(); _this15.initComment();
_this14.onScroll(); _this15.onScroll();
_this14.onResize(); _this15.onResize();
_this14.onClickMask(); _this15.onClickMask();
}, 100); }, 100);
} }
}]); }]);

View File

@@ -267,6 +267,31 @@ therefore, additional escape character expressions are required for these places
* `\[` -> `\\[` * `\[` -> `\\[`
* `\]` -> `\\]` * `\]` -> `\\]`
* `\\` -> `\\\\` * `\\` -> `\\\\`
**LoveIt** theme supports `raw` shortcode to avoid these escape characters,
which helps you write raw mathematical formula content.
Example `raw` input:
```markdown
Inline Formula: {{</* raw */>}}\(\mathbf{E}=\sum_{i} \mathbf{E}_{i}=\mathbf{E}_{1}+\mathbf{E}_{2}+\mathbf{E}_{3}+\cdots\){{</* /raw */>}}
Block Formula:
{{</* raw */>}}
\[ a=b+c \\ d+e=f \]
{{</* /raw */>}}
```
The rendered output looks like this:
Inline Formula: {{< raw >}}\(\mathbf{E}=\sum_{i} \mathbf{E}_{i}=\mathbf{E}_{1}+\mathbf{E}_{2}+\mathbf{E}_{3}+\cdots\){{< /raw >}}
Block Formula:
{{< raw>}}
\[ a=b+c \\ d+e=f \]
{{< /raw >}}
{{< /admonition >}} {{< /admonition >}}
#### Inline Formula #### Inline Formula

View File

@@ -265,6 +265,31 @@ resources:
* `\[` -> `\\[` * `\[` -> `\\[`
* `\]` -> `\\]` * `\]` -> `\\]`
* `\\` -> `\\\\` * `\\` -> `\\\\`
**LoveIt** 主题支持 `raw` shortcode 以避免这些转义字符,
它可以帮助您编写原始数学公式内容.
一个 `raw` 示例:
```markdown
行内公式: {{</* raw */>}}\(\mathbf{E}=\sum_{i} \mathbf{E}_{i}=\mathbf{E}_{1}+\mathbf{E}_{2}+\mathbf{E}_{3}+\cdots\){{</* /raw */>}}
公式块:
{{</* raw */>}}
\[ a=b+c \\ d+e=f \]
{{</* /raw */>}}
```
呈现的输出效果如下:
行内公式: {{< raw >}}\(\mathbf{E}=\sum_{i} \mathbf{E}_{i}=\mathbf{E}_{1}+\mathbf{E}_{2}+\mathbf{E}_{3}+\cdots\){{< /raw >}}
公式块:
{{< raw>}}
\[ a=b+c \\ d+e=f \]
{{< /raw >}}
{{< /admonition >}} {{< /admonition >}}
#### 行内公式 #### 行内公式

View File

@@ -1 +1,2 @@
{{- .Inner | safeHTML -}} {{- $id := dict "Content" .Inner "Scratch" .Page.Scratch | partial "function/id.html" -}}
<data id="{{ $id }}" data-raw></data>

View File

@@ -43,6 +43,12 @@ class Theme {
if (window.objectFitImages) objectFitImages(); if (window.objectFitImages) objectFitImages();
} }
initRaw() {
this.util.forEach(document.querySelectorAll('[data-raw]'), $raw => {
$raw.innerHTML = this.data[$raw.id];
});
}
initSVGIcon() { initSVGIcon() {
this.util.forEach(document.querySelectorAll('[data-svg-src]'), $icon => { this.util.forEach(document.querySelectorAll('[data-svg-src]'), $icon => {
fetch($icon.getAttribute('data-svg-src')) fetch($icon.getAttribute('data-svg-src'))
@@ -703,6 +709,7 @@ class Theme {
init() { init() {
try { try {
this.initRaw();
this.initSVGIcon(); this.initSVGIcon();
this.initTwemoji(); this.initTwemoji();
this.initMenuMobile(); this.initMenuMobile();