Showing
3 changed files
with
29 additions
and
21 deletions
@@ -63,7 +63,7 @@ class OrderedListView extends StatelessWidget { | @@ -63,7 +63,7 @@ class OrderedListView extends StatelessWidget { | ||
63 | const OrderedListView( | 63 | const OrderedListView( |
64 | {super.key, | 64 | {super.key, |
65 | this.spacing = 6, | 65 | this.spacing = 6, |
66 | - this.padding = 10, | 66 | + this.padding = 6, |
67 | TextStyle? style, | 67 | TextStyle? style, |
68 | required this.child, | 68 | required this.child, |
69 | this.textDirection = TextDirection.ltr, | 69 | this.textDirection = TextDirection.ltr, |
@@ -5,6 +5,8 @@ abstract class MarkdownComponent { | @@ -5,6 +5,8 @@ abstract class MarkdownComponent { | ||
5 | static final List<MarkdownComponent> components = [ | 5 | static final List<MarkdownComponent> components = [ |
6 | CodeBlockMd(), | 6 | CodeBlockMd(), |
7 | NewLines(), | 7 | NewLines(), |
8 | + // IndentMd(), | ||
9 | + ImageMd(), | ||
8 | TableMd(), | 10 | TableMd(), |
9 | HTag(), | 11 | HTag(), |
10 | UnOrderedList(), | 12 | UnOrderedList(), |
@@ -13,7 +15,6 @@ abstract class MarkdownComponent { | @@ -13,7 +15,6 @@ abstract class MarkdownComponent { | ||
13 | CheckBoxMd(), | 15 | CheckBoxMd(), |
14 | HrLine(), | 16 | HrLine(), |
15 | LatexMathMultiLine(), | 17 | LatexMathMultiLine(), |
16 | - IndentMd(), | ||
17 | LatexMath(), | 18 | LatexMath(), |
18 | ImageMd(), | 19 | ImageMd(), |
19 | HighlightedText(), | 20 | HighlightedText(), |
@@ -306,8 +307,11 @@ class RadioButtonMd extends BlockMd { | @@ -306,8 +307,11 @@ class RadioButtonMd extends BlockMd { | ||
306 | /// Indent | 307 | /// Indent |
307 | class IndentMd extends InlineMd { | 308 | class IndentMd extends InlineMd { |
308 | @override | 309 | @override |
310 | + bool get inline => false; | ||
311 | + @override | ||
309 | RegExp get exp => | 312 | RegExp get exp => |
310 | - RegExp(r"^(\ +)(((?!(\n\n|\n\ )).)+)$", dotAll: true, multiLine: true); | 313 | + // RegExp(r"(?<=\n\n)(\ +)(.+?)(?=\n\n)", dotAll: true, multiLine: true); |
314 | + RegExp(r"(?:\n\n+)^(\ *)(.+?)$(?:\n\n+)", dotAll: true, multiLine: true); | ||
311 | 315 | ||
312 | @override | 316 | @override |
313 | InlineSpan span( | 317 | InlineSpan span( |
@@ -318,7 +322,8 @@ class IndentMd extends InlineMd { | @@ -318,7 +322,8 @@ class IndentMd extends InlineMd { | ||
318 | var match = exp.firstMatch(text); | 322 | var match = exp.firstMatch(text); |
319 | int spaces = (match?[1] ?? "").length; | 323 | int spaces = (match?[1] ?? "").length; |
320 | var data = "${match?[2]}".trim(); | 324 | var data = "${match?[2]}".trim(); |
321 | - data = data.replaceAll(RegExp(r'\n\ {' '$spaces' '}'), '\n').trim(); | 325 | + // data = data.replaceAll(RegExp(r'\n\ {' '$spaces' '}'), '\n').trim(); |
326 | + data = data.trim(); | ||
322 | var child = TextSpan( | 327 | var child = TextSpan( |
323 | children: MarkdownComponent.generate( | 328 | children: MarkdownComponent.generate( |
324 | context, | 329 | context, |
@@ -326,19 +331,24 @@ class IndentMd extends InlineMd { | @@ -326,19 +331,24 @@ class IndentMd extends InlineMd { | ||
326 | config, | 331 | config, |
327 | ), | 332 | ), |
328 | ); | 333 | ); |
334 | + var leftPadding = 20.0; | ||
329 | if (spaces < 4) { | 335 | if (spaces < 4) { |
330 | - return child; | 336 | + leftPadding = 0; |
331 | } | 337 | } |
338 | + var padding = config.style?.fontSize ?? 16.0; | ||
332 | return TextSpan( | 339 | return TextSpan( |
333 | children: [ | 340 | children: [ |
334 | WidgetSpan( | 341 | WidgetSpan( |
335 | - child: Row( | ||
336 | - children: [ | ||
337 | - const SizedBox( | ||
338 | - width: 20, | ||
339 | - ), | ||
340 | - Expanded(child: config.getRich(child)), | ||
341 | - ], | 342 | + child: Padding( |
343 | + padding: EdgeInsets.symmetric(vertical: padding), | ||
344 | + child: Row( | ||
345 | + children: [ | ||
346 | + SizedBox( | ||
347 | + width: leftPadding, | ||
348 | + ), | ||
349 | + Expanded(child: config.getRich(child)), | ||
350 | + ], | ||
351 | + ), | ||
342 | ), | 352 | ), |
343 | ), | 353 | ), |
344 | ], | 354 | ], |
@@ -350,7 +360,6 @@ class IndentMd extends InlineMd { | @@ -350,7 +360,6 @@ class IndentMd extends InlineMd { | ||
350 | class UnOrderedList extends BlockMd { | 360 | class UnOrderedList extends BlockMd { |
351 | @override | 361 | @override |
352 | String get expString => (r"(?:\-|\*)\ ([^\n]+)$"); | 362 | String get expString => (r"(?:\-|\*)\ ([^\n]+)$"); |
353 | - get onLinkTab => null; | ||
354 | 363 | ||
355 | @override | 364 | @override |
356 | Widget build( | 365 | Widget build( |
@@ -361,9 +370,10 @@ class UnOrderedList extends BlockMd { | @@ -361,9 +370,10 @@ class UnOrderedList extends BlockMd { | ||
361 | var match = this.exp.firstMatch(text); | 370 | var match = this.exp.firstMatch(text); |
362 | return UnorderedListView( | 371 | return UnorderedListView( |
363 | bulletColor: | 372 | bulletColor: |
364 | - config.style?.color ?? DefaultTextStyle.of(context).style.color, | ||
365 | - padding: 10.0, | ||
366 | - bulletSize: 0.4 * | 373 | + (config.style?.color ?? DefaultTextStyle.of(context).style.color), |
374 | + padding: 7, | ||
375 | + spacing: 10, | ||
376 | + bulletSize: 0.3 * | ||
367 | (config.style?.fontSize ?? | 377 | (config.style?.fontSize ?? |
368 | DefaultTextStyle.of(context).style.fontSize ?? | 378 | DefaultTextStyle.of(context).style.fontSize ?? |
369 | kDefaultFontSize), | 379 | kDefaultFontSize), |
@@ -381,8 +391,6 @@ class OrderedList extends BlockMd { | @@ -381,8 +391,6 @@ class OrderedList extends BlockMd { | ||
381 | @override | 391 | @override |
382 | String get expString => (r"([0-9]+\.)\ ([^\n]+)$"); | 392 | String get expString => (r"([0-9]+\.)\ ([^\n]+)$"); |
383 | 393 | ||
384 | - get onLinkTab => null; | ||
385 | - | ||
386 | @override | 394 | @override |
387 | Widget build( | 395 | Widget build( |
388 | BuildContext context, | 396 | BuildContext context, |
@@ -701,7 +709,7 @@ class SourceTag extends InlineMd { | @@ -701,7 +709,7 @@ class SourceTag extends InlineMd { | ||
701 | /// Link text component | 709 | /// Link text component |
702 | class ATagMd extends InlineMd { | 710 | class ATagMd extends InlineMd { |
703 | @override | 711 | @override |
704 | - RegExp get exp => RegExp(r"\[([^\s\*][^\n]*?[^\s]?)?\]\(([^\s\*]+?)?\)"); | 712 | + RegExp get exp => RegExp(r"\[([^\s\*\[][^\n]*?[^\s]?)?\]\(([^\s\*]*[^\)])\)"); |
705 | 713 | ||
706 | @override | 714 | @override |
707 | InlineSpan span( | 715 | InlineSpan span( |
@@ -721,7 +729,7 @@ class ATagMd extends InlineMd { | @@ -721,7 +729,7 @@ class ATagMd extends InlineMd { | ||
721 | onPressed: () { | 729 | onPressed: () { |
722 | config.onLinkTab?.call("${match?[2]}", "${match?[1]}"); | 730 | config.onLinkTab?.call("${match?[2]}", "${match?[1]}"); |
723 | }, | 731 | }, |
724 | - text: "${match?[1]}", | 732 | + text: match?[1] ?? "", |
725 | config: config, | 733 | config: config, |
726 | ), | 734 | ), |
727 | ); | 735 | ); |
-
Please register or login to post a comment