-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
410 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,26 @@ | ||
export default formatSolution; | ||
|
||
export function formatSolution(sourceStr: string): Promise<string>; | ||
export type Config = { | ||
clang?: { | ||
enabled?: boolean; | ||
config?: string; | ||
}; | ||
}; | ||
/** | ||
* @typedef {{ | ||
* clang?: { | ||
* enabled?: boolean, | ||
* config?: string | ||
* } | ||
* }} Config | ||
*/ | ||
/** | ||
* @param {string} sourceStr | ||
* @param {Config} config | ||
*/ | ||
export function formatSolution(sourceStr: string, config?: Config): Promise<string>; | ||
/** | ||
* clang-format is not supported. | ||
* | ||
* @param {string} sourceStr | ||
*/ | ||
export function formatSolutionSync(sourceStr: string): string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
declare module "@wasm-fmt/clang-format/clang-format-vite.js" { | ||
export * from "@wasm-fmt/clang-format"; | ||
} | ||
|
||
/** | ||
* @param {string} config | ||
*/ | ||
export default function remarkClangFmtWasm( | ||
config?: string | ||
): (tree: Root) => Promise<void>; | ||
export type Root = import("mdast").Root; | ||
export type RootContent = import("mdast").RootContent; | ||
export type VFile = import("vfile").VFile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @typedef {import('mdast').Root} Root | ||
* @typedef {import('mdast').RootContent} RootContent | ||
* @typedef {import('vfile').VFile} VFile | ||
*/ | ||
|
||
|
||
// @ts-ignore | ||
import init, { format } from "@wasm-fmt/clang-format/clang-format-vite.js"; | ||
import { visit } from "unist-util-visit"; | ||
|
||
/** | ||
* @param {string} config | ||
*/ | ||
export default function remarkClangFmtWasm(config = "WebKit") { | ||
/** | ||
* The plugin. | ||
* | ||
* @param {Root} tree | ||
* Tree. | ||
* @returns | ||
* Nothing. | ||
*/ | ||
return async (tree) => { | ||
await init(); | ||
|
||
visit(tree, "code", (node) => { | ||
if (node.lang === "cpp" || node.lang === "c++") { | ||
node.value = format(node.value, "main.cc", config); | ||
} else if (node.lang === "c") { | ||
node.value = format(node.value, "main.c", config); | ||
} | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "@imkdown/remark-clang-fmt-wasm", | ||
"private": true, | ||
"version": "1.0.0", | ||
"type": "module", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"exports": { | ||
"default": "./index.js" | ||
}, | ||
"types": "index.d.ts", | ||
"dependencies": { | ||
"@wasm-fmt/clang-format": "^18.1.8", | ||
"unist-util-visit": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/mdast": "^4.0.3", | ||
"vfile": "^6.0.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": ["index.js"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<script lang="ts" setup> | ||
import { storeToRefs } from "pinia"; | ||
import { useStore } from "../store"; | ||
import { ref, watch } from "vue"; | ||
const store = useStore(); | ||
const { clangEnabled, clangConfig } = storeToRefs(store); | ||
const model = ref<HTMLDialogElement | null>(null); | ||
const props = defineProps({ open: Number }); | ||
watch(props, () => { | ||
if (props.open) model.value?.showModal(); | ||
}); | ||
const clear = () => localStorage.removeItem("state"); | ||
</script> | ||
|
||
<template> | ||
<dialog ref="model" id="configModel" class="modal"> | ||
<div class="modal-box"> | ||
<h3 class="text-lg font-bold">选项设置</h3> | ||
<div class="form-control"> | ||
<div class="pb-5"> | ||
<label class="label cursor-pointer"> | ||
<span class="label-text">启用 clang-format (实验性)</span> | ||
<input type="checkbox" class="toggle" v-model="clangEnabled" /> | ||
</label> | ||
|
||
<label class="label cursor-pointer" v-if="clangEnabled"> | ||
<span class="label-text"> | ||
clang-format 设置 | ||
<a | ||
href="https://clang.llvm.org/docs/ClangFormatStyleOptions.html" | ||
class="link link-primary" | ||
>帮助</a> | ||
</span> | ||
</label> | ||
<textarea | ||
v-if="clangEnabled" | ||
v-model="clangConfig" | ||
class="textarea textarea-bordered w-full border min-h-40 font-['Fira_Code']" | ||
></textarea> | ||
</div> | ||
|
||
<button class="btn btn-sm" v-on:click="() => (clear(), store.$reset())"> | ||
重置本地数据 | ||
</button> | ||
</div> | ||
|
||
<div class="modal-action"> | ||
<form method="dialog"> | ||
<button class="btn">关闭</button> | ||
</form> | ||
</div> | ||
</div> | ||
</dialog> | ||
</template> |
Oops, something went wrong.