markdown_widget
markdown_widget copied to clipboard
Align text to center
Hi,
First I want to thank you for this great package!
I noted that the text align seems no longer to be available with the new package version.
With the old version (1.XX.XX)
I was able to center my markdown text using:
pConfig: PConfig(
textConfig: TextConfig(textAlign: textAlign),
),
I don't see this option with the package version 2.1.10
.
Did I miss something ?
Thanks in advance!
Hi @NicolasLaube There is indeed no option to set the TextAlign
in markdown_widget 2.x.x
, as it would result in the rendered markdown looking strange.
However, if you do want to try this parameter, you can refer to writing a custom ParagraphNode
, and in the build()
method, return the following code.
SpanNodeGeneratorWithTag(
tag: MarkdownTag.p.name, generator: (e, config, visitor) => YourParagraphNode (config.p));
class YourParagraphNode extends ElementNode {
final PConfig pConfig;
YourParagraphNode (this.pConfig);
@override
InlineSpan build() {
return WidgetSpan(child: Text.rich(TextSpan(
children: List.generate(children.length, (index) {
final child = children[index];
return child.build();
})), textAlign: TextAlign.center,));
}
}
then pass the SpanNodeGeneratorWithTag
to MarkdownGeneratorConfig generators
Ok, thank you for your help!
Hi ! I also want to thank you for your work !
Your solution works well for centering simple text, but not with latex elements containing simple text. (Based on this file: https://github.com/asjqkkkk/markdown_widget/blob/dev/example/lib/markdown_custom/latex.dart)
I tried to mix the two codes, but I can't do it.
Is there a way to center the latex content even without the $$
sign?
Thanks in advance :)
Hi @xdidx , I currently have no relatively complete method for filting true LaTeX expressions from ordinary text, so I am preparing to file an issue with flutter_math_fork to see if they can address this problem.
Ok thanks, and maybe the MarkdownWidget can take only the width needed for the text if it is short, in order to center the whole MarkdownWidget?
@xdidx you can use MarkdownBlock
widget
It works well, thanks !