Files
archived-orca/mobile/src/components/MobileMarkdownDetails.tsx
Kelvin Amoaba 78ff857c88 feat(mobile): render PR descriptions and comments with the shared Markdown renderer (#38611)
* feat(mobile): render PR bodies and comments with the shared Markdown renderer

The PR view drew PR bodies, comments and review threads with its own small
parser, so strikethrough, footnotes, task lists, entities, nested lists and
quotes, images and bare links came out raw or mangled, and nothing could be
selected. It now uses MobileMarkdown, like chat, file preview and Tasks.

MobileMarkdown gains collapsible <details> sections (closed unless authored
open), the one thing only the PR parser had. Images without alt text no
longer draw the word "image".

* fix(mobile): keep <details> parsing bounded and browser-like

Cap section nesting, keep each markup scan linear on hostile input, leave
markup inside HTML comments alone, read open as a real attribute, and close
a section whose </details> sits inside a list item with that list.

* fix(mobile): close <details> at an inline </details> and ignore <details-*> tags

A </details> at the end of a paragraph or list item ends the section with
that block, as in a browser. Custom <details-menu>-style tags no longer
open a section, and heading markup in a summary keeps only its text.

* refactor(mobile): simplify <details> parsing and reuse DisclosureChevron

Keep the close-with-container mark on the node instead of a module set,
skip HTML blocks with no details markup up front, scan inline HTML once,
and turn the summary chevron the way other disclosures do.

* chore(mobile): register the <details> mdast node in a declaration file both lint gates accept

* chore(mobile): keep the lint config plain JSON
2026-11-05 21:30:33 +00:00

40 lines
1.4 KiB
TypeScript

import { useState, type ReactNode } from 'react'
import { Pressable, Text, View, type StyleProp, type TextStyle } from 'react-native'
import { ChevronRight } from 'lucide-react-native'
import { DisclosureChevron } from './DisclosureChevron'
import { styles } from './mobile-markdown-styles'
import { colors, pressedStyle } from '../theme/mobile-theme'
import { useMobileColorScheme } from '../theme/use-mobile-color-scheme'
/** A `<details>` section: closed unless authored `open`, like desktop and GitHub. */
export function MobileMarkdownDetails({
summary,
open,
summaryStyle,
children
}: {
summary: ReactNode
open: boolean
summaryStyle: StyleProp<TextStyle>
children: ReactNode
}) {
useMobileColorScheme()
const [expanded, setExpanded] = useState(open)
return (
<View style={styles.details}>
<Pressable
style={({ pressed }) => [styles.detailsSummary, pressed && pressedStyle]}
onPress={() => setExpanded((value) => !value)}
accessibilityRole="button"
accessibilityState={{ expanded }}
>
<DisclosureChevron expanded={expanded} collapsedDeg={0} expandedDeg={90}>
<ChevronRight size={14} color={colors.textSecondary} strokeWidth={2.2} />
</DisclosureChevron>
<Text style={[summaryStyle, styles.detailsSummaryText]}>{summary}</Text>
</Pressable>
{expanded ? <View style={styles.detailsBody}>{children}</View> : null}
</View>
)
}