decode html entities in text nodes

This commit is contained in:
Evan You 2016-04-12 18:03:45 -04:00
parent 7f7132ee0b
commit e918476447
5 changed files with 28 additions and 19 deletions

View File

@ -3,9 +3,8 @@ var zlib = require('zlib')
var rollup = require('rollup')
var uglify = require('uglify-js')
var babel = require('rollup-plugin-babel')
var node = require('rollup-plugin-node-resolve')
var commonjs = require('rollup-plugin-commonjs')
var replace = require('rollup-plugin-replace')
var alias = require('rollup-plugin-alias')
var version = process.env.VERSION || require('../package.json').version
var banner =
@ -21,16 +20,6 @@ var main = fs
.replace(/Vue\.version = '[\d\.]+'/, "Vue.version = '" + version + "'")
fs.writeFileSync('src/index.js', main)
var plugins = [
node(),
commonjs({
include: 'node_modules/**'
}),
babel({
exclude: 'node_modules/**'
})
]
// CommonJS build.
// this is used as the "main" field in package.json
// and used by bundlers like Webpack and Browserify.
@ -38,7 +27,7 @@ var plugins = [
// used with vue-loader which pre-compiles the template.
rollup.rollup({
entry: 'src/index.js',
plugins: plugins
plugins: [babel()]
})
.then(function (bundle) {
return write('dist/vue.common.js', bundle.generate({
@ -51,10 +40,14 @@ rollup.rollup({
return rollup.rollup({
entry: 'src/with-compiler.js',
plugins: [
alias({
entities: './entity-decoder'
}),
replace({
'process.env.NODE_ENV': "'development'"
})
].concat(plugins)
}),
babel()
]
})
.then(function (bundle) {
return write('dist/vue.js', bundle.generate({
@ -69,10 +62,14 @@ rollup.rollup({
return rollup.rollup({
entry: 'src/with-compiler.js',
plugins: [
alias({
entities: './entity-decoder'
}),
replace({
'process.env.NODE_ENV': "'production'"
})
].concat(plugins)
}),
babel()
]
})
.then(function (bundle) {
var code = bundle.generate({

View File

@ -28,9 +28,8 @@
"babel-preset-es2015-rollup": "^1.1.1",
"babel-preset-stage-2": "^6.0.0",
"rollup": "^0.25.8",
"rollup-plugin-alias": "^1.0.2",
"rollup-plugin-babel": "^2.4.0",
"rollup-plugin-commonjs": "^2.2.1",
"rollup-plugin-node-resolve": "^1.5.0",
"rollup-plugin-replace": "^1.1.0",
"uglify-js": "^2.6.2",
"webpack": "^1.12.14"

View File

@ -0,0 +1,6 @@
const decoder = document.createElement('div')
export function decodeHTML (html) {
decoder.innerHTML = html
return decoder.textContent
}

View File

@ -1,4 +1,5 @@
import config from '../config'
import { decodeHTML } from 'entities'
/**
* Convert HTML string to AST
@ -37,6 +38,7 @@ export function parse (html) {
currentParent = stack[stack.length - 1]
},
chars (text) {
text = decodeHTML(text)
text = currentParent.tag === 'pre'
? text
: text.trim()

View File

@ -8,6 +8,11 @@ module.exports = {
library: 'Vue',
libraryTarget: 'umd'
},
resolve: {
alias: {
entities: './entity-decoder'
}
},
module: {
loaders: [
{ test: /\.js/, loader: 'babel', exclude: /node_modules/ }