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 */ |
|||
|
|||
import VNode from 'core/vdom/vnode' |
|||
import { renderAttr } from './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 |
|||
let res = '' |
|||
if (props) { |
|||
let res = '' |
|||
for (const key in props) { |
|||
const attr = propsToAttrMap[key] || key.toLowerCase() |
|||
if (isRenderableAttr(attr)) { |
|||
res += renderAttr(attr, props[key]) |
|||
if (key === 'innerHTML') { |
|||
setText(node, props[key], true) |
|||
} 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