Skip to content

Commit

Permalink
fix: copy pragma true by default (#228)
Browse files Browse the repository at this point in the history
Push
  • Loading branch information
PuruVJ committed Sep 16, 2023
1 parent e3facf3 commit bc5adba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/curly-stingrays-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/site-kit': patch
---

chore: copy true by default
4 changes: 2 additions & 2 deletions packages/site-kit/src/lib/docs/DocsCopyCodeButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
grid-template-columns: 1fr;
grid-template-rows: 1fr;
opacity: 0.8;
opacity: 0.5;
height: 2.4rem;
width: 2.4rem;
Expand All @@ -80,7 +80,7 @@
}
button:hover {
opacity: 1;
opacity: 0.7;
}
span {
Expand Down
8 changes: 6 additions & 2 deletions packages/site-kit/src/lib/markdown/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export async function render_content_markdown(
if (cached_snippet.code) return cached_snippet.code;

/** @type {SnippetOptions} */
const options = { file: null, link: null, copy: false };
const options = { file: null, link: null, copy: true };

source = collect_options(source, options);
source = adjust_tab_indentation(source, language);
Expand Down Expand Up @@ -880,13 +880,17 @@ function create_type_links(modules, resolve_link) {
function collect_options(source, options) {
METADATA_REGEX.lastIndex = 0;

let copy_value = 'true';
source = source.replace(METADATA_REGEX, (_, key, value) => {
if (key === 'copy') {
copy_value = value;
}
options[/** @type {MetadataKeys} */ (key)] = value;
return '';
});

options.link = options.link === 'true';
options.copy = options.copy === 'true' || (options.file && options.copy !== 'false');
options.copy = copy_value === 'true' || (options.file && copy_value !== 'false');

return source;
}
Expand Down

0 comments on commit bc5adba

Please sign in to comment.