Commit 957fc944 authored by chris's avatar chris
Browse files

fix nested tags

parent f9ff2323
import { eq, get, isEmpty, isEqual, groupBy } from 'lodash'
import { eq, get, isEmpty, isEqual, groupBy, forEach } from 'lodash'
import React from 'react'
import ReactDOM from 'react-dom'
import PropTypes from 'prop-types'
......@@ -108,6 +108,64 @@ class Wax extends React.Component {
return onSave(convertedSource)
}
cleaup(content) {
var wrapper = document.createElement('div')
wrapper.innerHTML = content
//CLEANUP EXCESSIVE EM TAGS
const emphasis = wrapper.getElementsByTagName('em')
forEach(emphasis, em => {
const emReplacer = document.createElement('em')
if (em) {
let text = em.textContent
forEach(em.childNodes, el => {
if (el.tagName === 'EM' && el.textContent === '') {
emReplacer.innerHTML = text
em.replaceWith(emReplacer)
}
})
}
})
//CLEANUP EXCESSIVE TRACK CHANGE TAGS
const trackChanges = wrapper.getElementsByTagName('track-change')
forEach(trackChanges, element => {
const trackChangeReplacer = document.createElement('track-change')
if (element) {
const username = element.getAttribute('username')
// const status = element.getAttribute('status')
// const color = element.getAttribute('color')
//
// const createUsername = document.createAttribute('username')
// const createStatus = document.createAttribute('status')
// const createColor = document.createAttribute('color')
//
// createUsername.value = username
// createStatus.value = status
// createColor.value = color
//
// trackChangeReplacer.setAttributeNode(createUsername)
// trackChangeReplacer.setAttributeNode(createStatus)
// trackChangeReplacer.setAttributeNode(createColor)
let text = element.textContent
forEach(element.childNodes, el => {
if (el.tagName === 'TRACK-CHANGE') {
if (el.getAttribute('username') === username) {
const temp = el.textContent
trackChangeReplacer.innerHTML = text
el.replaceWith(temp)
}
}
})
}
})
return wrapper.innerHTML
}
mountEditor() {
const el = ReactDOM.findDOMNode(this)
......@@ -131,7 +189,8 @@ class Wax extends React.Component {
this.configurator = new Configurator().import(config)
this.configurator.addImporter('html', Importer)
this.configurator.menus = menus
const editorSession = this.createSession(content)
const cleaupContent = this.cleaup(content)
const editorSession = this.createSession(cleaupContent)
const onClose = this.onClose
// TODO -- make this configurable
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment