Skip to content

Commit d5b415a

Browse files
square-tombstudioclaude
committed
fix(mobile): end a quoted fence with its quote
gpt_markdown parses a fence inside a quote only within the quoted lines, so an unclosed quoted fence ends where the quote does. The prose mapper kept treating the rest of the message as code, so a later URL lost its link and escaped punctuation kept its backslash. A fence opened at quote depth N now ends at the first line with fewer than N markers. Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Tom Brow <[email protected]>
1 parent c847244 commit d5b415a

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎mobile/lib/features/channels/message_content/link_normalizer.dart‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ String mapMarkdownProse(String content, String Function(String) transform) {
3535
var fenceQuoteDepth = 0;
3636

3737
while (offset < content.length) {
38+
// A fence opened inside a quote ends with that quote, closed or not.
39+
if (fenceDelimiterLength > 0 &&
40+
fenceQuoteDepth > 0 &&
41+
content[offset] == '\n' &&
42+
_lineQuoteDepth(content, offset + 1) < fenceQuoteDepth) {
43+
buffer.write(content.substring(codeStart, offset));
44+
fenceDelimiterLength = 0;
45+
proseStart = offset;
46+
}
3847
final run = _codeRunPattern.matchAsPrefix(content, offset);
3948
if (run == null) {
4049
offset++;
@@ -152,6 +161,21 @@ int _fenceQuoteDepth(String content, int runStart) {
152161
return depth;
153162
}
154163

164+
/// The number of quote markers (`>`) in the blank-and-marker prefix of the
165+
/// line starting at [lineStart].
166+
int _lineQuoteDepth(String content, int lineStart) {
167+
var depth = 0;
168+
for (var i = lineStart; i < content.length; i++) {
169+
final char = content[i];
170+
if (char == '>') {
171+
depth++;
172+
} else if (char == '\n' || char.trim().isNotEmpty) {
173+
break;
174+
}
175+
}
176+
return depth;
177+
}
178+
155179
bool _hasInlineCloserOnLine(String content, int start, int delimiterLength) {
156180
final newline = content.indexOf('\n', start);
157181
final lineEnd = newline < 0 ? content.length : newline;

‎mobile/test/features/channels/message_content/link_normalizer_test.dart‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ void main() {
196196
input: '> ```sh\n> $url',
197197
expected: '> ```sh\n> $url',
198198
),
199+
(
200+
name: 'unclosed quoted fence ends with its quote',
201+
input: '> ```sh\n> $url\n\n$url',
202+
expected: '> ```sh\n> $url\n\n[$url]($url)',
203+
),
204+
(
205+
name: 'quoted fence ends at a lazy line',
206+
input: '> ```sh\n> $url\n$url',
207+
expected: '> ```sh\n> $url\n[$url]($url)',
208+
),
199209
(
200210
name: 'top-level fence does not close on a quoted fence',
201211
input: '```md\n> ```\n$url\n```\n$url',

‎mobile/test/features/channels/message_content_test.dart‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,8 @@ void main() {
521521
// A fence closes only at the quote depth it opened at.
522522
('```md\n> ```\necho \\#g\n```', r'echo \#g'),
523523
('> ```sh\n> x\n\n```\necho \\#g\n```', r'echo \#g'),
524+
// A quoted fence ends with its quote, so later prose is parsed.
525+
('> ```sh\n> echo x\n\nplain \\#text', 'plain #text'),
524526
// Known limitation: gpt_markdown's raw-text fallback for this
525527
// unclaimed strike skips inline components, so the stand-in shows.
526528
// Its fullwidth form still reads as #.

0 commit comments

Comments
 (0)