File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
src/routes/[pid=pid]/[org]/[repo]/[id=number] Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change 5959 import Step from " $lib/components/Step.svelte" ;
6060 import Steps from " $lib/components/Steps.svelte" ;
6161 import BottomCollapsible from " ./BottomCollapsible.svelte" ;
62- import { transformerDiffMarking , transformerLanguageDetection } from " ./syntax-highlighting" ;
62+ import {
63+ transformerDiffMarking ,
64+ transformerLanguageDetection ,
65+ transformerTrimCode
66+ } from " ./syntax-highlighting" ;
6367
6468 const shikiPlugin: Plugin = {
6569 rehypePlugin: [
6670 rehypeShikiFromHighlighter ,
6771 highlighter ,
6872 {
6973 themes: { light: " github-light-default" , dark: " github-dark-default" },
70- transformers: [transformerLanguageDetection , transformerDiffMarking ]
74+ transformers: [transformerTrimCode , transformerLanguageDetection , transformerDiffMarking ]
7175 } satisfies Parameters <typeof rehypeShikiFromHighlighter >[1 ]
7276 ]
7377 };
Original file line number Diff line number Diff line change @@ -25,6 +25,15 @@ export function detectLanguage(code: string): (SpecialLanguage | (string & {}))
2525 if ( / [ a - z - ] + : \S + / . test ( code ) ) return "css" ;
2626}
2727
28+ /**
29+ * A transformer that trims unnecessary whitespace at the beginning and end of the string.
30+ */
31+ export const transformerTrimCode : ShikiTransformer = {
32+ preprocess ( code ) {
33+ return code . replace ( / ( ^ \r ? \n | \r ? \n $ ) / g, "" ) ;
34+ }
35+ } ;
36+
2837/**
2938 * A Shiki transformer used for language detection and setting the appropriate language metadata
3039 * in code blocks. Useful for handling code snippets with "diff" language and converting them
You can’t perform that action at this time.
0 commit comments