Skip to content

Commit

Permalink
refactor: extract extractCodeBlockHeader func
Browse files Browse the repository at this point in the history
  • Loading branch information
ignace committed Jan 6, 2024
1 parent 8998ad6 commit 2b53d84
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions addon/initializers/shikiji.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,7 @@ function stripQuotes(string) {
return string;
}

function transformCodeBlock(
wholeMatch,
delim,
languageBlock,
inputCodeblock,
highlighter,
options,
globals
) {
const end = options.omitExtraWLInCodeBlocks ? '' : '\n';
const codeblock = showdown.subParser('detab')(
inputCodeblock,
options,
globals
);
function extractCodeBlockHeader(languageBlock) {
let match = languageBlock.match(/(\w+) ?(\{([^}]*)\})?/);
let language = '';
let attributeString = '';
Expand All @@ -54,6 +40,29 @@ function transformCodeBlock(
attributes[keyValue[0]] = stripQuotes(keyValue[1]);
});

return {
language,
attributes,
};
}

function transformCodeBlock(
wholeMatch,
_delim,
languageBlock,
inputCodeblock,
highlighter,
options,
globals
) {
const end = options.omitExtraWLInCodeBlocks ? '' : '\n';
const codeblock = showdown.subParser('detab')(
inputCodeblock,
options,
globals
);
const { language, attributes } = extractCodeBlockHeader(languageBlock);

const highlightedCodeBlock = highlighter.codeToHtml(codeblock, {
lang: language,
theme: 'github-dark',
Expand Down

0 comments on commit 2b53d84

Please sign in to comment.