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
2 changes: 1 addition & 1 deletion apps/mobile/deps/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The Enriched Markdown tarball comes from `main` of [aislopware/enriched-markdown](https://github.com/aislopware/enriched-markdown). Its `oni-fork.json` records the exact source commit and upstream base. React block renderers, signed image sources, the `onLinksChange` link list (`renderers`, `resolveImageSource`, `onLinksChange`) and the iOS streaming memory bounds are upstream. The fork carries only changes with an open upstream PR: clipboard link metadata ([#962](https://github.com/software-mansion/enriched-markdown/pull/962)), development-host autolinks ([#961](https://github.com/software-mansion/enriched-markdown/pull/961)) and hash-route link fragments ([mity/md4c#454](https://github.com/mity/md4c/pull/454), arriving through [md4c#7](https://github.com/software-mansion-labs/md4c/pull/7)), `md4cFlags.preserveWindowsPaths`, which keeps backslashes in Windows drive paths in prose ([#1105](https://github.com/software-mansion/enriched-markdown/pull/1105), after [mity/md4c#477](https://github.com/mity/md4c/pull/477)), GitHub's strikethrough rules for `~` ([md4c#6](https://github.com/software-mansion-labs/md4c/pull/6)), `\(…\)` and `\[…\]` math delimiters ([#1043](https://github.com/software-mansion/enriched-markdown/pull/1043), [md4c#4](https://github.com/software-mansion-labs/md4c/pull/4)), iOS Copy as Markdown keeping bold spans whole ([#1143](https://github.com/software-mansion/enriched-markdown/pull/1143)), line breaks in copied table cells written as `<br>` ([#1144](https://github.com/software-mansion/enriched-markdown/pull/1144)), and Android measuring text in the span order its view draws it, so code blocks nested in list items no longer make a reply overlap the next message ([#1145](https://github.com/software-mansion/enriched-markdown/pull/1145)). It also carries two fork-only changes, both from T3 Code's fork: iOS code blocks too big for one backing store draw through tiles, so a tall block with long lines no longer shows an empty pane ([pingdotgg/enriched-markdown#15](https://github.com/pingdotgg/enriched-markdown/pull/15)), and a long-pressed iOS blockquote lifts on the background it sits on instead of drawing its text over the thread.
The Enriched Markdown tarball comes from `main` of [aislopware/enriched-markdown](https://github.com/aislopware/enriched-markdown). Its `oni-fork.json` records the exact source commit and upstream base. React block renderers, signed image sources, the `onLinksChange` link list (`renderers`, `resolveImageSource`, `onLinksChange`) and the iOS streaming memory bounds are upstream. The fork carries only changes with an open upstream PR: clipboard link metadata ([#962](https://github.com/software-mansion/enriched-markdown/pull/962)), development-host autolinks ([#961](https://github.com/software-mansion/enriched-markdown/pull/961)) and hash-route link fragments ([mity/md4c#454](https://github.com/mity/md4c/pull/454), arriving through [md4c#7](https://github.com/software-mansion-labs/md4c/pull/7)), `md4cFlags.preserveWindowsPaths`, which keeps backslashes in Windows drive paths in prose ([#1105](https://github.com/software-mansion/enriched-markdown/pull/1105), after [mity/md4c#477](https://github.com/mity/md4c/pull/477)), GitHub's strikethrough rules for `~` ([md4c#6](https://github.com/software-mansion-labs/md4c/pull/6)), `\(…\)` and `\[…\]` math delimiters ([#1043](https://github.com/software-mansion/enriched-markdown/pull/1043), [md4c#4](https://github.com/software-mansion-labs/md4c/pull/4)), iOS Copy as Markdown keeping bold spans whole ([#1143](https://github.com/software-mansion/enriched-markdown/pull/1143)), line breaks in copied table cells written as `<br>` ([#1144](https://github.com/software-mansion/enriched-markdown/pull/1144)), and Android measuring text in the span order its view draws it, so code blocks nested in list items no longer make a reply overlap the next message ([#1145](https://github.com/software-mansion/enriched-markdown/pull/1145)). It also carries three fork-only changes. `writingDirection="word-majority"` sets each paragraph, list item, heading and table cell right to left when its right-to-left words outnumber its left-to-right ones. It counts words as the desktop client does, but decides per paragraph where desktop decides per top-level block (Android API 29+; older Android keeps first-strong). The other two come from T3 Code's fork: iOS code blocks too big for one backing store draw through tiles, so a tall block with long lines no longer shows an empty pane ([pingdotgg/enriched-markdown#15](https://github.com/pingdotgg/enriched-markdown/pull/15)), and a long-pressed iOS blockquote lifts on the background it sits on instead of drawing its text over the thread.

To replace it, commit the fork changes on `main` with the next `1.2.0-oni.N` version, run `yarn install --immutable` and `yarn workspace react-native-enriched-markdown prepare` in the fork checkout, then `yarn workspace react-native-enriched-markdown pack:onicode /absolute/path/to/onicode/apps/mobile/deps`. Tag the source commit `oni-v<version>` and push `main` and the tag to the fork. Rename the archive to include the first eight characters of the source commit, as in `react-native-enriched-markdown-<version>-<commit>.tgz`, so each build has a distinct dependency path. Update the tarball path in `apps/mobile/package.json` and `pnpm-workspace.yaml`'s `allowBuilds`, and run `vp i` to update the lockfile. Native clients need rebuilding when this dependency changes.

Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"react": "catalog:",
"react-dom": "catalog:",
"react-native": "0.88.1",
"react-native-enriched-markdown": "file:deps/react-native-enriched-markdown-1.2.0-oni.21-a423deee.tgz",
"react-native-enriched-markdown": "file:deps/react-native-enriched-markdown-1.2.0-oni.22-0c421a6f.tgz",
"react-native-gesture-handler": "~3.5.0",
"react-native-image-viewing": "^0.2.2",
"react-native-keyboard-controller": "1.23.0",
Expand Down
3 changes: 2 additions & 1 deletion apps/mobile/src/features/threads/PendingUserInputCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ function QuestionText(props: {
<SelectableMarkdownText
markdown={markdown}
textStyle={styles.nativeTextStyle}
writingDirection={markdownProseDirection(markdown)}
// Android maps an explicit direction to first-strong, so it keeps the word-majority default.
writingDirection={Platform.OS === "android" ? undefined : markdownProseDirection(markdown)}
// Android's renderer aligns relative to each paragraph's direction.
textAlign={
Platform.OS === "android" ? undefined : props.setDirection === "rtl" ? "right" : "left"
Expand Down
1 change: 0 additions & 1 deletion apps/mobile/src/lib/enrichedLinkPresentation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ describe("Enriched link presentation", () => {
"Try (model:codex/gpt-6.1).",
"Try [model:codex/gpt-6.1] next",
'"model:codex/gpt-6.1"',
"‏model:codex/gpt-6.1 هذا شرح",
]) {
const source = regex?.exec(text)?.[0];
expect(source, text).toBe("model:codex/gpt-6.1");
Expand Down
3 changes: 1 addition & 2 deletions apps/mobile/src/lib/enrichedLinkPresentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,8 @@ export function enrichedModelLinkRegex(models?: ReadonlyArray<SelectableMarkdown
.map((model) => model.source)
.sort((a, b) => b.length - a.length)
.map((source) => source.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
// LRM and RLM can open a paragraph whose first word runs against the text direction.
return new RegExp(
`(?<![^\\s,(\\["'\\u200E\\u200F])(?:${alternatives.join("|")})(?=$|[\\s,"']|[.;:!?\\)\\]]+(?=$|[\\s,"']))`,
`(?<![^\\s,(\\["'])(?:${alternatives.join("|")})(?=$|[\\s,"']|[.;:!?\\)\\]]+(?=$|[\\s,"']))`,
"u",
);
}
Expand Down
62 changes: 0 additions & 62 deletions apps/mobile/src/lib/markdownDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
parseMarkdownFileLink,
} from "@onicode/shared/markdownLinks";
import { isWindowsAbsolutePath } from "@onicode/shared/path";
import { hasRightToLeftLetter, textDirection } from "@onicode/shared/textDirection";

const parser = unified().use(remarkParse).use(remarkGfm).use(remarkKeepWindowsProsePaths);
export type MarkdownNode = Root | RootContent;
Expand Down Expand Up @@ -563,64 +562,3 @@ export function markdownWithFileEmbeds(
parts.push(markdown.slice(offset));
return { markdown: parts.join(""), fileHrefs };
}

const DIRECTION_MARK = { ltr: "‎", rtl: "‏" } as const;

function proseText(node: MarkdownNode): string {
if (node.type === "text") return node.value;
if (node.type === "inlineCode" || node.type === "code") return " ";
if (!("children" in node)) return "";
const text = node.children.map(proseText).join("");
return node.type === "paragraph" || node.type === "heading" || node.type === "tableCell"
? ` ${text} `
: text;
}

// The native renderer scans inline code too when it picks a paragraph's direction.
function renderedText(node: MarkdownNode): string {
if (node.type === "text" || node.type === "inlineCode") return node.value;
if (!("children" in node)) return "";
return node.children.map(renderedText).join("");
}

// A mark inside `[label]` or `<url>` would break the reference or autolink.
function firstLeafOffset(node: MarkdownNode): number | undefined {
if (
!("children" in node) ||
node.children.length === 0 ||
node.type === "link" ||
node.type === "linkReference"
) {
return node.position?.start.offset;
}
return firstLeafOffset(node.children[0]!);
}

/**
* The native renderer gives each paragraph the direction of its first letter, so an Arabic
* line that opens with an English name renders left to right. Like the web's
* `rehypeTextDirection`, each top-level block follows the majority of its words, and a
* paragraph whose first letter disagrees gets a direction mark that the renderer reads first.
*/
export function markdownWithTextDirection(markdown: string): string {
if (!hasRightToLeftLetter(markdown)) return markdown;
const edits: MarkdownEdit[] = [];
for (const block of parser.parse(markdown).children) {
if (block.type === "code" || block.type === "html") continue;
const direction = textDirection(proseText(block));
if (!direction) continue;
const mark = (node: MarkdownNode) => {
if (node.type === "paragraph" || node.type === "heading" || node.type === "tableCell") {
const offset = firstLeafOffset(node);
const first = renderedText(node).match(/\p{L}/u)?.[0];
if (offset !== undefined && first && textDirection(first) !== direction) {
edits.push({ start: offset, end: offset, content: DIRECTION_MARK[direction] });
}
return;
}
if ("children" in node) node.children.forEach(mark);
};
mark(block);
}
return applyMarkdownEdits(markdown, edits);
}
71 changes: 0 additions & 71 deletions apps/mobile/src/lib/markdownTextDirection.test.ts

This file was deleted.

13 changes: 4 additions & 9 deletions apps/mobile/src/native/EnrichedMarkdownText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
markdownForNativeParsing,
markdownWithInlineFileLinks,
markdownWithTableBreaks,
markdownWithTextDirection,
} from "../lib/markdownDocument";
import { useGT } from "gt-react-native";
import { isValidElement, useMemo, useState, type ReactElement, type ReactNode } from "react";
Expand Down Expand Up @@ -250,9 +249,7 @@ export function MobileEnrichedMarkdownText(props: SelectableMarkdownTextProps) {
const { markdown, fileHrefs } = useMemo(() => {
if (!fileEmbedLabel) {
return {
markdown: markdownWithTextDirection(
markdownForNativeRendering(props.markdown, ENRICHED_INLINE_FILE_LINK_REGEX),
),
markdown: markdownForNativeRendering(props.markdown, ENRICHED_INLINE_FILE_LINK_REGEX),
fileHrefs: new Set<string>(),
};
}
Expand All @@ -261,10 +258,7 @@ export function MobileEnrichedMarkdownText(props: SelectableMarkdownTextProps) {
ENRICHED_INLINE_FILE_LINK_REGEX,
);
const files = markdownWithFileEmbeds(content, fileEmbedLabel);
return {
...files,
markdown: markdownWithTextDirection(markdownWithTableBreaks(files.markdown)),
};
return { ...files, markdown: markdownWithTableBreaks(files.markdown) };
}, [props.markdown, fileEmbedLabel]);
const [parsedLinkUrls, setParsedLinkUrls] = useState<ReadonlyArray<string>>([]);
const onLinksChange = (links: MarkdownLinkOccurrence[]) => {
Expand Down Expand Up @@ -440,7 +434,8 @@ export function MobileEnrichedMarkdownText(props: SelectableMarkdownTextProps) {
<EnrichedMarkdownText
markdown={markdown}
markdownStyle={markdownStyle}
writingDirection={props.writingDirection}
// Each paragraph, item and cell goes the way most of its words read, as on desktop.
writingDirection={props.writingDirection ?? "word-majority"}
onLinksChange={onLinksChange}
renderers={renderers}
resolveImageSource={resolveNativeImageSource}
Expand Down
4 changes: 0 additions & 4 deletions packages/shared/src/textDirection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ function majority(
return rtl > ltr ? "rtl" : "ltr";
}

export function hasRightToLeftLetter(text: string): boolean {
return RTL_LETTER.test(text);
}

function wordDirection(word: string): TextDirection | undefined {
const letter = LETTER.exec(word)?.[0];
if (!letter) return undefined;
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading