MCPcopy
hub / github.com/basecamp/trix / appendBlockForElement

Method appendBlockForElement

src/trix/models/html_parser.js:144–170  ·  view source on GitHub ↗
(element)

Source from the content-addressed store, hash-verified

142 }
143
144 appendBlockForElement(element) {
145 const elementIsBlockElement = this.isBlockElement(element)
146 const currentBlockContainsElement = elementContainsNode(this.currentBlockElement, element)
147
148 if (elementIsBlockElement && !this.isBlockElement(element.firstChild)) {
149 if (!this.isInsignificantTextNode(element.firstChild) || !this.isBlockElement(element.firstElementChild)) {
150 const attributes = this.getBlockAttributes(element)
151 const htmlAttributes = this.getBlockHTMLAttributes(element)
152 if (element.firstChild) {
153 if (!(currentBlockContainsElement && arraysAreEqual(attributes, this.currentBlock.attributes))) {
154 this.currentBlock = this.appendBlockForAttributesWithElement(attributes, element, htmlAttributes)
155 this.currentBlockElement = element
156 } else {
157 return this.appendStringWithAttributes("\n")
158 }
159 }
160 }
161 } else if (this.currentBlockElement && !currentBlockContainsElement && !elementIsBlockElement) {
162 const parentBlockElement = this.findParentBlockElement(element)
163 if (parentBlockElement) {
164 return this.appendBlockForElement(parentBlockElement)
165 } else {
166 this.currentBlock = this.appendEmptyBlock()
167 this.currentBlockElement = null
168 }
169 }
170 }
171
172 findParentBlockElement(element) {
173 let { parentElement } = element

Callers 1

processNodeMethod · 0.95

Calls 10

isBlockElementMethod · 0.95
getBlockAttributesMethod · 0.95
appendEmptyBlockMethod · 0.95
elementContainsNodeFunction · 0.90
arraysAreEqualFunction · 0.90

Tested by

no test coverage detected