Skip to content

Commit

Permalink
feat: 基础示例(base-usage)部分的代码格式化 (Tencent#3654)
Browse files Browse the repository at this point in the history
  • Loading branch information
coderYangLiu authored Nov 29, 2023
1 parent b144188 commit 68cae1a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion site/src/components/base-usage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

<script setup lang="jsx">
import { ref, compile, onMounted, computed, onBeforeUnmount, watchEffect } from 'vue';
import * as prettier from 'prettier/standalone';
import * as parserHtml from 'prettier/parser-html';
const stringifyProp = (name, value) => {
if (value === true) return name; // 为 true 只展示 name
Expand Down Expand Up @@ -73,13 +75,21 @@ const defaultProps = ref(
}, {}),
);
function codeFormat(code, options = {}) {
return prettier.format(code, {
parser: 'vue',
...options,
plugins: [parserHtml],
});
}
const usageCode = computed(() => {
const propsStr = Object.keys(changedProps.value)
.map((name) => `${stringifyProp(name, changedProps.value[name])}`)
.filter(Boolean);
const trueCode = props.code.replace(/\s*v-bind="configProps"/g, () =>
propsStr.length ? `\n ${propsStr.join('\n ')}` : '',
);
return trueCode;
return codeFormat(trueCode);
});
</script>

0 comments on commit 68cae1a

Please sign in to comment.