You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/site/components/md.vue

52 lines
1.0 KiB

7 years ago
<template>
<div class="markdown" v-html="marked(text)" />
7 years ago
</template>
<script>
import marked from 'marked';
import { isZhCN } from '../util';
const renderer = new marked.Renderer();
renderer.heading = function(text, level) {
return (
'<h' + level + ' id="' + text.replace(/[^\w]+/g, '-') + '">' + text + '</h' + level + '>\n'
);
};
7 years ago
marked.setOptions({
7 years ago
renderer,
7 years ago
gfm: true,
tables: true,
breaks: true,
pedantic: true,
sanitize: true,
smartLists: true,
smartypants: true,
});
7 years ago
export default {
name: 'Md',
7 years ago
props: {
cn: String,
us: String,
},
inject: {
demoContext: { default: {} },
},
data() {
let text = '';
const { cn, us } = this;
7 years ago
if (this.$slots.default && this.$slots.default[0] && this.$slots.default[0].text) {
text = this.$slots.default[0].text;
7 years ago
} else {
text = isZhCN(this.demoContext.name) ? cn : us;
7 years ago
}
text = text || '';
text = text
.split('\n')
.map(t => t.trim())
.join('\n');
7 years ago
return {
marked,
text,
};
7 years ago
},
};
7 years ago
</script>