INNER CODE UNIT · TypeScript

isWhitespaceOnlyText

kane50613/takumi · takumi-helpers/src/html/index.ts:8

const isWhitespaceOnlyText = (node: Node | undefined): boolean =>
  node !== undefined && "text" in node && typeof node.text === "string" && node.text.trim() === "";

/**
 * @deprecated Pass the markup to a renderer, which parses it in Rust. Will be removed in v3.
 */
export function fromHtml(html: string): FromHtmlResult {
  const converted = fromStaticMarkup(html);

  while (isWhitespaceOnlyText(converted.nodes[0])) {
    converted.nodes.shift();
  }

  while (isWhitespaceOnlyText(converted.nodes.at(-1))) {
    converted.nodes.pop();
  }

  return rootResult(converted);

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…