(node: TextNode, settings: HTMLSettings)
| 469 | |
| 470 | // For htmlText and htmlContainer, use the htmlGenerationMode to determine styling approach |
| 471 | const htmlText = (node: TextNode, settings: HTMLSettings): string => { |
| 472 | let layoutBuilder = new HtmlTextBuilder(node, settings) |
| 473 | .commonPositionStyles() |
| 474 | .textTrim() |
| 475 | .textAlignHorizontal() |
| 476 | .textAlignVertical(); |
| 477 | |
| 478 | const styledHtml = layoutBuilder.getTextSegments(node); |
| 479 | previousExecutionCache.push(...styledHtml); |
| 480 | |
| 481 | const mode = settings.htmlGenerationMode || "html"; |
| 482 | |
| 483 | // For styled-components mode |
| 484 | if (mode === "styled-components") { |
| 485 | // Build wrapper to store in cssCollection |
| 486 | layoutBuilder.build(); |
| 487 | |
| 488 | const wrapperComponentName = |
| 489 | cssCollection[layoutBuilder.cssClassName!]?.componentName || "div"; |
| 490 | |
| 491 | const content = styledHtml |
| 492 | .map((style) => { |
| 493 | const tag = |
| 494 | style.openTypeFeatures.SUBS === true |
| 495 | ? "sub" |
| 496 | : style.openTypeFeatures.SUPS === true |
| 497 | ? "sup" |
| 498 | : "span"; |
| 499 | |
| 500 | if (style.componentName) { |
| 501 | return `<${style.componentName}>${style.text}</${style.componentName}>`; |
| 502 | } |
| 503 | return `<${tag}>${style.text}</${tag}>`; |
| 504 | }) |
| 505 | .join(""); |
| 506 | |
| 507 | return `\n<${wrapperComponentName}>${content}</${wrapperComponentName}>`; |
| 508 | } |
| 509 | |
| 510 | // Standard HTML/CSS approach for HTML, React or Svelte |
| 511 | let content = ""; |
| 512 | if (styledHtml.length === 1) { |
| 513 | // For HTML and React modes, we use inline styles |
| 514 | if (mode === "html" || mode === "jsx") { |
| 515 | layoutBuilder.addStyles(styledHtml[0].style); |
| 516 | } |
| 517 | |
| 518 | content = styledHtml[0].text; |
| 519 | |
| 520 | const additionalTag = |
| 521 | styledHtml[0].openTypeFeatures.SUBS === true |
| 522 | ? "sub" |
| 523 | : styledHtml[0].openTypeFeatures.SUPS === true |
| 524 | ? "sup" |
| 525 | : ""; |
| 526 | |
| 527 | if (additionalTag) { |
| 528 | content = `<${additionalTag}>${content}</${additionalTag}>`; |
no test coverage detected