Skip to content
Merged
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
26 changes: 9 additions & 17 deletions packages/site-kit/src/lib/markdown/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -967,24 +967,16 @@ function collect_options(source: string, options: SnippetOptions) {
return source;
}

/**
* `marked` replaces tabs with four spaces, which is unhelpful.
* This function turns them back into tabs (plus leftover spaces for e.g. `\t * some JSDoc`)
*/
function adjust_tab_indentation(source: string, language: string) {
return (
source
// TODO: what exactly is going on here? The regex finds spaces and replaces them with spaces again?
.replace(/^([\-\+])?((?: )+)/gm, (match, prefix = '', spaces) => {
if ((prefix && language !== 'diff') || language === 'yaml') return match;

// for no good reason at all, marked replaces tabs with spaces
let i = 0;
let tabs = '';
for (; i < spaces.length; i += 4) {
tabs += '\t';
}
tabs += ' '.repeat(i % 4);
return prefix + tabs;
})
.replace(/\*\\\//g, '*/')
);
return source.replace(/^([\-\+])?((?: )+)/gm, (match, prefix = '', spaces) => {
if ((prefix && language !== 'diff') || language === 'yaml') return match;

return prefix + '\t'.repeat(spaces.length / 4) + ' '.repeat(spaces.length % 4);
});
}

function replace_blank_lines(html: string) {
Expand Down
Loading