File tree Expand file tree Collapse file tree 1 file changed +9
-17
lines changed
packages/site-kit/src/lib/markdown Expand file tree Collapse file tree 1 file changed +9
-17
lines changed Original file line number Diff line number Diff line change @@ -967,24 +967,16 @@ function collect_options(source: string, options: SnippetOptions) {
967
967
return source ;
968
968
}
969
969
970
+ /**
971
+ * `marked` replaces tabs with four spaces, which is unhelpful.
972
+ * This function turns them back into tabs (plus leftover spaces for e.g. `\t * some JSDoc`)
973
+ */
970
974
function adjust_tab_indentation ( source : string , language : string ) {
971
- return (
972
- source
973
- // TODO: what exactly is going on here? The regex finds spaces and replaces them with spaces again?
974
- . replace ( / ^ ( [ \- \+ ] ) ? ( (?: ) + ) / gm, ( match , prefix = '' , spaces ) => {
975
- if ( ( prefix && language !== 'diff' ) || language === 'yaml' ) return match ;
976
-
977
- // for no good reason at all, marked replaces tabs with spaces
978
- let i = 0 ;
979
- let tabs = '' ;
980
- for ( ; i < spaces . length ; i += 4 ) {
981
- tabs += '\t' ;
982
- }
983
- tabs += ' ' . repeat ( i % 4 ) ;
984
- return prefix + tabs ;
985
- } )
986
- . replace ( / \* \\ \/ / g, '*/' )
987
- ) ;
975
+ return source . replace ( / ^ ( [ \- \+ ] ) ? ( (?: ) + ) / gm, ( match , prefix = '' , spaces ) => {
976
+ if ( ( prefix && language !== 'diff' ) || language === 'yaml' ) return match ;
977
+
978
+ return prefix + '\t' . repeat ( spaces . length / 4 ) + ' ' . repeat ( spaces . length % 4 ) ;
979
+ } ) ;
988
980
}
989
981
990
982
function replace_blank_lines ( html : string ) {
You can’t perform that action at this time.
0 commit comments