Skip to content

Commit 7f506fd

Browse files
Merge branch 'main' into dev
2 parents 2464577 + b1b7812 commit 7f506fd

File tree

6 files changed

+126
-125
lines changed

6 files changed

+126
-125
lines changed

.release-it.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"git": {
3+
"commitMessage": "chore: release ${version}",
4+
"tagName": "v${version}"
5+
},
6+
"npm": {
7+
"publish": true
8+
},
9+
"github": {
10+
"release": true,
11+
"releaseName": "v${version}"
12+
}
13+
}

dist/vue-code-block.cjs.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vue-code-block.es.js

Lines changed: 78 additions & 71 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wdns/vue-code-block",
3-
"version": "2.3.3",
3+
"version": "2.3.4",
44
"description": "Vue 3 CodeBlock - Highlight your code with ease using this syntax highlighting component powered by PrismJS or Highlight.js.",
55
"private": false,
66
"publishConfig": {

src/plugin/VCodeBlock.vue

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,13 @@
9696
:class="`language-${settings.lang}`"
9797
:style="preTagStyles"
9898
>
99-
<code
100-
v-if="prismPlugin"
101-
:class="`language-${settings.lang} ${settings.browserWindow ? 'v-code-block--code-browser' : ''} ${settings.highlightjs ? 'hljs' : ''}`"
102-
:style="codeTagStyles"
103-
v-text="computedCode"
104-
></code>
105-
<code
106-
v-else
107-
:class="`language-${settings.lang} ${settings.browserWindow ? 'v-code-block--code-browser' : ''} ${settings.highlightjs ? 'hljs' : ''}`"
108-
:style="codeTagStyles"
109-
v-html="renderedCode"
110-
></code>
111-
</pre>
99+
<code v-if="prismPlugin"
100+
:class="`language-${settings.lang} ${settings.browserWindow ? 'v-code-block--code-browser' : ''} ${settings.highlightjs ? 'hljs' : ''}`"
101+
:style="codeTagStyles" v-text="computedCode"></code>
102+
<code v-else
103+
:class="`language-${settings.lang} ${settings.browserWindow ? 'v-code-block--code-browser' : ''} ${settings.highlightjs ? 'hljs' : ''}`"
104+
:style="codeTagStyles" v-html="renderedCode"></code>
105+
</pre>
112106
</div>
113107
</div>
114108
</template>
@@ -332,10 +326,29 @@ function checkLibrary(): void {
332326
}
333327
}
334328
329+
function isValidJSON(str: string): boolean {
330+
try {
331+
JSON.parse(str);
332+
return true;
333+
}
334+
catch (e) {
335+
return false;
336+
}
337+
}
338+
335339
function convertCode(): void {
336340
if (settings.value.lang === 'json') {
337341
const propsCode = settings.value.code.toString();
338-
convertedCode.value = JSON.stringify(JSON.parse(propsCode), null, settings.value.indent);
342+
343+
// Check if the code is valid JSON //
344+
if (isValidJSON(propsCode)) {
345+
convertedCode.value = JSON.stringify(JSON.parse(propsCode), null, settings.value.indent);
346+
return;
347+
}
348+
349+
// Change lang to text if not valid JSON to prevent errors //
350+
settings.value.lang = 'text';
351+
convertedCode.value = propsCode;
339352
return;
340353
}
341354

src/plugin/__tests__/__snapshots__/VCodeBlock.test.ts.snap

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,5 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`VCodeBlock Component > Component > should ... 1`] = `
4-
{
5-
"browserWindow": false,
6-
"code": "",
7-
"codeBlockRadius": "0.5rem",
8-
"copyButton": true,
9-
"copyFailedText": "Copy failed!",
10-
"copyIcons": true,
11-
"copySuccessText": "Copied!",
12-
"copyTab": true,
13-
"copyText": "Copy Code",
14-
"cssPath": undefined,
15-
"floatingTabs": true,
16-
"globalOptions": false,
17-
"height": "auto",
18-
"highlightjs": true,
19-
"indent": 2,
20-
"label": "",
21-
"lang": "javascript",
22-
"languages": undefined,
23-
"maxHeight": "auto",
24-
"persistentCopyButton": false,
25-
"prismPlugin": false,
26-
"prismjs": false,
27-
"runTab": false,
28-
"runText": "Run",
29-
"tabGap": "0.25rem",
30-
"tabs": false,
31-
"theme": "neon-bunny",
32-
}
33-
`;
34-
353
exports[`VCodeBlock Component > Component > should mount the component 1`] = `
364
{
375
"browserWindow": false,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy