Skip to content

Commit

Permalink
xor docs raw (no prettier)
Browse files Browse the repository at this point in the history
  • Loading branch information
edemaine committed Nov 12, 2023
1 parent aebdd20 commit 701507c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
3 changes: 2 additions & 1 deletion civet.dev/.vitepress/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ export default async function vitePressConfig() {

if (token.content.startsWith('<Playground')) {
const lines = token.content.trim().split('\n');
const raw = /\braw\b/.test(lines[0]);
const code = lines.slice(1, -1).join('\n');
const { tsCode } = compileCivet(code, civet, prettier);
const { tsCode } = compileCivet(code, civet, raw ? null : prettier);
const inputHtml = highlighter.codeToHtml(code, { lang: 'coffee' });
const outputHtml = highlighter.codeToHtml(tsCode, { lang: 'tsx' });

Expand Down
22 changes: 12 additions & 10 deletions civet.dev/.vitepress/utils/compileCivet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ export function compileCivet(
let tsCode = civetInstance.compile(code);
const tsRawCode = tsCode;

try {
tsCode = prettierInstance.format(tsCode, {
parser: 'typescript',
printWidth: 50,
});
} catch (err) {
console.info('Prettier error. Fallback to raw civet output', {
tsCode,
err,
});
if (prettierInstance) {
try {
tsCode = prettierInstance.format(tsCode, {
parser: 'typescript',
printWidth: 50,
});
} catch (err) {
console.info('Prettier error. Fallback to raw civet output', {
tsCode,
err,
});
}
}

return { tsCode, tsRawCode };
Expand Down
4 changes: 2 additions & 2 deletions civet.dev/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,14 @@ a not instanceof "number"
### Logical XOR Operator
<Playground>
<Playground raw>
a ^^ b
a xor b
a ^^= b
a xor= b
</Playground>
<Playground>
<Playground raw>
a !^ b
a xnor b
a !^= b
Expand Down

0 comments on commit 701507c

Please sign in to comment.