LCOV - code coverage report
Current view: top level - src/components/graph/widgets - TextPreviewWidget.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 100.0 % 20 20
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <template>
       2            3 :   <div
       3              :     class="relative max-h-[200px] min-h-[28px] w-full overflow-y-auto rounded-lg px-4 py-2 text-xs"
       4              :   >
       5              :     <div class="flex items-center gap-2">
       6              :       <div class="flex flex-1 items-center gap-2 break-all">
       7              :         <SanitizedHtml
       8              :           as="span"
       9              :           class="[&_a]:text-primary [&_a]:underline"
      10              :           :html="formattedText"
      11              :         />
      12              :         <Skeleton
      13              :           v-if="isParentNodeExecuting"
      14              :           data-testid="skeleton"
      15              :           class="h-4 flex-1"
      16              :         />
      17              :       </div>
      18              :     </div>
      19              :   </div>
      20              : </template>
      21              : 
      22              : <script setup lang="ts">
      23              : import { default as DOMPurify } from 'dompurify'
      24              : import { computed } from 'vue'
      25              : 
      26              : import SanitizedHtml from '@comfyorg/design-system/common/SanitizedHtml'
      27              : import Skeleton from '@comfyorg/design-system/skeleton/Skeleton'
      28              : import { useExecutionStore } from '@/stores/executionStore'
      29              : import type { NodeId } from '@comfyorg/graph-model/nodeId'
      30              : import { linkifyHtml, nl2br } from '@/utils/formatUtil'
      31              : import { escapeHtml } from '@/utils/htmlEscape'
      32              : 
      33            1 : const modelValue = defineModel<string>({ required: true })
      34            1 : const props = defineProps<{
      35              :   nodeId: NodeId
      36              : }>()
      37              : 
      38            1 : const executionStore = useExecutionStore()
      39            1 : const isParentNodeExecuting = computed(() => {
      40            2 :   if (executionStore.isIdle) return false
      41            2 :   return executionStore.executingNodeIds.includes(props.nodeId)
      42              : })
      43            1 : const formattedText = computed(() => {
      44            2 :   const src = modelValue.value
      45              :   // Turn [[label|url]] into placeholders to avoid interfering with linkifyHtml
      46            2 :   const tokens: { label: string; url: string }[] = []
      47            2 :   const holed = src.replace(
      48              :     /\[\[([^|\]]+)\|([^\]]+)\]\]/g,
      49              :     (_m, label, url) => {
      50            1 :       tokens.push({ label: String(label), url: String(url) })
      51            1 :       return `__LNK${tokens.length - 1}__`
      52              :     }
      53              :   )
      54              : 
      55              :   // Escape HTML-significant characters BEFORE linkifying so bracket-delimited
      56              :   // text that looks like a tag (e.g. `<lora:my_style_v2:0.8>`) displays
      57              :   // literally instead of being parsed as markup and dropped. linkifyHtml only
      58              :   // matches http(s)/ftp/file/www URLs, none of which contain the escaped
      59              :   // entities, so escaping first doesn't stop real URLs from being linkified.
      60              :   // Keep current behavior otherwise (auto-link bare URLs + \n -> <br>).
      61            2 :   let html = nl2br(linkifyHtml(escapeHtml(holed)))
      62              : 
      63              :   // Restore placeholders as <a>...</a> (escape label/url for safety)
      64            2 :   html = html.replace(/__LNK(\d+)__/g, (_m, i) => {
      65            1 :     const { label, url } = tokens[+i]
      66            1 :     const safeHref = escapeHtml(url)
      67            1 :     const safeLabel = escapeHtml(label)
      68            1 :     return /^https?:\/\//i.test(url)
      69              :       ? `<a href="${safeHref}" target="_blank" rel="noopener noreferrer">${safeLabel}</a>`
      70              :       : safeLabel
      71              :   })
      72              : 
      73              :   // Strict allowlist: this widget only needs anchors and line breaks. Raw
      74              :   // websocket progress text flows into modelValue, so we drop every other
      75              :   // tag (img, script, iframe, etc.) to keep the v-html trust boundary tight.
      76            2 :   return DOMPurify.sanitize(html, {
      77              :     ALLOWED_TAGS: ['a', 'br'],
      78              :     ALLOWED_ATTR: ['href', 'target', 'rel']
      79              :   })
      80              : })
      81              : </script>
        

Generated by: LCOV version 2.0-1