Skip to content

Commit de77496

Browse files
authored
feat: migrate figure and captioned images to jaspr (#12586)
Part of #12548 Migrates both the `app-figure.md` and `captioned-image.md` files to a `DashImage` Jaspr component.
1 parent 6d5d1c3 commit de77496

File tree

28 files changed

+181
-140
lines changed

28 files changed

+181
-140
lines changed

site/lib/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'jaspr_options.dart'; // Generated. Do not remove or edit.
1111
import 'src/components/card.dart';
1212
import 'src/components/client/archive_table.dart';
1313
import 'src/components/client/download_latest_button.dart';
14+
import 'src/components/dash_image.dart';
1415
import 'src/components/expansion_list.dart';
1516
import 'src/components/os_selector.dart';
1617
import 'src/components/pages/devtools_release_notes_index.dart';
@@ -71,6 +72,7 @@ final RegExp _passThroughPattern = RegExp(r'.*\.(txt|json|pdf)$');
7172
/// Custom "components" that can be used from Markdown files.
7273
List<CustomComponent> get _embeddableComponents => [
7374
const DashTabs(),
75+
const DashImage(),
7476
CustomComponent(
7577
pattern: RegExp('OSSelector', caseSensitive: false),
7678
builder: (name, attributes, child) {
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2025 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:jaspr/jaspr.dart';
6+
import 'package:jaspr_content/jaspr_content.dart';
7+
8+
import '../markdown/markdown_parser.dart';
9+
10+
class DashImage with CustomComponentBase {
11+
const DashImage();
12+
13+
@override
14+
Pattern get pattern => RegExp('DashImage', caseSensitive: false);
15+
16+
@override
17+
Component apply(_, Map<String, String> attributes, _) {
18+
final isFigure = attributes.containsKey('figure');
19+
final imgSrc =
20+
attributes['image'] ??
21+
(throw Exception(
22+
'<DashImage> component requires an "image" attribute.',
23+
));
24+
25+
final caption = attributes['caption'] ?? '';
26+
final alt = attributes['alt'] ?? caption;
27+
28+
final figureClass = isFigure ? attributes['class'] : null;
29+
final imgClass = attributes[isFigure ? 'img-class' : 'class'];
30+
31+
final style = [
32+
if (attributes['img-style'] case final s?) s,
33+
if (attributes['width'] case final w?) 'width: $w',
34+
if (attributes['height'] case final h?) 'height: $h',
35+
].map((s) => s.trim()).map((s) => s.endsWith(';') ? s : '$s;').join(' ');
36+
37+
final child = Component.fragment([
38+
img(
39+
src: '/assets/images/docs/$imgSrc',
40+
alt: alt,
41+
classes: imgClass,
42+
attributes: {
43+
if (style.isNotEmpty) 'style': style,
44+
},
45+
),
46+
if (caption.isNotEmpty)
47+
figcaption(classes: 'figure-caption', [
48+
DashMarkdown(content: caption),
49+
]),
50+
]);
51+
52+
if (isFigure) {
53+
return figure(classes: figureClass, [
54+
div(classes: 'site-figure-container', [
55+
child,
56+
]),
57+
]);
58+
}
59+
60+
return child;
61+
}
62+
}

src/_includes/docs/add-to-app/ios-project/link-and-embed.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ To link the necessary frameworks, follow this procedure.
1818

1919
1. Expand **Link Binary With Libraries**.
2020

21-
{% render "docs/captioned-image.md", image:"development/add-to-app/ios/project-setup/linked-libraries.png", caption:"Expand the **Link Binary With Libraries** build phase in Xcode" %}
21+
<DashImage image="development/add-to-app/ios/project-setup/linked-libraries.png" caption="Expand the **Link Binary With Libraries** build phase in Xcode" />
2222

2323
1. Click **+** (plus sign).
2424

@@ -29,7 +29,7 @@ To link the necessary frameworks, follow this procedure.
2929

3030
1. Command-click the frameworks in that directory then click **Open**.
3131

32-
{% render "docs/captioned-image.md", image:"development/add-to-app/ios/project-setup/choose-libraries.png", caption:"Choose frameworks to link from the **Choose frameworks and libraries to add:** dialog box in Xcode" %}
32+
<DashImage image="development/add-to-app/ios/project-setup/choose-libraries.png" caption="Choose frameworks to link from the **Choose frameworks and libraries to add:** dialog box in Xcode" />
3333

3434
1. Update the paths to the libraries to account for build modes.
3535

@@ -43,7 +43,7 @@ To link the necessary frameworks, follow this procedure.
4343
1. Open `project.pbxproj` with Xcode. The file opens in Xcode's text
4444
editor. This also locks **Project Navigator** until you close the text editor.
4545

46-
{% render "docs/captioned-image.md", image:"development/add-to-app/ios/project-setup/project-pbxproj.png", caption:"The `project-pbxproj` file open in the Xcode text editor" %}
46+
<DashImage image="development/add-to-app/ios/project-setup/project-pbxproj.png" caption="The `project-pbxproj` file open in the Xcode text editor" />
4747

4848
1. Find the lines that resemble the following text in the
4949
`/* Begin PBXFileReference section */`.
@@ -106,7 +106,7 @@ To link the necessary frameworks, follow this procedure.
106106
1. Type `$(PROJECT_DIR)/Flutter/$(CONFIGURATION)/`
107107
and press <kbd>Enter</kbd>.
108108
109-
{% render "docs/captioned-image.md", image:"development/add-to-app/ios/project-setup/framework-search-paths.png", caption:"Update **Framework Search Paths** in Xcode" %}
109+
<DashImage image="development/add-to-app/ios/project-setup/framework-search-paths.png" caption="Update **Framework Search Paths** in Xcode" />
110110
111111
After linking the frameworks, they should display in the
112112
**Frameworks, Libraries, and Embedded Content**
@@ -121,7 +121,7 @@ To embed your dynamic frameworks, complete the following procedure.
121121
122122
1. Click on each of your dynamic frameworks and select **Embed & Sign**.
123123
124-
{% render "docs/captioned-image.md", image:"development/add-to-app/ios/project-setup/choose-to-embed.png", caption:"Select **Embed & Sign** for each of your frameworks in Xcode" %}
124+
<DashImage image="development/add-to-app/ios/project-setup/choose-to-embed.png" caption="Select **Embed & Sign** for each of your frameworks in Xcode" />
125125
126126
Don't include any static frameworks,
127127
including `FlutterPluginRegistrant.xcframework`.
@@ -131,7 +131,7 @@ To embed your dynamic frameworks, complete the following procedure.
131131
1. Expand **Embed Frameworks**.
132132
Your dynamic frameworks should display in that section.
133133
134-
{% render "docs/captioned-image.md", image:"development/add-to-app/ios/project-setup/embed-xcode.png", caption:"The expanded **Embed Frameworks** build phase in Xcode" %}
134+
<DashImage image="development/add-to-app/ios/project-setup/embed-xcode.png" caption="The expanded **Embed Frameworks** build phase in Xcode" />
135135
136136
1. Build the project.
137137

src/_includes/docs/app-figure.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/_includes/docs/captioned-image.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/_includes/docs/swift-package-manager/migrate-ios-project-manually.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ the following files in your issue:
2222
1. Open your app (`ios/Runner.xcworkspace`) in Xcode.
2323
1. Navigate to **Package Dependencies** for the project.
2424

25-
{% render "docs/captioned-image.md", image:"development/packages-and-plugins/swift-package-manager/package-dependencies.png", caption:"The project's package dependencies" %}
25+
<DashImage image="development/packages-and-plugins/swift-package-manager/package-dependencies.png" caption="The project's package dependencies" />
2626

2727
1. Click <span class="material-symbols" translate="no">add</span>.
2828
1. In the dialog that opens, click **Add Local...**.
2929
1. Navigate to `ios/Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage`
3030
and click **Add Package**.
3131
1. Ensure that it's added to the `Runner` target and click **Add Package**.
3232

33-
{% render "docs/captioned-image.md", image:"development/packages-and-plugins/swift-package-manager/choose-package-products.png", caption:"Ensure that the package is added to the `Runner` target" %}
33+
<DashImage image="development/packages-and-plugins/swift-package-manager/choose-package-products.png" caption="Ensure that the package is added to the `Runner` target" />
3434

3535
1. Ensure that `FlutterGeneratedPluginSwiftPackage` was added to **Frameworks,
3636
Libraries, and Embedded Content**.
3737

38-
{% render "docs/captioned-image.md", image:"development/packages-and-plugins/swift-package-manager/add-generated-framework.png", caption:"Ensure that `FlutterGeneratedPluginSwiftPackage` was added to **Frameworks, Libraries, and Embedded Content**" %}
38+
<DashImage image="development/packages-and-plugins/swift-package-manager/add-generated-framework.png" caption="Ensure that `FlutterGeneratedPluginSwiftPackage` was added to **Frameworks, Libraries, and Embedded Content**" />
3939

4040
### Step 2: Add Run Prepare Flutter Framework Script Pre-Action {:.no_toc}
4141

@@ -59,15 +59,15 @@ the following files in your issue:
5959
"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" prepare
6060
```
6161

62-
{% render "docs/captioned-image.md", image:"development/packages-and-plugins/swift-package-manager/add-flutter-pre-action.png", caption:"Add **Run Prepare Flutter Framework Script** build pre-action" %}
62+
<DashImage image="development/packages-and-plugins/swift-package-manager/add-flutter-pre-action.png" caption="Add **Run Prepare Flutter Framework Script** build pre-action" />
6363

6464
### Step 3: Run app {:.no_toc}
6565

6666
1. Run the app in Xcode.
6767
1. Ensure that **Run Prepare Flutter Framework Script** runs as a pre-action
6868
and that `FlutterGeneratedPluginSwiftPackage` is a target dependency.
6969

70-
{% render "docs/captioned-image.md", image:"development/packages-and-plugins/swift-package-manager/flutter-pre-action-build-log.png", caption:"Ensure **Run Prepare Flutter Framework Script** runs as a pre-action" %}
70+
<DashImage image="development/packages-and-plugins/swift-package-manager/flutter-pre-action-build-log.png" caption="Ensure **Run Prepare Flutter Framework Script** runs as a pre-action" />
7171

7272
1. Ensure that the app runs on the command line with `flutter run`.
7373

src/_includes/docs/swift-package-manager/migrate-ios-project.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ To migrate your project:
3030
1. Ensure that **Run Prepare Flutter Framework Script** runs as a pre-action
3131
and that `FlutterGeneratedPluginSwiftPackage` is a target dependency.
3232

33-
{% render "docs/captioned-image.md", image:"development/packages-and-plugins/swift-package-manager/flutter-pre-action-build-log.png", caption:"Ensure **Run Prepare Flutter Framework Script** runs as a pre-action" %}
33+
<DashImage image="development/packages-and-plugins/swift-package-manager/flutter-pre-action-build-log.png" caption="Ensure **Run Prepare Flutter Framework Script** runs as a pre-action" />
3434

3535
[Turn on Swift Package Manager]: /packages-and-plugins/swift-package-manager/for-app-developers/#how-to-turn-on-swift-package-manager
3636
[manualIntegration]: /packages-and-plugins/swift-package-manager/for-app-developers/#add-to-a-flutter-app-manually

src/_includes/docs/swift-package-manager/migrate-macos-project-manually.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ the following files in your issue:
2222
1. Open your app (`macos/Runner.xcworkspace`) in Xcode.
2323
1. Navigate to **Package Dependencies** for the project.
2424

25-
{% render "docs/captioned-image.md", image:"development/packages-and-plugins/swift-package-manager/package-dependencies.png", caption:"The project's package dependencies" %}
25+
<DashImage image="development/packages-and-plugins/swift-package-manager/package-dependencies.png" caption="The project's package dependencies" />
2626

2727
1. Click <span class="material-symbols" translate="no">add</span>.
2828
1. In the dialog that opens, click the **Add Local...**.
2929
1. Navigate to `macos/Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage`
3030
and click the **Add Package**.
3131
1. Ensure that it's added to the Runner Target and click **Add Package**.
3232

33-
{% render "docs/captioned-image.md", image:"development/packages-and-plugins/swift-package-manager/choose-package-products.png", caption:"Ensure that the package is added to the `Runner` target" %}
33+
<DashImage image="development/packages-and-plugins/swift-package-manager/choose-package-products.png" caption="Ensure that the package is added to the `Runner` target" />
3434

3535
1. Ensure that `FlutterGeneratedPluginSwiftPackage` was added to **Frameworks,
3636
Libraries, and Embedded Content**.
3737

38-
{% render "docs/captioned-image.md", image:"development/packages-and-plugins/swift-package-manager/add-generated-framework.png", caption:"Ensure that `FlutterGeneratedPluginSwiftPackage` was added to **Frameworks, Libraries, and Embedded Content**" %}
38+
<DashImage image="development/packages-and-plugins/swift-package-manager/add-generated-framework.png" caption="Ensure that `FlutterGeneratedPluginSwiftPackage` was added to **Frameworks, Libraries, and Embedded Content**" />
3939

4040
### Step 2: Add Run Prepare Flutter Framework Script Pre-Action {:.no_toc}
4141

@@ -59,15 +59,15 @@ the following files in your issue:
5959
"$FLUTTER_ROOT"/packages/flutter_tools/bin/macos_assemble.sh prepare
6060
```
6161

62-
{% render "docs/captioned-image.md", image:"development/packages-and-plugins/swift-package-manager/add-flutter-pre-action.png", caption:"Add **Run Prepare Flutter Framework Script** build pre-action" %}
62+
<DashImage image="development/packages-and-plugins/swift-package-manager/add-flutter-pre-action.png" caption="Add **Run Prepare Flutter Framework Script** build pre-action" />
6363

6464
### Step 3: Run app {:.no_toc}
6565

6666
1. Run the app in Xcode.
6767
1. Ensure that **Run Prepare Flutter Framework Script** runs as a pre-action
6868
and that `FlutterGeneratedPluginSwiftPackage` is a target dependency.
6969

70-
{% render "docs/captioned-image.md", image:"development/packages-and-plugins/swift-package-manager/flutter-pre-action-build-log.png", caption:"Ensure `Run Prepare Flutter Framework Script` runs as a pre-action" %}
70+
<DashImage image="development/packages-and-plugins/swift-package-manager/flutter-pre-action-build-log.png" caption="Ensure `Run Prepare Flutter Framework Script` runs as a pre-action" />
7171

7272
1. Ensure that the app runs on the command line with `flutter run`.
7373

src/_includes/docs/swift-package-manager/migrate-macos-project.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ To migrate your project:
3030
1. Ensure that **Run Prepare Flutter Framework Script** runs as a pre-action
3131
and that `FlutterGeneratedPluginSwiftPackage` is a target dependency.
3232

33-
{% render "docs/captioned-image.md", image:"development/packages-and-plugins/swift-package-manager/flutter-pre-action-build-log.png", caption:"Ensure **Run Prepare Flutter Framework Script** runs as a pre-action" %}
33+
<DashImage image="development/packages-and-plugins/swift-package-manager/flutter-pre-action-build-log.png" caption="Ensure **Run Prepare Flutter Framework Script** runs as a pre-action" />
3434

3535
[Turn on Swift Package Manager]: /packages-and-plugins/swift-package-manager/for-app-developers/#how-to-turn-on-swift-package-manager
3636
[manualIntegration]: /packages-and-plugins/swift-package-manager/for-app-developers/#add-to-a-flutter-app-manually

src/content/add-to-app/android/project-setup.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ flutter build aar
278278

279279
Then, follow the on-screen instructions to integrate.
280280

281-
{% render "docs/app-figure.md", image:"development/add-to-app/android/project-setup/build-aar-instructions.png" %}
281+
<DashImage figure image="development/add-to-app/android/project-setup/build-aar-instructions.png" />
282282

283283
More specifically, this command creates
284284
(by default all debug/profile/release modes)
@@ -417,7 +417,7 @@ check out [Using Flutter in China][] page.
417417
You can also build an AAR for your Flutter module in Android Studio using
418418
the `Build > Flutter > Build AAR` menu.
419419
420-
{% render "docs/app-figure.md", image:"development/add-to-app/android/project-setup/ide-build-aar.png" %}
420+
<DashImage figure image="development/add-to-app/android/project-setup/ide-build-aar.png"/>
421421
:::
422422
423423
</Tab>

0 commit comments

Comments
 (0)