chore: update doc template (#2142)

This commit is contained in:
0song 2021-06-03 20:37:31 +08:00 committed by GitHub
parent da622e10d1
commit 0cac0bda38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -77,7 +77,8 @@ const version = '1.0.0' // element version
const stripTemplateAndRemoveTemplate = code => { const stripTemplateAndRemoveTemplate = code => {
const result = removeSetup(stripTemplate(code)) const result = removeSetup(stripTemplate(code))
if (result.indexOf('<template>') === 0) { if (result.indexOf('<template>') === 0) {
return result.replace(/^<template>/, '').replace(/<\/template>$/,'') const html = result.replace(/^<template>/, '').replace(/<\/template>$/,'')
return html.replace(/^[\r?\n|\r]/, '').replace(/[\r?\n|\r]$/, '').trim()
} }
return result return result
} }
@ -196,12 +197,15 @@ export default {
nextTick(() => { nextTick(() => {
const highlight = this.$el.querySelector('.highlight') const highlight = this.$el.querySelector('.highlight')
const hlcode = highlight.querySelector('pre code') const hlcode = highlight.querySelector('pre code')
hlcode.innerHTML = sanitizeHTML(`<template>${this.codepen.html}</template> const innerScript = `<script>
<script>
${this.displayDemoCode} ${this.displayDemoCode}
${'</sc' + 'ript>'} ${'</sc' + 'ript>'}
`) `
hlcode.innerHTML = sanitizeHTML(`<template>
${this.codepen.html}
</template>
${this.displayDemoCode ? innerScript : ''}`)
nextTick(() => { nextTick(() => {
if (this.$el.getElementsByClassName('description').length === 0) { if (this.$el.getElementsByClassName('description').length === 0) {