MCPcopy Create free account
hub / github.com/HubSpot/draft-convert / genFragment

Function genFragment

src/convertFromHTML.js:280–526  ·  view source on GitHub ↗
(
  node,
  inlineStyle,
  lastList,
  inBlock,
  fragmentBlockTags,
  depth,
  processCustomInlineStyles,
  checkEntityNode,
  checkEntityText,
  checkBlockType,
  createEntity,
  getEntity,
  mergeEntityData,
  replaceEntityData,
  options,
  inEntity
)

Source from the content-addressed store, hash-verified

278}
279
280function genFragment(
281 node,
282 inlineStyle,
283 lastList,
284 inBlock,
285 fragmentBlockTags,
286 depth,
287 processCustomInlineStyles,
288 checkEntityNode,
289 checkEntityText,
290 checkBlockType,
291 createEntity,
292 getEntity,
293 mergeEntityData,
294 replaceEntityData,
295 options,
296 inEntity
297) {
298 let nodeName = node.nodeName.toLowerCase();
299 let newBlock = false;
300 let nextBlockType = 'unstyled';
301
302 // Base Case
303 if (nodeName === '#text') {
304 let text = node.textContent;
305 if (text.trim() === '' && inBlock === null) {
306 return getEmptyChunk();
307 }
308
309 if (text.trim() === '' && inBlock !== 'code-block') {
310 return getWhitespaceChunk(inEntity);
311 }
312 if (inBlock !== 'code-block') {
313 // Can't use empty string because MSWord
314 text = text.replace(REGEX_LF, SPACE);
315 }
316
317 const entities = Array(text.length).fill(inEntity);
318
319 let offsetChange = 0;
320 const textEntities = checkEntityText(
321 text,
322 createEntity,
323 getEntity,
324 mergeEntityData,
325 replaceEntityData
326 ).sort(rangeSort);
327
328 textEntities.forEach(({ entity, offset, length, result }) => {
329 const adjustedOffset = offset + offsetChange;
330
331 if (result === null || result === undefined) {
332 result = text.substr(adjustedOffset, length);
333 }
334
335 const textArray = text.split('');
336 textArray.splice
337 .bind(textArray, adjustedOffset, length)

Callers 1

getChunkForHTMLFunction · 0.85

Calls 7

getEmptyChunkFunction · 0.85
getWhitespaceChunkFunction · 0.85
getSoftNewlineChunkFunction · 0.85
processInlineTagFunction · 0.85
getBlockDividerChunkFunction · 0.85
getBlockTypeForTagFunction · 0.85
joinChunksFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…