Skip to content

Commit cf5fb77

Browse files
authored
small tidy up (#193)
1 parent a7d0a9d commit cf5fb77

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,11 @@ export async function render_content_markdown(
134134
return parse({
135135
body: await generate_ts_from_js(await replace_export_type_placeholders(body, modules)),
136136
type_links,
137-
code: (source, language, current) => {
138-
const cached_snippet = SNIPPET_CACHE.get(source + language + current);
137+
code: (raw, language, current) => {
138+
const cached_snippet = SNIPPET_CACHE.get(raw + language + current);
139139
if (cached_snippet.code) return cached_snippet.code;
140140

141-
const options: SnippetOptions = { file: null, link: null, copy: true };
142-
143-
source = collect_options(source, options);
141+
let { source, options } = parse_options(raw);
144142
source = adjust_tab_indentation(source, language);
145143

146144
let version_class: 'ts-version' | 'js-version' | '' = '';
@@ -949,9 +947,11 @@ function create_type_links(
949947
return { type_regex, type_links };
950948
}
951949

952-
function collect_options(source: string, options: SnippetOptions) {
950+
function parse_options(source: string) {
953951
METADATA_REGEX.lastIndex = 0;
954952

953+
const options: SnippetOptions = { file: null, link: null, copy: true };
954+
955955
let copy_value = 'true';
956956
source = source.replace(METADATA_REGEX, (_, key, value) => {
957957
if (key === 'copy') {
@@ -964,7 +964,7 @@ function collect_options(source: string, options: SnippetOptions) {
964964
options.link = options.link === 'true';
965965
options.copy = copy_value === 'true' || (options.file && copy_value !== 'false');
966966

967-
return source;
967+
return { source, options };
968968
}
969969

970970
/**

0 commit comments

Comments
 (0)