Files
paseo/packages/react-native-enriched-markdown/lib/module/web/utils.js
T
Mohamed Boudra eda906f6ee chore(app): vendor react-native-enriched-markdown with the Paseo patch applied
Copy react-native-enriched-markdown@1.2.0-nightly-20261014-766fc0e67 (upstream
software-mansion/enriched-markdown 766fc0e67) into
packages/react-native-enriched-markdown, with
patches/react-native-enriched-markdown+1.2.0-nightly-20261014-766fc0e67.patch
applied. Nothing else changes in this commit; the package is not a workspace yet.

Reproduce:

  npm pack react-native-enriched-markdown@1.2.0-nightly-20261014-766fc0e67
  tar xzf react-native-enriched-markdown-*.tgz
  mkdir -p t/node_modules && mv package t/node_modules/react-native-enriched-markdown
  (cd t && git init -q && git apply ../patches/react-native-enriched-markdown+*.patch)
  diff -r t/node_modules/react-native-enriched-markdown packages/react-native-enriched-markdown

The diff is empty.
2026-11-22 08:14:39 +01:00

63 lines
2.0 KiB
JavaScript

"use strict";
/** Recursively collects plain text content from an AST node's subtree. */
export function extractNodeText(node) {
if (node.type === 'SoftBreak' || node.type === 'LineBreak') return ' ';
if (node.content !== undefined) return node.content;
return node.children?.map(extractNodeText).join('') ?? '';
}
/** Extracts the filename from a URL path, without extension. */
export function filenameFromUrl(url) {
try {
const pathname = new URL(url, 'https://placeholder').pathname;
const filename = pathname.split('/').pop() ?? '';
return filename.replace(/\.[^.]+$/, '');
} catch {
return '';
}
}
/**
* Stamps each task ListItem with a sequential `taskIndex` matching the order
* native C++ assigns — so onTaskListItemPress.index is correct on web too.
* Mutates the AST in-place (safe: called once on the freshly-parsed result).
*/
export function indexTaskItems(node, counter = {
value: 0
}) {
if (node.type === 'ListItem' && node.attributes?.isTask === 'true') {
node.attributes.taskIndex = counter.value++;
}
node.children?.forEach(child => indexTaskItems(child, counter));
}
/**
* Stamps Image nodes with `isInline` when they appear inside a paragraph
* that also contains other content (text, links, etc.).
* Matches native behavior: sole-child images are block-level, mixed are inline.
* Mutates the AST in-place (safe: called once on the freshly-parsed result).
*/
export function markInlineImages(node) {
if (node.type === 'Paragraph' && node.children) {
if (!node.children.every(isImageLike)) {
node.children.forEach(stampInlineImages);
}
}
node.children?.forEach(markInlineImages);
}
function isImageLike(node) {
if (node.type === 'Image') return true;
return node.type === 'Link' && node.children?.length === 1 && isImageLike(node.children[0]);
}
function stampInlineImages(node) {
if (node.type === 'Image') {
node.attributes = {
...node.attributes,
isInline: true
};
return;
}
node.children?.forEach(stampInlineImages);
}
//# sourceMappingURL=utils.js.map