Evan You
9 years ago
10 changed files with 76 additions and 26 deletions
@ -0,0 +1,18 @@ |
|||||
|
declare module 'entities' { |
||||
|
declare function encodeHTML(html: string): string; |
||||
|
declare function decodeHTML(html: string): string; |
||||
|
} |
||||
|
|
||||
|
declare module 'de-indent' { |
||||
|
declare var exports: { |
||||
|
(str: string): string; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
declare module 'source-map' { |
||||
|
declare class SourceMapGenerator { |
||||
|
setSourceContent(filename: string, content: string): void; |
||||
|
addMapping(mapping: Object): void; |
||||
|
toString(): string; |
||||
|
} |
||||
|
} |
@ -1,18 +1,31 @@ |
|||||
/* @flow */ |
/* @flow */ |
||||
|
|
||||
|
import VNode from 'core/vdom/vnode' |
||||
import { renderAttr } from './attrs' |
import { renderAttr } from './attrs' |
||||
import { propsToAttrMap, isRenderableAttr } from 'web/util/attrs' |
import { propsToAttrMap, isRenderableAttr } from 'web/util/attrs' |
||||
|
|
||||
export default function (node: VNodeWithData): ?string { |
export default function (node: VNodeWithData): string { |
||||
const props = node.data.props |
const props = node.data.props |
||||
|
let res = '' |
||||
if (props) { |
if (props) { |
||||
let res = '' |
|
||||
for (const key in props) { |
for (const key in props) { |
||||
const attr = propsToAttrMap[key] || key.toLowerCase() |
if (key === 'innerHTML') { |
||||
if (isRenderableAttr(attr)) { |
setText(node, props[key], true) |
||||
res += renderAttr(attr, props[key]) |
} else if (key === 'textContent') { |
||||
|
setText(node, props[key]) |
||||
|
} else { |
||||
|
const attr = propsToAttrMap[key] || key.toLowerCase() |
||||
|
if (isRenderableAttr(attr)) { |
||||
|
res += renderAttr(attr, props[key]) |
||||
|
} |
||||
} |
} |
||||
} |
} |
||||
return res |
|
||||
} |
} |
||||
|
return res |
||||
|
} |
||||
|
|
||||
|
function setText (node, text, raw) { |
||||
|
const child = new VNode(undefined, undefined, undefined, text) |
||||
|
child.raw = raw |
||||
|
node.children = [child] |
||||
} |
} |
||||
|
Loading…
Reference in new issue