Skip to content

Commit 4a8251c

Browse files
committed
Adds support for using MediaWiki-style links and code blocks within script descriptions.
Adds support for using MediaWiki-style links and code blocks within script descriptions
1 parent 8a4e4e0 commit 4a8251c

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

web/src/components/CodeExamplesSection.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
import { Code } from '@astrojs/starlight/components';
3-
import { marked } from 'marked';
43
import NeedsExample from '@src/components/NeedsExample.astro';
4+
import EnhancedMarkdown from '@src/components/EnhancedMarkdown.astro'
55
66
export interface CodeExample {
77
description?: string;
@@ -57,7 +57,7 @@ if (codeExamples.length === 0 && !examplesRequired) {
5757
<strong>{example.side}</strong> {example.exampleTitle && ` - ${example.exampleTitle}`}
5858
</div>
5959
<div class="tab-body">
60-
{example.description && <Fragment set:html={marked(example.description)} />}
60+
{example.description && <EnhancedMarkdown content={example.description} />}
6161
<div class="code-example">
6262
<Code code={example.luaCode} lang="lua" />
6363
</div>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
import { Code } from '@astrojs/starlight/components';
3+
import { marked } from 'marked';
4+
5+
interface Props {
6+
content: string;
7+
}
8+
9+
const { content } = Astro.props;
10+
11+
function convertMediaWikiLinks(text: string): string {
12+
return text.replace(
13+
/\[\[([^|\]#]+)(?:#([^\]]+))?(?:\|([^\]]+))?\]\]/g,
14+
(_, link, hash, text) => {
15+
const url = `/${link}${hash ? `#${hash}` : ''}`;
16+
return `[${text || link}](${url})`;
17+
}
18+
);
19+
}
20+
21+
const processedContent = convertMediaWikiLinks(content);
22+
const tokens = marked.lexer(processedContent);
23+
---
24+
25+
{
26+
tokens.map((token) => {
27+
if (token.type === 'code') {
28+
return <Code code={token.text} lang={token.lang || 'text'} />;
29+
}
30+
return <Fragment set:html={marked.parser([token])} />;
31+
})
32+
}

0 commit comments

Comments
 (0)