Skip to content
Open
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
4 changes: 4 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:adaptive_platform_ui/adaptive_platform_ui.dart';
import 'package:flutter_driver/driver_extension.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:pdfrx/pdfrx.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'core/widgets/error_boundary.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
Expand Down Expand Up @@ -71,6 +72,9 @@ void main() {
runZonedGuarded(
() async {
WidgetsFlutterBinding.ensureInitialized();
// pdfrx: warm up the PDFium engine once at startup so the inline PDF
// viewer opens without a first-use delay.
unawaited(pdfrxFlutterInitialize());
PerformanceProfiler.instance.attachFrameTimings();

// Global error handlers
Expand Down
19 changes: 19 additions & 0 deletions lib/shared/widgets/markdown/renderer/inline_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import '../compiled_markdown_document.dart';
import '../citation_badge.dart';
import 'latex_preprocessor.dart';
import 'markdown_style.dart';
import 'pdf_inline_view.dart';

/// Callback invoked when a user taps a markdown link.
typedef LinkTapCallback = void Function(String url, String title);
Expand Down Expand Up @@ -336,6 +337,24 @@ class InlineRenderer {
) {
final href = element.attributes['href'] ?? '';
final title = element.attributes['title'] ?? '';

// Links to a PDF (a URL ending in .pdf) render as an inline PDF preview card
// with tap-to-fullscreen, instead of a plain tappable hyperlink. Works in
// every render tier because both richText and blocks route `<a>` elements
// through this method.
if (PdfInlineView.isPdfLink(href)) {
return [
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: PdfInlineView(
key: ValueKey(href),
url: href,
label: element.textContent,
),
),
];
}

final linkStyle = currentStyle.copyWith(
color: style.linkColor,
decoration: TextDecoration.underline,
Expand Down
Loading