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

Method processElement

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

Source from the content-addressed store, hash-verified

193 }
194
195 processElement(element) {
196 let attributes
197 if (nodeIsAttachmentElement(element)) {
198 attributes = parseTrixDataAttribute(element, "attachment")
199 if (Object.keys(attributes).length) {
200 const textAttributes = this.getTextAttributes(element)
201 this.appendAttachmentWithAttributes(attributes, textAttributes)
202 // We have everything we need so avoid processing inner nodes
203 element.innerHTML = ""
204 }
205 return this.processedElements.push(element)
206 } else {
207 switch (tagName(element)) {
208 case "br":
209 if (!this.isExtraBR(element) && !this.isBlockElement(element.nextSibling)) {
210 this.appendStringWithAttributes("\n", this.getTextAttributes(element))
211 }
212 return this.processedElements.push(element)
213 case "img":
214 attributes = { url: element.getAttribute("src"), contentType: "image" }
215 const object = getImageDimensions(element)
216 for (const key in object) {
217 const value = object[key]
218 attributes[key] = value
219 }
220 this.appendAttachmentWithAttributes(attributes, this.getTextAttributes(element))
221 return this.processedElements.push(element)
222 case "tr":
223 if (this.needsTableSeparator(element)) {
224 return this.appendStringWithAttributes(config.parser.tableRowSeparator)
225 }
226 break
227 case "td":
228 if (this.needsTableSeparator(element)) {
229 return this.appendStringWithAttributes(config.parser.tableCellSeparator)
230 }
231 break
232 }
233 }
234 }
235
236 // Document construction
237

Callers 1

processNodeMethod · 0.95

Calls 11

getTextAttributesMethod · 0.95
isExtraBRMethod · 0.95
isBlockElementMethod · 0.95
needsTableSeparatorMethod · 0.95
nodeIsAttachmentElementFunction · 0.90
tagNameFunction · 0.90
parseTrixDataAttributeFunction · 0.85
getImageDimensionsFunction · 0.85
getAttributeMethod · 0.45

Tested by

no test coverage detected