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 lib/screens/documents/section_detail_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:google_fonts/google_fonts.dart';

Expand Down
4 changes: 2 additions & 2 deletions lib/screens/projects/blobs_section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:io';

import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:path_provider/path_provider.dart';
Expand Down Expand Up @@ -401,7 +401,7 @@ class _BlobTile extends StatelessWidget {
}

/// Fullscreen reader for text-shaped blobs (markdown, plain text,
/// JSON, YAML). Decoded as UTF-8; markdown renders via flutter_markdown,
/// JSON, YAML). Decoded as UTF-8; markdown renders via flutter_markdown_plus,
/// everything else falls back to a monospace `SelectableText` so the
/// raw content stays copyable. Keeps the assets surface useful for the
/// notes/configs testers upload to verify behavior without needing the
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/projects/doc_viewer_screen.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:google_fonts/google_fonts.dart';

import '../../providers/hub_provider.dart';
import '../../theme/design_colors.dart';

/// Full-screen read-only viewer for a single project doc. Markdown files
/// render via flutter_markdown; anything else falls back to monospace
/// render via flutter_markdown_plus; anything else falls back to monospace
/// selectable text so code/config files stay copyable.
class DocViewerScreen extends ConsumerStatefulWidget {
final String projectId;
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/projects/documents_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:google_fonts/google_fonts.dart';

Expand Down Expand Up @@ -383,7 +383,7 @@ class DocKindChip extends StatelessWidget {
}

/// Read-only viewer for a document with version history and "Request
/// review" action. Inline markdown renders through flutter_markdown;
/// review" action. Inline markdown renders through flutter_markdown_plus;
/// artifact-backed docs show a placeholder pointer since the bytes live
/// on the host (blueprint §6.7: metadata in hub, bytes stay put).
class DocumentDetailScreen extends ConsumerStatefulWidget {
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/projects/reviews_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:google_fonts/google_fonts.dart';

Expand Down
2 changes: 1 addition & 1 deletion lib/screens/projects/runs_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:convert';
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:url_launcher/url_launcher.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/projects/task_detail_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:google_fonts/google_fonts.dart';

Expand Down
2 changes: 1 addition & 1 deletion lib/screens/projects/task_edit_sheet.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:google_fonts/google_fonts.dart';

Expand Down
2 changes: 1 addition & 1 deletion lib/screens/team/templates_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:termipod/l10n/app_localizations.dart';
Expand Down
31 changes: 20 additions & 11 deletions lib/widgets/markdown_builders.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// module is the single home for code-fence highlighting, LaTeX inline
// syntaxes, math element rendering, and the multiline-math
// preprocessor that flatten-fixes well-formed `$$...$$` and `\[...\]`
// regions before flutter_markdown sees them.
// regions before flutter_markdown_plus sees them.
//
// Names dropped their underscore prefix on extraction (this codebase
// does not use Dart `part`-of files; symbols moving across files have
Expand All @@ -14,7 +14,7 @@ import 'package:termipod/l10n/app_localizations.dart';
import 'package:flutter_highlight/flutter_highlight.dart';
import 'package:flutter_highlight/themes/atom-one-dark.dart';
import 'package:flutter_highlight/themes/atom-one-light.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
import 'package:flutter_math_fork/flutter_math.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:markdown/markdown.dart' as md;
Expand All @@ -23,22 +23,31 @@ import 'package:url_launcher/url_launcher.dart';
import '../theme/design_colors.dart';

/// MarkdownElementBuilder that swaps `<pre><code class="language-X">` blocks
/// out for a syntax-highlighted view. Inline `<code>` (no class attribute)
/// returns null so flutter_markdown falls back to its own monochrome
/// styleSheet rendering — we only want the heavy treatment on fenced
/// blocks where the language is declared. Fenced blocks without a
/// language (just ``` ```) get a plaintext highlight (no colors), which
/// still picks up the themed background + padding so the block visually
/// stands out from prose.
/// out for a syntax-highlighted view.
///
/// A `code` element reaches the highlighter ONLY when it carries a
/// `language-` class, which the `markdown` package adds only when the fence
/// declares an info string. Everything else returns null and falls through to
/// flutter_markdown_plus's own styleSheet rendering:
///
/// * **inline** `` `code` `` — monochrome, in the `code` text style;
/// * **a bare fence** (just ``` ```) — the `codeblockDecoration` box, so it
/// still reads as a code block, just without tokenizing.
///
/// The doc here previously claimed a bare fence got a *plaintext highlight*
/// via `class="language-"`. It never did, under either renderer — the class is
/// simply absent (markdown ≥0.10.0, "if a language is provided, it is added as
/// a class"). Pinned now by markdown_plus_behaviour_test so the claim and the
/// behaviour can't drift apart again.
class HighlightedCodeBuilder extends MarkdownElementBuilder {
final bool isDark;
HighlightedCodeBuilder({required this.isDark});

@override
Widget? visitElementAfter(md.Element element, TextStyle? preferredStyle) {
final classAttr = element.attributes['class'] ?? '';
// Inline `<code>` has no class — let the base styleSheet handle it.
// Fenced blocks always get a class even with no language ("language-").
// No `language-` class ⇒ inline code, or a fence with no info string.
// Both belong to the styleSheet (see the class doc).
if (!classAttr.startsWith('language-')) return null;
var language = classAttr.substring('language-'.length).trim();
// flutter_highlight expects a known id or 'plaintext'; an unknown id
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/markdown_section_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import '../theme/tokens.dart';
/// W5a — Basic markdown editor used by the Section Detail screen for
/// manual edits. Textarea + simple toolbar (H1/H2/H3 / list / link /
/// code block) per A4 §5.6 — explicitly NOT a rich editor; the
/// underlying body is plain markdown that flutter_markdown renders on
/// underlying body is plain markdown that flutter_markdown_plus renders on
/// the read path.
///
/// Returns the saved body via Navigator.pop, or `null` on cancel.
Expand Down
4 changes: 2 additions & 2 deletions lib/widgets/transcript/event_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'dart:math' as math;

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:markdown/markdown.dart' as md;

Expand Down Expand Up @@ -785,7 +785,7 @@ class AgentEventCard extends StatefulWidget {
// Tap on `[text](href)` opens the URL in the system browser.
// Underline + primary color come from styleSheet.a below; we
// intentionally don't register a custom 'a' element builder,
// because flutter_markdown appends the builder's widget *after*
// because flutter_markdown_plus appends the builder's widget *after*
// the default styled inline span — registering one renders the
// visible label twice (once colored-underlined, once tappable).
onTapLink: (text, href, title) => openMarkdownLink(ctx, href),
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/transcript/interaction_cards.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:google_fonts/google_fonts.dart';

Expand Down
13 changes: 9 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,17 @@ dependencies:
# Public Downloads on Android via MediaStore (no-op on iOS).
# iOS uses Info.plist UIFileSharingEnabled instead.
media_store_plus: ^0.1.3
# Markdown rendering for Docs viewer in hub project detail
flutter_markdown: ^0.7.4
# Markdown rendering for the transcript, docs viewer and project detail.
# flutter_markdown was DISCONTINUED by the Flutter team (pub.dev,
# 2025-05-30); flutter_markdown_plus is its maintained continuation from
# Foresight Mobile, API-identical for everything we use (MarkdownBody,
# MarkdownElementBuilder, the `builders` map, MarkdownStyleSheet).
flutter_markdown_plus: ^1.0.12
# Direct markdown parser dep (also pulled in transitively by
# flutter_markdown) — used to type custom MarkdownElementBuilder
# flutter_markdown_plus) — used to type custom MarkdownElementBuilder
# closures that override fenced-code rendering with syntax highlights.
markdown: ^7.2.2
# Tracks what flutter_markdown_plus resolves.
markdown: ^7.3.1
# Syntax highlighting for fenced code blocks in agent transcripts.
# Static highlight.js port; covers ~190 languages with built-in themes.
flutter_highlight: ^0.7.0
Expand Down
117 changes: 117 additions & 0 deletions test/widgets/markdown_plus_behaviour_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import 'package:flutter/material.dart';
import 'package:flutter_highlight/flutter_highlight.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:termipod/widgets/transcript/event_card.dart';

import '../helpers/test_helpers.dart';

// Transcript P5 B3 — the two behaviours the migration to
// flutter_markdown_plus had to preserve (plan §4).
//
// The plan listed both as "verify on device". They are cheaper and more durable
// as assertions: a renderer swap that quietly changed either would otherwise be
// caught only by someone noticing a duplicated link label months later. Both
// are properties of the RENDERER, not of our code, so they are equally a
// regression net for the next version bump.

/// Every rendered character on screen, in one string.
String renderedText(WidgetTester tester) {
final buf = StringBuffer();
for (final w in tester.allWidgets) {
if (w is SelectableText) {
buf.write(w.data ?? w.textSpan?.toPlainText() ?? '');
} else if (w is Text) {
buf.write(w.data ?? w.textSpan?.toPlainText() ?? '');
}
}
return buf.toString();
}

int occurrences(String haystack, String needle) {
var n = 0;
var i = haystack.indexOf(needle);
while (i >= 0) {
n++;
i = haystack.indexOf(needle, i + needle.length);
}
return n;
}

Map<String, dynamic> textEvent(String text) => {
'id': 'e1',
'seq': 1,
'kind': 'text',
'producer': 'agent',
'ts': '2026-07-29T10:00:00Z',
'payload': {'text': text},
};

Future<void> pumpCard(WidgetTester tester, String markdown) async {
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: testLocalizationsDelegates,
supportedLocales: testSupportedLocales,
home: Scaffold(
body: SizedBox(
width: 420,
child: SingleChildScrollView(child: AgentEventCard(event: textEvent(markdown))),
),
),
),
);
await tester.pumpAndSettle();
}

void main() {
testWidgets('a link label renders once, not twice', (tester) async {
// We deliberately do NOT register an `a` element builder: the renderer
// appends a builder's widget AFTER its own styled inline span, so a custom
// one draws the label twice (once coloured+underlined, once tappable).
// That workaround is only correct while the append semantics hold — if a
// future version stops appending, the link would silently lose its style
// instead of doubling, and this test is what notices.
await pumpCard(tester, 'See [the docs](https://example.com) for more.');
final text = renderedText(tester);
expect(occurrences(text, 'the docs'), 1,
reason: 'link label duplicated — the `a` builder-append assumption changed');
expect(text, contains('See '));
expect(text, contains(' for more.'));
});

testWidgets('inline code falls through to the styleSheet, not the highlighter',
(tester) async {
// HighlightedCodeBuilder returns null unless the element carries a
// `language-` class, which only fenced blocks get. Inline code must reach
// the styleSheet's mono `code` style instead — if the renderer started
// tagging inline code with a class, every `foo` in prose would become a
// full highlight.js block.
await pumpCard(tester, 'Call `resolveToolAnchor` before folding.');
expect(find.byType(HighlightView), findsNothing);
expect(renderedText(tester), contains('resolveToolAnchor'));
});

testWidgets('a fenced block with a language still reaches the highlighter',
(tester) async {
// The positive control for the test above: without it, "no HighlightView"
// would pass just as well if the builder had stopped being wired at all.
await pumpCard(tester, 'Code:\n\n```dart\nvoid main() {}\n```\n');
expect(find.byType(HighlightView), findsOneWidget);
});

testWidgets('a fenced block with no language does NOT reach the highlighter',
(tester) async {
// Written first as `findsOneWidget`, on the strength of a doc comment in
// markdown_builders.dart claiming a bare fence got a plaintext highlight
// via `class="language-"`. It fails — and an A/B probe against the
// pre-migration renderer showed it fails there too, so the claim was never
// true under either. The `markdown` package adds the class only when the
// fence declares an info string (≥0.10.0).
//
// The block is still rendered as a code block, through the styleSheet's
// codeblockDecoration. Pinned here so the comment and the behaviour cannot
// drift apart again.
await pumpCard(tester, 'Code:\n\n```\nplain text block\n```\n');
expect(find.byType(HighlightView), findsNothing);
expect(renderedText(tester), contains('plain text block'));
});
}
12 changes: 6 additions & 6 deletions test/widgets/streaming_markdown_cache_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:termipod/widgets/transcript/event_card.dart';
import 'package:termipod/widgets/transcript/streaming_markdown.dart';
Expand Down Expand Up @@ -52,7 +52,7 @@ class _HarnessState extends State<_Harness> {

/// Pumps the harness and discards the build from its initial empty text, so a
/// test asserts only on the chunks it drives.
Future<_HarnessState> boot(WidgetTester tester, List<String> built) async {
Future<_HarnessState> _boot(WidgetTester tester, List<String> built) async {
await tester.pumpWidget(_Harness(built: built));
built.clear();
return tester.state<_HarnessState>(find.byType(_Harness));
Expand Down Expand Up @@ -84,7 +84,7 @@ void main() {
testWidgets('a settled block is built once, however many chunks follow',
(tester) async {
final built = <String>[];
final state = await boot(tester, built);
final state = await _boot(tester, built);

state.grow('Alpha.\n\nBeta.\n\ntail one');
await tester.pump();
Expand All @@ -105,7 +105,7 @@ void main() {
testWidgets('a completed tail is parsed once more, then never again',
(tester) async {
final built = <String>[];
final state = await boot(tester, built);
final state = await _boot(tester, built);

state.grow('Alpha.\n\ntail');
await tester.pump();
Expand All @@ -127,7 +127,7 @@ void main() {
// Otherwise a theme flip mid-turn would leave settled blocks in the old
// colours — cached widgets carry their styling with them.
final built = <String>[];
final state = await boot(tester, built);
final state = await _boot(tester, built);

state.grow('Alpha.\n\nBeta.\n\ntail');
await tester.pump();
Expand All @@ -140,7 +140,7 @@ void main() {

testWidgets('text with no safe boundary renders as one body', (tester) async {
final built = <String>[];
final state = await boot(tester, built);
final state = await _boot(tester, built);

// A list is atomic — no cut is safe anywhere in it.
const src = '- alpha\n\n- beta\n\n- gamma';
Expand Down
Loading