/*
* <<
* Davinci
* ==
* Copyright (C) 2016 - 2017 EDP
* ==
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* >>
*/
import escapeHtml from 'escape-html'
import { Node, Text } from 'slate'
import { jsx } from 'slate-hyperscript'
import { ElementTags, TextStyles, TextTags } from './Element'
import { TextProperties, ElementTypes } from './Element/constants'
const serializeNode = (node: Node) => {
if (Text.isText(node)) {
let text = escapeHtml(node.text)
if (node[TextStyles.Bold]) {
text = `${text}`
}
if (node[TextStyles.Italic]) {
text = `${text}`
}
if (node[TextStyles.Underline]) {
text = `${text}`
}
if (node[TextStyles.StrikeThrough]) {
text = `${text}`
}
if (node[TextStyles.Code]) {
text = `${text}
`
}
TextProperties
var span = document.createElement('span')
if (node[TextProperties.BackgroundColor]) {
span.style.backgroundColor = node[TextProperties.BackgroundColor]
}
if (node[TextProperties.Color]) {
span.style.color = node[TextProperties.Color]
}
if (node[TextProperties.FontFamily]) {
span.style.fontFamily = node[TextProperties.FontFamily]
}
if (node[TextProperties.FontSize]) {
span.style.fontSize = `${node[TextProperties.FontSize]}px`
}
span.innerHTML = text
text = span.outerHTML
return text
}
const children = node.children.map((n) => serializeNode(n)).join('')
switch (node.type) {
case ElementTypes.Paragraph:
return `
${children}
` case ElementTypes.BlockQuote: return `${children}` case ElementTypes.Code: return `
${children}
`
case ElementTypes.BulletedList:
return `