flutter_html
flutter_html copied to clipboard
[QUESTION]Indent the first line of a paragraph in an article
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 ' ' but it didn't work.
I am using flutter_ html: ^ 3.0.0-beta. 2
That would be the CSS text-indent property, which isn't currently supported. Could be implemented though
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 $content</p>';
},
);