Skip to content

Commit 23c976a

Browse files
fix: separate code spans (sveltejs#577)
Else browsers don't break them up when too many consecuitive `foo`/`bar`/`baz` code spans appear --------- Co-authored-by: Conduitry <[email protected]>
1 parent 7b7ff06 commit 23c976a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ dist
55
pnpm-lock.yaml
66
.vercel
77
_generated.md
8-
land-110m.json
8+
land-110m.json
9+
/apps/svelte.dev/content/docs

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,24 @@ export async function render_content_markdown(
283283
// Save everything locally now
284284
snippets.save(token.text, html);
285285
}
286+
287+
// ensure that `foo`/`bar` is transformed to `foo` / `bar`
288+
// https://github.com/sveltejs/svelte.dev/pull/577
289+
const slash_index =
290+
// @ts-expect-error
291+
token.tokens?.findIndex((token) => token.type === 'text' && token.text === '/') ?? -1;
292+
293+
if (slash_index !== -1) {
294+
// @ts-expect-error
295+
const before = token.tokens[slash_index - 1];
296+
// @ts-expect-error
297+
const after = token.tokens[slash_index + 1];
298+
299+
if (before?.type === 'codespan' && after?.type === 'codespan') {
300+
// @ts-expect-error
301+
token.tokens[slash_index].raw = token.tokens[slash_index].text = ' / ';
302+
}
303+
}
286304
},
287305
text(token) {
288306
// @ts-expect-error I think this is a bug in marked — some text tokens have children,

0 commit comments

Comments
 (0)