Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

Commit 66a4aff

Browse files
authored
fix: renderer indent code snippets by 2 spaces only (#225)
* Push * Exclude yaml from adjust_tab_indentation * Remove comment * Use tabs
1 parent ad15034 commit 66a4aff

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

.changeset/fifty-insects-sing.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/site-kit': patch
3+
---
4+
5+
fix: renderer indent code snippets by 2 spaces only

packages/site-kit/src/lib/docs/DocsOnThisPage.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@
257257
/* override global styles */
258258
margin: 0;
259259
border: none;
260+
padding: 0 0.85rem;
260261
}
261262
262263
.h2 {
@@ -374,6 +375,10 @@
374375
border-radius: var(--sk-border-radius) var(--sk-border-radius) 0 0;
375376
}
376377
378+
h2 {
379+
padding: unset;
380+
}
381+
377382
.h2 {
378383
font-size: var(--sk-text-s);
379384
line-height: 1;

packages/site-kit/src/lib/markdown/renderer.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import { SHIKI_LANGUAGE_MAP, escape, normalizeSlugify, transform } from './utils
1111
* @typedef {'file' | 'link' | 'copy'} MetadataKeys
1212
*/
1313

14+
// Supports js, svelte, yaml files
1415
const METADATA_REGEX =
15-
/(?:<!---\s*|\/\/\/\s*)(?<key>file|link|copy):\s*(?<value>.*?)(?:\s*--->|$)\n/gm;
16+
/(?:<!---\s*|\/\/\/\s*|###\s*)(?<key>file|link|copy):\s*(?<value>.*?)(?:\s*--->|$)\n/gm;
1617

1718
/** @type {Map<string, string>} */
1819
const CACHE_MAP = new Map();
@@ -899,13 +900,15 @@ function adjust_tab_indentation(source, language) {
899900
source
900901
// TODO: what exactly is going on here? The regex finds spaces and replaces them with spaces again?
901902
.replace(/^([\-\+])?((?: )+)/gm, (match, prefix = '', spaces) => {
902-
if (prefix && language !== 'diff') return match;
903+
if ((prefix && language !== 'diff') || language === 'yaml') return match;
903904

904905
// for no good reason at all, marked replaces tabs with spaces
906+
let i = 0;
905907
let tabs = '';
906-
for (let i = 0; i < spaces.length; i += 4) {
907-
tabs += ' ';
908+
for (; i < spaces.length; i += 4) {
909+
tabs += '\t';
908910
}
911+
tabs += ' '.repeat(i % 4);
909912
return prefix + tabs;
910913
})
911914
.replace(/\*\\\//g, '*/')
@@ -931,7 +934,7 @@ function replace_blank_lines(html) {
931934
function syntax_highlight({ source, filename, language, highlighter, twoslashBanner, options }) {
932935
let html = '';
933936

934-
if (/^(dts|yaml)/.test(language)) {
937+
if (/^(dts|yaml|yml)/.test(language)) {
935938
html = replace_blank_lines(
936939
twoslash_module.renderCodeToHTML(
937940
source,

0 commit comments

Comments
 (0)