ui: select closest sample output (#634)

pull/638/head
panda 1 year ago committed by GitHub
parent 20fe72a708
commit 45c5642db3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,12 +17,13 @@ const highlighterPage = new AutoloadPage('highlighterPage', () => {
$container.find('pre code').get().forEach((code) => { $container.find('pre code').get().forEach((code) => {
const $code = $(code); const $code = $(code);
const $root = $code.parent().parent(); const $root = $code.parent().parent();
const $typo = $code.closest('.typo');
const language = ($(code).attr('class') || '').trim(); const language = ($(code).attr('class') || '').trim();
const m = language.match(/language-input([0-9]+)/); const m = language.match(/language-input([0-9]+)/);
if (m?.[1]) { if (m?.[1]) {
const id = +m[1]; const id = +m[1];
if (Number.isSafeInteger(id)) { if (Number.isSafeInteger(id)) {
const $output = $container.find(`pre.language-output${id}`); const $output = ($typo.length ? $typo : $container).find(`pre.language-output${id}`);
if ($output.length) { if ($output.length) {
const $c = $(document.createElement('div')).addClass('row'); const $c = $(document.createElement('div')).addClass('row');
$root.after($c); $root.after($c);

Loading…
Cancel
Save