2018-04-04 10:39:21 +00:00
|
|
|
<template>
|
2019-09-28 12:45:07 +00:00
|
|
|
<div class="markdown" v-html="marked(text)" />
|
2018-04-04 10:39:21 +00:00
|
|
|
</template>
|
|
|
|
<script>
|
2019-01-12 03:33:27 +00:00
|
|
|
import marked from 'marked';
|
|
|
|
import { isZhCN } from '../util';
|
|
|
|
const renderer = new marked.Renderer();
|
2019-09-28 12:45:07 +00:00
|
|
|
renderer.heading = function(text, level) {
|
|
|
|
return (
|
|
|
|
'<h' + level + ' id="' + text.replace(/[^\w]+/g, '-') + '">' + text + '</h' + level + '>\n'
|
|
|
|
);
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-04-04 10:39:21 +00:00
|
|
|
marked.setOptions({
|
2018-04-07 09:38:39 +00:00
|
|
|
renderer,
|
2018-04-04 10:39:21 +00:00
|
|
|
gfm: true,
|
|
|
|
tables: true,
|
|
|
|
breaks: true,
|
|
|
|
pedantic: true,
|
|
|
|
sanitize: true,
|
|
|
|
smartLists: true,
|
|
|
|
smartypants: true,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-04-04 10:39:21 +00:00
|
|
|
export default {
|
2019-02-01 09:23:00 +00:00
|
|
|
name: 'Md',
|
2018-04-04 10:39:21 +00:00
|
|
|
props: {
|
|
|
|
cn: String,
|
|
|
|
us: String,
|
|
|
|
},
|
2018-07-13 13:55:29 +00:00
|
|
|
inject: {
|
2019-09-28 12:45:07 +00:00
|
|
|
demoContext: { default: {} },
|
2018-07-13 13:55:29 +00:00
|
|
|
},
|
2019-09-28 12:45:07 +00:00
|
|
|
data() {
|
2019-01-12 03:33:27 +00:00
|
|
|
let text = '';
|
|
|
|
const { cn, us } = this;
|
2018-04-04 10:39:21 +00:00
|
|
|
if (this.$slots.default && this.$slots.default[0] && this.$slots.default[0].text) {
|
2019-01-12 03:33:27 +00:00
|
|
|
text = this.$slots.default[0].text;
|
2018-04-04 10:39:21 +00:00
|
|
|
} else {
|
2019-01-12 03:33:27 +00:00
|
|
|
text = isZhCN(this.demoContext.name) ? cn : us;
|
2018-04-04 10:39:21 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
text = text || '';
|
2019-09-28 12:45:07 +00:00
|
|
|
text = text
|
|
|
|
.split('\n')
|
|
|
|
.map(t => t.trim())
|
|
|
|
.join('\n');
|
2018-04-04 10:39:21 +00:00
|
|
|
return {
|
|
|
|
marked,
|
|
|
|
text,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-04-04 10:39:21 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-04-04 10:39:21 +00:00
|
|
|
</script>
|