Skip to content

Commit

Permalink
Merge pull request #63 from webdevnerdstuff/fix/issue-60
Browse files Browse the repository at this point in the history
Fix/issue 60
  • Loading branch information
webdevnerdstuff authored Dec 12, 2024
2 parents dde88d8 + f1c5f36 commit 8d54097
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 124 deletions.
13 changes: 13 additions & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"git": {
"commitMessage": "chore: release ${version}",
"tagName": "v${version}"
},
"npm": {
"publish": true
},
"github": {
"release": true,
"releaseName": "v${version}"
}
}
14 changes: 7 additions & 7 deletions dist/vue-code-block.cjs.js

Large diffs are not rendered by default.

149 changes: 78 additions & 71 deletions dist/vue-code-block.es.js

Large diffs are not rendered by default.

41 changes: 27 additions & 14 deletions src/plugin/VCodeBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,13 @@
:class="`language-${settings.lang}`"
:style="preTagStyles"
>
<code
v-if="prismPlugin"
:class="`language-${settings.lang} ${settings.browserWindow ? 'v-code-block--code-browser' : ''} ${settings.highlightjs ? 'hljs' : ''}`"
:style="codeTagStyles"
v-text="computedCode"
></code>
<code
v-else
:class="`language-${settings.lang} ${settings.browserWindow ? 'v-code-block--code-browser' : ''} ${settings.highlightjs ? 'hljs' : ''}`"
:style="codeTagStyles"
v-html="renderedCode"
></code>
</pre>
<code v-if="prismPlugin"
:class="`language-${settings.lang} ${settings.browserWindow ? 'v-code-block--code-browser' : ''} ${settings.highlightjs ? 'hljs' : ''}`"
:style="codeTagStyles" v-text="computedCode"></code>
<code v-else
:class="`language-${settings.lang} ${settings.browserWindow ? 'v-code-block--code-browser' : ''} ${settings.highlightjs ? 'hljs' : ''}`"
:style="codeTagStyles" v-html="renderedCode"></code>
</pre>
</div>
</div>
</template>
Expand Down Expand Up @@ -332,10 +326,29 @@ function checkLibrary(): void {
}
}
function isValidJSON(str: string): boolean {
try {
JSON.parse(str);
return true;
}
catch (e) {
return false;
}
}
function convertCode(): void {
if (settings.value.lang === 'json') {
const propsCode = settings.value.code.toString();
convertedCode.value = JSON.stringify(JSON.parse(propsCode), null, settings.value.indent);
// Check if the code is valid JSON //
if (isValidJSON(propsCode)) {
convertedCode.value = JSON.stringify(JSON.parse(propsCode), null, settings.value.indent);
return;
}
// Change lang to text if not valid JSON to prevent errors //
settings.value.lang = 'text';
convertedCode.value = propsCode;
return;
}
Expand Down
32 changes: 0 additions & 32 deletions src/plugin/__tests__/__snapshots__/VCodeBlock.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,37 +1,5 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`VCodeBlock Component > Component > should ... 1`] = `
{
"browserWindow": false,
"code": "",
"codeBlockRadius": "0.5rem",
"copyButton": true,
"copyFailedText": "Copy failed!",
"copyIcons": true,
"copySuccessText": "Copied!",
"copyTab": true,
"copyText": "Copy Code",
"cssPath": undefined,
"floatingTabs": true,
"globalOptions": false,
"height": "auto",
"highlightjs": true,
"indent": 2,
"label": "",
"lang": "javascript",
"languages": undefined,
"maxHeight": "auto",
"persistentCopyButton": false,
"prismPlugin": false,
"prismjs": false,
"runTab": false,
"runText": "Run",
"tabGap": "0.25rem",
"tabs": false,
"theme": "neon-bunny",
}
`;

exports[`VCodeBlock Component > Component > should mount the component 1`] = `
{
"browserWindow": false,
Expand Down

0 comments on commit 8d54097

Please sign in to comment.