1
This commit is contained in:
@@ -53,6 +53,7 @@
|
||||
"js-beautify": "1.10.2",
|
||||
"js-cookie": "2.2.0",
|
||||
"jsencrypt": "3.0.0-rc.1",
|
||||
"minhtml": "^1.1.1",
|
||||
"normalize.css": "7.0.0",
|
||||
"nprogress": "0.2.0",
|
||||
"path-to-regexp": "2.4.0",
|
||||
|
||||
2273
ebts-ui/public/format.js
Normal file
2273
ebts-ui/public/format.js
Normal file
File diff suppressed because one or more lines are too long
@@ -8,14 +8,14 @@ module.exports = {
|
||||
/**
|
||||
* 单点登录url
|
||||
*/
|
||||
// casloginUrl: 'https://cas.swjtu.edu.cn/authserver/login?service=http://192.168.190.67/dev-api/cas-login',
|
||||
casloginUrl: 'https://cas.swjtu.edu.cn/authserver/login?service=http://sist.swjtu.edu.cn/dev-api/cas-login',
|
||||
casloginUrl: 'https://cas.swjtu.edu.cn/authserver/login?service=http://192.168.190.67/dev-api/cas-login',
|
||||
// casloginUrl: 'https://cas.swjtu.edu.cn/authserver/login?service=http://sist.swjtu.edu.cn/dev-api/cas-login',
|
||||
|
||||
/**
|
||||
* 单点登出url
|
||||
*/
|
||||
// caslogoutUrl: 'https://cas.swjtu.edu.cn/authserver/logout?service=http://192.168.190.67/admin/logout',
|
||||
caslogoutUrl: 'https://cas.swjtu.edu.cn/authserver/logout?service=http://sist.swjtu.edu.cn/admin/logout',
|
||||
caslogoutUrl: 'https://cas.swjtu.edu.cn/authserver/logout?service=http://192.168.190.67/admin/logout',
|
||||
// caslogoutUrl: 'https://cas.swjtu.edu.cn/authserver/logout?service=http://sist.swjtu.edu.cn/admin/logout',
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,6 +9,18 @@
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="文章描述" prop="description">
|
||||
<el-input v-model="formData.description"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
placeholder="请输入内容"
|
||||
clearable :style="{width: '100%'}">
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="是否新闻" prop="isTop">
|
||||
@@ -143,7 +155,7 @@
|
||||
</template>
|
||||
<script>
|
||||
// import ArticleFile from './ArticleFile'
|
||||
import Editor from '@/components/Editor';
|
||||
import Editor from '@/views/utils/Editor'
|
||||
import {updateArticle, getArticle, drafts, getArticleType, getArticleApprove} from "@/api/sist/article";
|
||||
import {Message} from "element-ui";
|
||||
import UploadFile from '@/views/utils/uploadFile.vue';
|
||||
|
||||
@@ -285,22 +285,22 @@
|
||||
<el-input v-model="formEdit.configKey" disabled placeholder="请输入参数键名" />
|
||||
</el-form-item>
|
||||
<el-form-item label="职工人数">
|
||||
<el-input-number :min="0" type="number" v-model="statisticConfig.worker" placeholder="请输入参数键值" />
|
||||
<el-input v-model="statisticConfig.worker" placeholder="请输入参数键值" />
|
||||
</el-form-item>
|
||||
<el-form-item label="在校生人数">
|
||||
<el-input-number :min="0" type="number" v-model="statisticConfig.students" placeholder="请输入参数键值" />
|
||||
<el-input v-model="statisticConfig.students" placeholder="请输入参数键值" />
|
||||
</el-form-item>
|
||||
<el-form-item label="研究生导师">
|
||||
<el-input-number :min="0" type="number" v-model="statisticConfig.postgraduateTutor" placeholder="请输入参数键值" />
|
||||
<el-input v-model="statisticConfig.postgraduateTutor" placeholder="请输入参数键值" />
|
||||
</el-form-item>
|
||||
<el-form-item label="科研团队">
|
||||
<el-input-number :min="0" type="number" v-model="statisticConfig.scientificTeam" placeholder="请输入参数键值" />
|
||||
<el-input v-model="statisticConfig.scientificTeam" placeholder="请输入参数键值" />
|
||||
</el-form-item>
|
||||
<el-form-item label="高层次人才">
|
||||
<el-input-number :min="0" type="number" v-model="statisticConfig.highLevelTalents" placeholder="请输入参数键值" />
|
||||
<el-input v-model="statisticConfig.highLevelTalents" placeholder="请输入参数键值" />
|
||||
</el-form-item>
|
||||
<el-form-item label="重大项目">
|
||||
<el-input-number :min="0" type="number" v-model="statisticConfig.majorProjects" placeholder="请输入参数键值" />
|
||||
<el-input v-model="statisticConfig.majorProjects" placeholder="请输入参数键值" />
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="formEdit.remark" type="textarea" placeholder="请输入内容" />
|
||||
|
||||
@@ -1,11 +1,31 @@
|
||||
<template>
|
||||
<div class="editor" :style="styles" ref="editor"></div>
|
||||
<div>
|
||||
<div class="editor" :style="styles" ref="editor"></div>
|
||||
<!-- <div class="code">-->
|
||||
<!-- <el-button @click="openCode">源码</el-button>-->
|
||||
<!-- </div>-->
|
||||
|
||||
|
||||
<el-dialog title="编辑详情" :visible="codeShow" width="1100px" :close-on-click-modal="false" @close="codeShow = false"
|
||||
append-to-body>
|
||||
<textarea
|
||||
class="textarea"
|
||||
rows="50"
|
||||
cols="50"
|
||||
|
||||
v-model="code"></textarea>
|
||||
|
||||
<el-button @click="codeSuccess">完成</el-button>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Editor from 'wangeditor'
|
||||
import { htmlFormat } from './fromat'
|
||||
|
||||
export default {
|
||||
name: "Editor",
|
||||
name: 'Editor',
|
||||
props: {
|
||||
/* 编辑器的内容 */
|
||||
value: {
|
||||
@@ -15,12 +35,12 @@ export default {
|
||||
/* 高度 */
|
||||
height: {
|
||||
type: Number,
|
||||
default: null,
|
||||
default: null
|
||||
},
|
||||
/* 最小高度 */
|
||||
minHeight: {
|
||||
type: Number,
|
||||
default: null,
|
||||
default: null
|
||||
},
|
||||
meanArray: {
|
||||
// 自定义菜单
|
||||
@@ -35,27 +55,28 @@ export default {
|
||||
|
||||
computed: {
|
||||
styles() {
|
||||
let style = {};
|
||||
let style = {}
|
||||
if (this.minHeight) {
|
||||
style.minHeight = `${this.minHeight}px`;
|
||||
style.minHeight = `${this.minHeight}px`
|
||||
}
|
||||
if (this.height) {
|
||||
style.height = `${this.height+50}px`;
|
||||
style.height = `${this.height + 50}px`
|
||||
}
|
||||
return style;
|
||||
},
|
||||
return style
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
value: function (value) {
|
||||
value: function(value) {
|
||||
if (value !== this.editor.txt.html()) {
|
||||
this.editor.txt.html(this.value)
|
||||
}
|
||||
}
|
||||
// value为编辑框输入的内容,这里我监听了一下值,当父组件调用得时候,如果给value赋值了,子组件将会显示父组件赋给的值
|
||||
},
|
||||
data () {
|
||||
data() {
|
||||
return {
|
||||
|
||||
code: null,
|
||||
codeShow: false,
|
||||
// 默认有这么多菜单,meanArray有值以meanArray为准
|
||||
defaultMeanus: [
|
||||
'head',
|
||||
@@ -86,7 +107,43 @@ export default {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
init () {
|
||||
|
||||
|
||||
|
||||
pack(s){
|
||||
s = s.replace(/\/\*(.|\n)*?\*\//g, "");
|
||||
s = s.replace(/\s*([\{\}\:\;\,])\s*/g, "$1");
|
||||
s = s.replace(/\,[\s\.\#\d]*\{/g, "{");
|
||||
s = s.replace(/;\s*;/g, ";");
|
||||
s = s.replace(/;\s*}/g, "}");
|
||||
s = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
|
||||
return (s == null) ? "" : s[1];
|
||||
},
|
||||
|
||||
openCode() {
|
||||
this.code = null
|
||||
this.code = htmlFormat(this.value)
|
||||
// this.code = this.value.replace(/</g, "<").replace(/>/g, ">").replace(/ /g, " ")
|
||||
// console.log(this.code,"this.code)")
|
||||
// let text = this.editor.txt.text().replace(/</ig, "<").replace(/>/ig, ">").replace(/ /ig, " ")
|
||||
// console.log(text,"text")
|
||||
this.codeShow = true
|
||||
},
|
||||
codeSuccess(){
|
||||
console.log(this.code)
|
||||
|
||||
|
||||
|
||||
// let packer = new Packer;
|
||||
// let output = packer.pack(this.value, 0, 0);
|
||||
// console.log(output, "output")
|
||||
// let output= packageFormat(this.code)
|
||||
// this.setHtml(output)
|
||||
// this.editor.dangerouslyInsertHtml(this.code)
|
||||
this.code = null
|
||||
this.codeShow = false
|
||||
},
|
||||
init() {
|
||||
const _this = this
|
||||
this.editor = new Editor(this.$refs.editor)
|
||||
this.editor.config.uploadImgAccept = ['doc', 'docx', 'png', 'gif', 'bmp', 'webp']
|
||||
@@ -100,7 +157,7 @@ export default {
|
||||
}
|
||||
this.editor.create() // 创建编辑器
|
||||
},
|
||||
setMenus () {
|
||||
setMenus() {
|
||||
// 设置菜单
|
||||
if (this.meanArray) {
|
||||
this.editor.config.menus = this.meanArray
|
||||
@@ -108,18 +165,20 @@ export default {
|
||||
this.editor.config.menus = this.defaultMeanus
|
||||
}
|
||||
},
|
||||
getHtml () {
|
||||
getHtml() {
|
||||
// 得到文本内容
|
||||
return this.editor.txt.html()
|
||||
},
|
||||
setHtml (txt) {
|
||||
setHtml(txt) {
|
||||
// 设置富文本里面的值
|
||||
this.editor.txt.html(txt)
|
||||
// this.editor.txt.html(txt)
|
||||
this.editor.txt.text(txt)
|
||||
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
mounted() {
|
||||
const that = this
|
||||
that.$nextTick(function () {
|
||||
that.$nextTick(function() {
|
||||
that.init()
|
||||
})
|
||||
}
|
||||
@@ -128,10 +187,19 @@ export default {
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
.editor{
|
||||
z-index: 1!important;
|
||||
white-space: pre-wrap!important;
|
||||
.editor {
|
||||
z-index: 1 !important;
|
||||
white-space: pre-wrap !important;
|
||||
line-height: normal !important;
|
||||
}
|
||||
|
||||
.code {
|
||||
margin-top: 3rem;
|
||||
|
||||
}
|
||||
.textarea{
|
||||
width: 1036px;
|
||||
height: 750px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
398
ebts-ui/src/views/utils/fromat.js
Normal file
398
ebts-ui/src/views/utils/fromat.js
Normal file
@@ -0,0 +1,398 @@
|
||||
var HTMLFormat = (function() {
|
||||
function style_html(html_source, indent_size, indent_character, max_char) {
|
||||
var Parser, multi_parser
|
||||
|
||||
function Parser() {
|
||||
|
||||
this.pos = 0
|
||||
this.token = ''
|
||||
this.current_mode = 'CONTENT'
|
||||
this.tags = {
|
||||
parent: 'parent1',
|
||||
parentcount: 1,
|
||||
parent1: ''
|
||||
}
|
||||
this.tag_type = ''
|
||||
this.token_text = this.last_token = this.last_text = this.token_type = ''
|
||||
|
||||
this.Utils = {
|
||||
whitespace: '\n\r\t '.split(''),
|
||||
single_token: 'br,input,link,meta,!doctype,basefont,base,area,hr,wbr,param,img,isindex,?xml,embed'.split(','),
|
||||
extra_liners: 'head,body,/html'.split(','),
|
||||
in_array: function(what, arr) {
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
if (what === arr[i]) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
this.get_content = function() {
|
||||
var char = ''
|
||||
var content = []
|
||||
var space = false
|
||||
while (this.input.charAt(this.pos) !== '<') {
|
||||
if (this.pos >= this.input.length) {
|
||||
return content.length ? content.join('') : ['', 'TK_EOF']
|
||||
}
|
||||
|
||||
char = this.input.charAt(this.pos)
|
||||
this.pos++
|
||||
this.line_char_count++
|
||||
|
||||
if (this.Utils.in_array(char, this.Utils.whitespace)) {
|
||||
if (content.length) {
|
||||
space = true
|
||||
}
|
||||
this.line_char_count--
|
||||
continue
|
||||
} else if (space) {
|
||||
if (this.line_char_count >= this.max_char) {
|
||||
content.push('\n')
|
||||
for (var i = 0; i < this.indent_level; i++) {
|
||||
content.push(this.indent_string)
|
||||
}
|
||||
this.line_char_count = 0
|
||||
} else {
|
||||
content.push(' ')
|
||||
this.line_char_count++
|
||||
}
|
||||
space = false
|
||||
}
|
||||
content.push(char)
|
||||
}
|
||||
return content.length ? content.join('') : ''
|
||||
}
|
||||
|
||||
this.get_script = function() {
|
||||
var char = ''
|
||||
var content = []
|
||||
var reg_match = new RegExp('\<\/script' + '\>', 'igm')
|
||||
reg_match.lastIndex = this.pos
|
||||
var reg_array = reg_match.exec(this.input)
|
||||
var end_script = reg_array ? reg_array.index : this.input.length
|
||||
while (this.pos < end_script) {
|
||||
if (this.pos >= this.input.length) {
|
||||
return content.length ? content.join('') : ['', 'TK_EOF']
|
||||
}
|
||||
|
||||
char = this.input.charAt(this.pos)
|
||||
this.pos++
|
||||
|
||||
content.push(char)
|
||||
}
|
||||
return content.length ? content.join('') : ''
|
||||
}
|
||||
|
||||
this.record_tag = function(tag) {
|
||||
if (this.tags[tag + 'count']) {
|
||||
this.tags[tag + 'count']++
|
||||
this.tags[tag + this.tags[tag + 'count']] = this.indent_level
|
||||
} else {
|
||||
this.tags[tag + 'count'] = 1
|
||||
this.tags[tag + this.tags[tag + 'count']] = this.indent_level
|
||||
}
|
||||
this.tags[tag + this.tags[tag + 'count'] + 'parent'] = this.tags.parent
|
||||
this.tags.parent = tag + this.tags[tag + 'count']
|
||||
}
|
||||
|
||||
this.retrieve_tag = function(tag) {
|
||||
if (this.tags[tag + 'count']) {
|
||||
var temp_parent = this.tags.parent
|
||||
while (temp_parent) {
|
||||
if (tag + this.tags[tag + 'count'] === temp_parent) {
|
||||
break
|
||||
}
|
||||
temp_parent = this.tags[temp_parent + 'parent']
|
||||
}
|
||||
if (temp_parent) {
|
||||
this.indent_level = this.tags[tag + this.tags[tag + 'count']]
|
||||
this.tags.parent = this.tags[temp_parent + 'parent']
|
||||
}
|
||||
delete this.tags[tag + this.tags[tag + 'count'] + 'parent']
|
||||
delete this.tags[tag + this.tags[tag + 'count']]
|
||||
if (this.tags[tag + 'count'] == 1) {
|
||||
delete this.tags[tag + 'count']
|
||||
} else {
|
||||
this.tags[tag + 'count']--
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.get_tag = function() {
|
||||
var char = ''
|
||||
var content = []
|
||||
var space = false
|
||||
|
||||
do {
|
||||
if (this.pos >= this.input.length) {
|
||||
return content.length ? content.join('') : ['', 'TK_EOF']
|
||||
}
|
||||
|
||||
char = this.input.charAt(this.pos)
|
||||
this.pos++
|
||||
this.line_char_count++
|
||||
|
||||
if (this.Utils.in_array(char, this.Utils.whitespace)) {
|
||||
space = true
|
||||
this.line_char_count--
|
||||
continue
|
||||
}
|
||||
|
||||
if (char === '\'' || char === '"') {
|
||||
if (!content[1] || content[1] !== '!') {
|
||||
char += this.get_unformatted(char)
|
||||
space = true
|
||||
}
|
||||
}
|
||||
|
||||
if (char === '=') {
|
||||
space = false
|
||||
}
|
||||
|
||||
if (content.length && content[content.length - 1] !== '=' && char !== '>' && space) {
|
||||
if (this.line_char_count >= this.max_char) {
|
||||
this.print_newline(false, content)
|
||||
this.line_char_count = 0
|
||||
} else {
|
||||
content.push(' ')
|
||||
this.line_char_count++
|
||||
}
|
||||
space = false
|
||||
}
|
||||
content.push(char)
|
||||
} while (char !== '>')
|
||||
|
||||
var tag_complete = content.join('')
|
||||
var tag_index
|
||||
if (tag_complete.indexOf(' ') != -1) {
|
||||
tag_index = tag_complete.indexOf(' ')
|
||||
} else {
|
||||
tag_index = tag_complete.indexOf('>')
|
||||
}
|
||||
var tag_check = tag_complete.substring(1, tag_index).toLowerCase()
|
||||
if (tag_complete.charAt(tag_complete.length - 2) === '/' || this.Utils.in_array(tag_check, this.Utils.single_token)) {
|
||||
this.tag_type = 'SINGLE'
|
||||
} else if (tag_check === 'script') {
|
||||
this.record_tag(tag_check)
|
||||
this.tag_type = 'SCRIPT'
|
||||
} else if (tag_check === 'style') {
|
||||
this.record_tag(tag_check)
|
||||
this.tag_type = 'STYLE'
|
||||
} else if (tag_check.charAt(0) === '!') {
|
||||
if (tag_check.indexOf('[if') != -1) {
|
||||
if (tag_complete.indexOf('!IE') != -1) {
|
||||
var comment = this.get_unformatted('-->', tag_complete)
|
||||
content.push(comment)
|
||||
}
|
||||
this.tag_type = 'START'
|
||||
} else if (tag_check.indexOf('[endif') != -1) {
|
||||
this.tag_type = 'END'
|
||||
this.unindent()
|
||||
} else if (tag_check.indexOf('[cdata[') != -1) {
|
||||
var comment = this.get_unformatted(']]>', tag_complete)
|
||||
content.push(comment)
|
||||
this.tag_type = 'SINGLE'
|
||||
} else {
|
||||
var comment = this.get_unformatted('-->', tag_complete)
|
||||
content.push(comment)
|
||||
this.tag_type = 'SINGLE'
|
||||
}
|
||||
} else {
|
||||
if (tag_check.charAt(0) === '/') {
|
||||
this.retrieve_tag(tag_check.substring(1))
|
||||
this.tag_type = 'END'
|
||||
} else {
|
||||
this.record_tag(tag_check)
|
||||
this.tag_type = 'START'
|
||||
}
|
||||
if (this.Utils.in_array(tag_check, this.Utils.extra_liners)) {
|
||||
this.print_newline(true, this.output)
|
||||
}
|
||||
}
|
||||
return content.join('')
|
||||
}
|
||||
|
||||
this.get_unformatted = function(delimiter, orig_tag) {
|
||||
if (orig_tag && orig_tag.indexOf(delimiter) != -1) {
|
||||
return ''
|
||||
}
|
||||
var char = ''
|
||||
var content = ''
|
||||
var space = true
|
||||
do {
|
||||
|
||||
char = this.input.charAt(this.pos)
|
||||
this.pos++
|
||||
|
||||
if (this.Utils.in_array(char, this.Utils.whitespace)) {
|
||||
if (!space) {
|
||||
this.line_char_count--
|
||||
continue
|
||||
}
|
||||
if (char === '\n' || char === '\r') {
|
||||
content += '\n'
|
||||
for (var i = 0; i < this.indent_level; i++) {
|
||||
content += this.indent_string
|
||||
}
|
||||
space = false
|
||||
this.line_char_count = 0
|
||||
continue
|
||||
}
|
||||
}
|
||||
content += char
|
||||
this.line_char_count++
|
||||
space = true
|
||||
|
||||
} while (content.indexOf(delimiter) == -1)
|
||||
return content
|
||||
}
|
||||
|
||||
this.get_token = function() {
|
||||
var token
|
||||
|
||||
if (this.last_token === 'TK_TAG_SCRIPT') {
|
||||
var temp_token = this.get_script()
|
||||
if (typeof temp_token !== 'string') {
|
||||
return temp_token
|
||||
}
|
||||
//token = js_beautify(temp_token, this.indent_size, this.indent_character, this.indent_level);
|
||||
//return [token, 'TK_CONTENT'];
|
||||
return [temp_token, 'TK_CONTENT']
|
||||
}
|
||||
if (this.current_mode === 'CONTENT') {
|
||||
token = this.get_content()
|
||||
if (typeof token !== 'string') {
|
||||
return token
|
||||
} else {
|
||||
return [token, 'TK_CONTENT']
|
||||
}
|
||||
}
|
||||
|
||||
if (this.current_mode === 'TAG') {
|
||||
token = this.get_tag()
|
||||
if (typeof token !== 'string') {
|
||||
return token
|
||||
} else {
|
||||
var tag_name_type = 'TK_TAG_' + this.tag_type
|
||||
return [token, tag_name_type]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.printer = function(js_source, indent_character, indent_size, max_char) {
|
||||
this.input = js_source || ''
|
||||
this.output = []
|
||||
this.indent_character = indent_character || ' '
|
||||
this.indent_string = ''
|
||||
this.indent_size = indent_size || 2
|
||||
this.indent_level = 0
|
||||
this.max_char = max_char || 70
|
||||
this.line_char_count = 0
|
||||
for (var i = 0; i < this.indent_size; i++) {
|
||||
this.indent_string += this.indent_character
|
||||
}
|
||||
|
||||
this.print_newline = function(ignore, arr) {
|
||||
this.line_char_count = 0
|
||||
if (!arr || !arr.length) {
|
||||
return
|
||||
}
|
||||
if (!ignore) {
|
||||
while (this.Utils.in_array(arr[arr.length - 1], this.Utils.whitespace)) {
|
||||
arr.pop()
|
||||
}
|
||||
}
|
||||
arr.push('\n')
|
||||
for (var i = 0; i < this.indent_level; i++) {
|
||||
arr.push(this.indent_string)
|
||||
}
|
||||
}
|
||||
|
||||
this.print_token = function(text) {
|
||||
this.output.push(text)
|
||||
}
|
||||
|
||||
this.indent = function() {
|
||||
this.indent_level++
|
||||
}
|
||||
|
||||
this.unindent = function() {
|
||||
if (this.indent_level > 0) {
|
||||
this.indent_level--
|
||||
}
|
||||
}
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
multi_parser = new Parser()
|
||||
multi_parser.printer(html_source, indent_character, indent_size)
|
||||
while (true) {
|
||||
var t = multi_parser.get_token()
|
||||
multi_parser.token_text = t[0]
|
||||
multi_parser.token_type = t[1]
|
||||
|
||||
if (multi_parser.token_type === 'TK_EOF') {
|
||||
break
|
||||
}
|
||||
|
||||
switch (multi_parser.token_type) {
|
||||
case 'TK_TAG_START':
|
||||
case 'TK_TAG_SCRIPT':
|
||||
case 'TK_TAG_STYLE':
|
||||
multi_parser.print_newline(false, multi_parser.output)
|
||||
multi_parser.print_token(multi_parser.token_text)
|
||||
multi_parser.indent()
|
||||
multi_parser.current_mode = 'CONTENT'
|
||||
break
|
||||
case 'TK_TAG_END':
|
||||
multi_parser.print_newline(true, multi_parser.output)
|
||||
multi_parser.print_token(multi_parser.token_text)
|
||||
multi_parser.current_mode = 'CONTENT'
|
||||
break
|
||||
case 'TK_TAG_SINGLE':
|
||||
multi_parser.print_newline(false, multi_parser.output)
|
||||
multi_parser.print_token(multi_parser.token_text)
|
||||
multi_parser.current_mode = 'CONTENT'
|
||||
break
|
||||
case 'TK_CONTENT':
|
||||
if (multi_parser.token_text !== '') {
|
||||
multi_parser.print_newline(false, multi_parser.output)
|
||||
multi_parser.print_token(multi_parser.token_text)
|
||||
}
|
||||
multi_parser.current_mode = 'TAG'
|
||||
break
|
||||
}
|
||||
multi_parser.last_token = multi_parser.token_type
|
||||
multi_parser.last_text = multi_parser.token_text
|
||||
}
|
||||
return multi_parser.output.join('')
|
||||
}
|
||||
|
||||
return function(data) {
|
||||
var dataHolder = ['__dataHolder_', [Math.random(), Math.random(), Math.random(), Math.random()].join('_').replace(/[^0-9]/g, '_'), '_'].join('_')
|
||||
var dataHolders = {}
|
||||
var index = 0
|
||||
data = data.replace(/(\")(data:[^\"]*)(\")/g, function($0, $1, $2, $3) {
|
||||
var name = dataHolder + index++
|
||||
dataHolders[name] = $2
|
||||
return $1 + name + $3
|
||||
})
|
||||
data = style_html(data, 1, '\t', 0x10000000)
|
||||
data = data.replace(new RegExp(dataHolder + '[0-9]+', 'g'), function($0) {
|
||||
return dataHolders[$0]
|
||||
})
|
||||
|
||||
return data
|
||||
}
|
||||
})()
|
||||
|
||||
export function htmlFormat(str) {
|
||||
return HTMLFormat(str)
|
||||
}
|
||||
|
||||
// 调用方式:
|
||||
var formattedHtml = HTMLFormat('<div><span>xxx</span></div>')
|
||||
Reference in New Issue
Block a user