Skip to content

MarkdownBody displays whitespace in lists, even though it should be ignored #134847

@krozett

Description

@krozett

Is there an existing issue for this?

Steps to reproduce

Markdown normally ignores whitespace, except for having two spaces at the end of a line of text to indicate a line break. This widget behaves well in most cases, ignoring whitespace at the beginning of paragraphs, unless there's 4 or more spaces to indicate a blockquote.

I confirmed this using several different Markdown editors.

To reproduce:

  1. Put multiple spaces between the list character (* or 1. or what have you) and the text value.
  2. You'll see that the whitespace is displayed as part of the text element. I gave the text a teal background to make it more obvious.

Clearly MardownBody is trimming text in other places, so it's probably just an oversight on this particular element type.

Expected results

A screenshot I took from the Dart Markdown Live Editor:

Screenshot 2023-09-15 at 16 48 31

Actual results

DBD32614-7069-44FB-A18B-4BBB1CD91847_1_201_a

Android looks the same, so I didn't bother with a screenshot.

Code sample

Code sample
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Rich Text Demo',
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Markdown Test'),
        ),
        body: MarkdownBody(
          data: '1. one space\n2.  two spaces\n3.   three spaces\n\n- one space\n-  two spaces\n-   three spaces',
          styleSheet: MarkdownStyleSheet(
            p: const TextStyle(
              backgroundColor: Colors.tealAccent,
            ),
          ),
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.13.3, on macOS 13.5.2 22G91 darwin-arm64, locale en-US)
    • Flutter version 3.13.3 on channel stable at /Users/keithrozett/Projects/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2524052335 (9 days ago), 2023-09-06 14:32:31 -0700
    • Engine revision b8d35810e9
    • Dart version 3.1.1
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/keithrozett/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] Connected device (3 available)
    • Keith’s iPhone (mobile) • 00008110-001C71610121401E • ios            • iOS 16.6.1 20G81
    • macOS (desktop)         • macos                     • darwin-arm64   • macOS 13.5.2 22G91 darwin-arm64
    • Chrome (web)            • chrome                    • web-javascript • Google Chrome 116.0.5845.187

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 3.13Found to occur in 3.13found in release: 3.14Found to occur in 3.14has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: flutter_markdownflutter/packages flutter_markdownpackageflutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer versionteam-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions