flutter_html icon indicating copy to clipboard operation
flutter_html copied to clipboard

[QUESTION]Indent the first line of a paragraph in an article

Open qadan72 opened this issue 1 year ago • 2 comments

May I ask how to solve the issue of indentation at the beginning of paragraphs in the latest version? For example, in a paragraph with 7 lines, the first line needs to be indented by 2 spaces. I tried using '&nbsp' but it didn't work.

I am using flutter_ html: ^ 3.0.0-beta. 2

qadan72 avatar Sep 16 '24 15:09 qadan72

That would be the CSS text-indent property, which isn't currently supported. Could be implemented though

Sub6Resources avatar Mar 12 '25 02:03 Sub6Resources

Post unsuccessfully trying to create the textIndent prop in Style, this hacky workaround might be helpful. Inject a non-stripable space and whitespace into the start of each p block. This is the only way I found that doesn't affect line height.

    final raw = _chapters[idx];
    int paragraphIndex = 0;
    final patched = raw.replaceAllMapped(
      RegExp(r'<p[^>]*>(.*?)</p>', dotAll: true),
      (match) {
        final content = (match[1] ?? '').trim();
        paragraphIndex++;
        if (paragraphIndex == 1) return '<p>$content</p>';
        return '<p>\u200B&nbsp;&nbsp;$content</p>';
      },
    );

Image

yohanderose avatar May 29 '25 06:05 yohanderose