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 59
59
import Step from " $lib/components/Step.svelte" ;
60
60
import Steps from " $lib/components/Steps.svelte" ;
61
61
import BottomCollapsible from " ./BottomCollapsible.svelte" ;
62
- import { transformerDiffMarking , transformerLanguageDetection } from " ./syntax-highlighting" ;
62
+ import {
63
+ transformerDiffMarking ,
64
+ transformerLanguageDetection ,
65
+ transformerTrimCode
66
+ } from " ./syntax-highlighting" ;
63
67
64
68
const shikiPlugin: Plugin = {
65
69
rehypePlugin: [
66
70
rehypeShikiFromHighlighter ,
67
71
highlighter ,
68
72
{
69
73
themes: { light: " github-light-default" , dark: " github-dark-default" },
70
- transformers: [transformerLanguageDetection , transformerDiffMarking ]
74
+ transformers: [transformerTrimCode , transformerLanguageDetection , transformerDiffMarking ]
71
75
} satisfies Parameters <typeof rehypeShikiFromHighlighter >[1 ]
72
76
]
73
77
};
Original file line number Diff line number Diff line change @@ -25,6 +25,15 @@ export function detectLanguage(code: string): (SpecialLanguage | (string & {}))
25
25
if ( / [ a - z - ] + : \S + / . test ( code ) ) return "css" ;
26
26
}
27
27
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
+
28
37
/**
29
38
* A Shiki transformer used for language detection and setting the appropriate language metadata
30
39
* 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