Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import { fonts } from '../theme/typography'
import { isTableSeparator } from '../lib/markdown'

/**
* Small self-contained markdown renderer for assistant chat answers (tutor-register gpt-4.1 output:
* Small self-contained markdown renderer. Its content is what an outside assistant wrote back as a
* BookInsight (Markdown on the wire:
* `##` headings, bullets, numbered lists, **bold**, *italic*, `inline code`, fenced code blocks,
* blockquotes, and GFM tables). Deliberately NOT `react-native-markdown-display` — that dep is
* unmaintained against RN 0.83 / the new architecture, and adding a native-adjacent parser is a
* Play Data-Safety + OTA risk for zero upside here. This renderer is ~180 lines, theme-tokenised,
* and pure-JS (OTA-safe). No raw-HTML path exists — model output is only ever tokenised as markdown.
*
* Divergences vs web AskMarkdown: tables degrade to a horizontally-scrollable monospace block
* Divergences vs web Markdown: tables degrade to a horizontally-scrollable monospace block
* (RN has no <table>); inline `[n]` citation markers render as plain text (the citation CHIPS below
* the answer are the jump surface on mobile). Links render as literal text (the inline pass has no
* link rule) — intended: answers are grounded in the book, external links are vanishingly rare.
Expand Down Expand Up @@ -59,7 +60,7 @@ function renderInline(line: string, colors: InlineColors, keyPrefix: string): Re

const HEADING_SIZE: Record<number, number> = { 1: 22, 2: 19, 3: 17, 4: 15, 5: 14, 6: 13 }

export const AskMarkdown = memo(function AskMarkdown({ text }: { text: string }) {
export const Markdown = memo(function Markdown({ text }: { text: string }) {
const { colors } = useTheme()
const inline: InlineColors = { text: colors.text, code: colors.primary, codeBg: colors.border + '66' }
const blocks: ReactNode[] = []
Expand Down
6 changes: 3 additions & 3 deletions apps/mobile/src/components/library/BookInsightsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { insightsApi, insightChapterLabel, type BookInsight } from '@textstack/s
import { useTheme } from '../../context/ThemeContext'
import { useLanguage } from '../../context/LanguageContext'
import { fonts } from '../../theme/typography'
import { AskMarkdown } from '../AskMarkdown'
import { Markdown } from '../Markdown'

/**
* "What you've worked out" — the conclusions an outside assistant wrote back into
Expand All @@ -19,7 +19,7 @@ import { AskMarkdown } from '../AskMarkdown'
* a tutorial for a feature you can only reach by connecting an assistant, and it
* would sit on every book screen forever for the readers who never do.
*
* Markdown goes through `AskMarkdown`, the renderer the Ask sheet already uses:
* Markdown goes through the shared `Markdown` renderer:
* pure JS, theme-tokenised, OTA-safe, and no raw-HTML path — so assistant output
* is only ever tokenised, never interpreted.
*/
Expand Down Expand Up @@ -71,7 +71,7 @@ export function BookInsightsSection({ userBookId, editionId }: Props) {
) : null}

<View style={styles.body}>
<AskMarkdown text={insight.text} />
<Markdown text={insight.text} />
</View>
</View>
))}
Expand Down
13 changes: 1 addition & 12 deletions apps/mobile/src/components/reader/ReaderShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { MutableRefObject, RefObject } from 'react'
import { View, Text, StyleSheet, TouchableOpacity, Animated, Linking, BackHandler } from 'react-native'
import { WebView } from 'react-native-webview'
import { useRouter, Stack } from 'expo-router'
import { t, computeBookProgress, estimateTimeLeft, formatMinutesLeft, citationChapterSlug, makeSnippet, plural, resolvePdfResumePage, chapterEndPage } from '@textstack/shared'
import { t, computeBookProgress, estimateTimeLeft, formatMinutesLeft, plural, resolvePdfResumePage, chapterEndPage } from '@textstack/shared'
import type { Chapter, BookmarkDto, TextPosition } from '@textstack/shared'
import { buildReaderHtml, buildPdfViewerHtml } from '../../lib/readerHtml'
import {
Expand Down Expand Up @@ -649,10 +649,6 @@ export function ReaderShell(props: ReaderShellProps) {
onNavigateChapter(slug)
}

// RAG citation (AI-026d): scroll the WebView to the cited passage.
const pendingCitationRef = useRef<{ slug: string; snippet: string; charStart: number } | null>(null)
const scrollToCitation = (snippet: string, charStart: number) =>
injectJs(`window.__textstackScrollToCitation && window.__textstackScrollToCitation(${JSON.stringify(snippet)}, ${charStart})`)

// M2: scroll the reflow WebView to a saved highlight (no chapter navigation →
// reading position preserved). The Highlights sheet's list is always the
Expand Down Expand Up @@ -955,13 +951,6 @@ export function ReaderShell(props: ReaderShellProps) {
// Scroll-restore is owned by useReaderPersistence — it coordinates
// this signal with the async saved-position fetch (no race).
onWebViewLoaded()
// A cross-chapter citation jump (AI-026d): once the cited chapter has rendered, scroll
// to the passage — after restore (delay) so the explicit jump wins.
const pc = pendingCitationRef.current
if (pc && pc.slug === activeSlug) {
pendingCitationRef.current = null
setTimeout(() => scrollToCitation(pc.snippet, pc.charStart), 120)
}
}}
originWhitelist={['*']}
// Android's WebView ignores the viewport's user-scalable unless the
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/lib/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Pure markdown-block helpers for the chat renderer (AskMarkdown). Kept RN-free so the block-detection
// Pure markdown-block helpers for the `Markdown` renderer. Kept RN-free so the block-detection
// rules are unit-testable under Vitest (see markdown.test.ts) without bundling React Native.

/**
Expand Down
85 changes: 0 additions & 85 deletions apps/mobile/src/lib/sse.ts

This file was deleted.

92 changes: 0 additions & 92 deletions apps/mobile/src/lib/sseParser.test.ts

This file was deleted.

119 changes: 0 additions & 119 deletions apps/mobile/src/lib/sseParser.ts

This file was deleted.

Loading
Loading