Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 0 additions & 115 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 0 additions & 16 deletions website/app/controllers/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ export default class ShowController extends Controller {
let tabs = [];
let tocs = [];

this.applyCodeHighlighting();

// check if the content is split in sections (and we need tabs) or is all together
const documentSections = document.querySelectorAll(
`.doc-page-content section[data-tab]`,
Expand Down Expand Up @@ -209,20 +207,6 @@ export default class ShowController extends Controller {
// console.log('show didInsert', this.sections, this.tabs, this.tocs);
};

applyCodeHighlighting() {
const codeBlocks = document.querySelectorAll(
'.doc-code-block__code-snippet',
);
if (
codeBlocks.length > 0 &&
typeof window?.Prism?.highlightAllUnder === 'function'
) {
codeBlocks.forEach((codeBlock) => {
window.Prism.highlightAllUnder(codeBlock);
});
}
}

@action
onClickTab(tab) {
// console.log('show onClickTab', tab);
Expand Down
128 changes: 0 additions & 128 deletions website/app/initializers/showdown-extensions.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
/* global Prism */

import showdown from 'showdown';

const uniqueId = () => {
return ([3e7] + -1e3 + -4e3 + -2e3 + -1e11).replace(/[0-3]/g, (a) =>
((a * 4) ^ ((Math.random() * 16) >> (a & 2))).toString(16),
);
};

export function initialize(/* application */) {
// Overriding `unhashHTMLSpans` subparser to overcome the 10 levels of nesting limit
showdown.subParser('unhashHTMLSpans', function (text, options, globals) {
Expand Down Expand Up @@ -45,126 +37,6 @@ export function initialize(/* application */) {
);
return text;
});

showdown.subParser('githubCodeBlocks', function (text, options, globals) {
'use strict';

// early exit if option is not enabled
if (!options.ghCodeBlocks) {
return text;
}

text = globals.converter._dispatch(
'githubCodeBlocks.before',
text,
options,
globals,
);

text += '¨0';

text = text.replace(
/(?:^|\n)(?: {0,3})(```+|~~~+)(?: *)([^\s`~]*)\n([\s\S]*?)\n(?: {0,3})\1/g,
function (wholeMatch, delim, languageBlock, inputCodeblock) {
var end = options.omitExtraWLInCodeBlocks ? '' : '\n';

let codeblock = inputCodeblock;

// We encode the codeblock so we can safely pass multi-line code and ember syntax to the `Doc::CopyButton` component
let codeblockEncoded = encodeURI(inputCodeblock);

// First parse the github code block
// codeblock = showdown.subParser('encodeCode')(codeblock, options, globals);
codeblock = showdown.subParser('detab')(codeblock, options, globals);
codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines
codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing whitespace

let match = languageBlock.match(/(\w+)({(.*)})?/);
let language = '';
let attributeString = '';
let encodedCodeBlock = '';

if (match && match[1]) {
language = match[1];
// languageString = ' class="' + match[1] + ' language-' + match[1] + '"';
}

if (match && match[3]) {
attributeString = match[3];
}

if (!language) {
// set the default to shell
language = 'shell';
}

// we encode the codeblock and present it as is (without highlight)
encodedCodeBlock = Prism.util.encode(codeblock) + end;

// escape { and } for the code sample
encodedCodeBlock = encodedCodeBlock
.replace(/{/g, '{')
.replace(/}/g, '}');

let blockUniqueId = uniqueId();
let preBlock = `<pre id="pre-block-${blockUniqueId}" class="doc-code-block__code-snippet language-${language}" tabindex="0"><code ${language ? `class="${language} language-${language}"` : ''}>${encodedCodeBlock}</code></pre>`;

let autoExecuteLanguages = ['html', 'handlebars', 'hbs'];

let selfExecutingBlock = '';
selfExecutingBlock +=
'<div class="doc-code-block doc-code-block--self-executing">';
selfExecutingBlock += ` <div class="doc-code-block__code-rendered">`;
selfExecutingBlock += ` ${inputCodeblock}`;
selfExecutingBlock += ' </div>';
selfExecutingBlock +=
' <div class="doc-code-block__code-snippet-wrapper">';
selfExecutingBlock += ` <Doc::CopyButton @type="solid" @textToCopy='${codeblockEncoded}' @encoded={{true}} @isIconOnly={{true}} />`;
selfExecutingBlock += ` ${preBlock}`;
selfExecutingBlock += ' </div>';
selfExecutingBlock += '</div>';

if (attributeString.includes('data-execute=false')) {
codeblock = preBlock;
} else if (attributeString.includes('data-execute=true')) {
codeblock = selfExecutingBlock;
} else if (autoExecuteLanguages.includes(language)) {
codeblock = selfExecutingBlock;
} else {
codeblock = preBlock;
}

codeblock = showdown.subParser('hashBlock')(
codeblock,
options,
globals,
);

// Since GHCodeblocks can be false positives, we need to
// store the primitive text and the parsed text in a global var,
// and then return a token
return (
'\n\n¨G' +
(globals.ghCodeBlocks.push({
text: wholeMatch,
codeblock: codeblock,
}) -
1) +
'G\n\n'
);
},
);

// attacklab: strip sentinel
text = text.replace(/¨0/, '');

return globals.converter._dispatch(
'githubCodeBlocks.after',
text,
options,
globals,
);
});
}

export default {
Expand Down
2 changes: 1 addition & 1 deletion website/app/shared/showdown-extensions/content-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const contentBlocks = function () {
text = text.replace(langRegex, function (_match, type, content) {
// we use the PHP tag as passthrough "tag" because is simply ignored by the `hashHTMLBlocks` function in Showdown
// see: https://github.com/showdownjs/showdown/blob/master/src/subParsers/makehtml/hashHTMLBlocks.js#L93-L95
return `\n<?php start="content-block" type="${type.toLowerCase()}" ?>\n${content}\n<?php end="content-block" type="${type.toLowerCase()}" ?>\n`;
return `\n<?php start="content-block" type="${type.toLowerCase()}" ?>\n\n${content}\n\n<?php end="content-block" type="${type.toLowerCase()}" ?>\n`;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is to fix an edge case I noticed that broke recently. It only broke on the dodont testing page

this do don't testing example that only contained an inline code snippet was treated as a full code block

Screenshot 2026-04-02 at 2 28 11 PM

but this doesn't work when I removed ember prism

Screenshot 2026-04-02 at 2 27 32 PM

when the code snippet had other text, it never broke. here is an example:
Screenshot 2026-04-02 at 2 29 29 PM

Now, with this the normal inline code snippets still work + when the do/dont only includes an inline code snippet it works.

Screenshot 2026-04-02 at 2 30 35 PM

});

// console.log('langExtension2 text', '\n', text, '\n\n');
Expand Down
Loading
Loading