MCPcopy
hub / github.com/hcengineering/platform / parse

Method parse

foundations/core/packages/text-html/src/parser.ts:512–599  ·  view source on GitHub ↗
(html: string)

Source from the content-addressed store, hash-verified

510 }
511
512 parse (html: string): MarkupNode {
513 const root: MarkupNode = { type: MarkupNodeType.doc, content: [] }
514 const state = new HtmlParseState(root, this.handlers)
515
516 let rawPos: number | undefined
517 let rawDepth: number | undefined
518
519 const parser = new Parser(
520 {
521 onopentag (tag: string, attributes: Record<string, string>) {
522 if (rawDepth !== undefined) {
523 rawDepth += 1
524 return
525 }
526
527 if (attributes.style !== undefined) {
528 const attrs = extractStyleAttrs(attributes, styleRules)
529 if (attrs !== undefined) {
530 attributes = { ...attributes, ...attrs }
531 }
532 }
533
534 const handler = state.handlers[tag]
535 if (handler !== undefined) {
536 handler.handleOpenTag(state, tag, attributes)
537 } else {
538 rawPos = parser.startIndex
539 rawDepth = 0
540 }
541 },
542
543 ontext (text: string) {
544 if (rawDepth !== undefined) {
545 return
546 }
547
548 if (text.length === 0) {
549 return
550 }
551
552 state.addText(text)
553 },
554
555 oncomment (text: string) {
556 if (rawDepth !== undefined) {
557 return
558 }
559
560 state.openNode(MarkupNodeType.comment)
561 state.addText(text)
562 state.closeNode(MarkupNodeType.comment)
563 },
564
565 onclosetag (tag: string) {
566 if (rawDepth !== undefined) {
567 rawDepth -= 1
568
569 if (rawDepth === 0) {

Callers 15

htmlToMarkupFunction · 0.95
uploadFileMethod · 0.45
processAttachmentMethod · 0.45
processDrawingsMethod · 0.45
fetchSafeFunction · 0.45
connectMethod · 0.45
subscribeMethod · 0.45
restoreLocationFunction · 0.45

Calls 2

writeMethod · 0.45
endMethod · 0.45

Tested by 4

httpRequestFunction · 0.36
decodeTokenPayloadFunction · 0.36
toEqualMarkupFunction · 0.36
sendMethod · 0.36