Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix/issue 60 #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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