saminsohag

baseline for bloc type component is fixed

## 1.0.16
* `IndentMd` and `BlockQuote` fixed.
* Baseline of bloc type component is fixed.
## 1.0.15
... ...
description: This file stores settings for Dart & Flutter DevTools.
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
extensions:
... ...
description: This file stores settings for Dart & Flutter DevTools.
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
extensions:
... ...
... ... @@ -76,57 +76,216 @@ class _MyHomePageState extends State<MyHomePage> {
TextDirection _direction = TextDirection.ltr;
final TextEditingController _controller = TextEditingController(
text: r'''
## ChatGPT Response
```markdown
# Complex Markdown Document for Testing
This document is designed to **challenge** your `gpt_markdown` package by incorporating a wide variety of Markdown components including headers, lists, tables, code blocks, blockquotes, footnotes, and LaTeX math expressions.
---
## Table of Contents
1. [Headers and Emphasis](#headers-and-emphasis)
2. [Lists](#lists)
3. [Code Blocks and Inline Code](#code-blocks-and-inline-code)
4. [Tables](#tables)
5. [Blockquotes and Nested Elements](#blockquotes-and-nested-elements)
6. [Mathematical Expressions](#mathematical-expressions)
7. [Links and Images](#links-and-images)
8. [Footnotes](#footnotes)
9. [Horizontal Rules and Miscellaneous](#horizontal-rules-and-miscellaneous)
---
## Headers and Emphasis
### Header Levels
Markdown supports multiple header levels:
- `# Header 1`
- `## Header 2`
- `### Header 3`
- `#### Header 4`
- `##### Header 5`
- `###### Header 6`
### Emphasis Examples
- *Italicized text* using single asterisks or underscores.
- **Bold text** using double asterisks or underscores.
- ***Bold and italic*** by combining them.
- ~~Strikethrough~~ text using two tildes.
---
## Lists
### Unordered List
- Item 1
- Nested Item 1.1
- Nested Item 1.2
- Deeply Nested Item 1.2.1
- Item 2
- [ ] Task not completed
- [x] Task completed
### Ordered List
1. First item
2. Second item with nested list:
1. Subitem 2.1
2. Subitem 2.2
3. Third item
### Mixed List Example
- **Fruits**
1. Apple
2. Banana
3. Cherry
- **Vegetables**
- Carrot
- Lettuce
- Spinach
---
## Code Blocks and Inline Code
### Inline Code
Here is an example of inline code: `print("Hello, world!")`.
### Fenced Code Block (Python)
```python
def greet(name):
"""
Greets a person with the provided name.
"""
print(f"Hello, {name}!")
greet("Alice")
```
Welcome to ChatGPT! Below is an example of a response with Markdown and LaTeX code:
### Fenced Code Block (JavaScript)
```javascript
function greet(name) {
console.log(`Hello, ${name}!`);
}
greet("Bob");
```
### Markdown Example
---
## Tables
```
class MarkdownHelper {
Here is a table demonstrating various elements:
| Syntax | Description | Example |
| ----------- | ---------------------------------------- | --------------------------------- |
| Header | Title | **Bold Header** |
| Paragraph | Text with *italic* and **bold** elements | This is a sample paragraph. |
| Inline Code | `code snippet` | `let x = 10;` |
Map<String, Widget> getTitleWidget(m.Node node) => title.getTitleWidget(node);
Additional table with alignment:
Widget getPWidget(m.Element node) => p.getPWidget(node);
| Left Align | Center Align | Right Align |
| :--------- |:------------:| ----------:|
| Row 1 | Row 1 | Row 1 |
| Row 2 | Row 2 | Row 2 |
Widget getPreWidget(m.Node node) => pre.getPreWidget(node);
}
```
---
## Blockquotes and Nested Elements
You can use Markdown to format text easily. Here are some examples:
> **Blockquote Header**
>
> This is a blockquote. You can include **bold** and *italic* text, as well as `inline code` within blockquotes.
>
> > ### Nested Blockquote
> > - Nested list item 1
> > - Nested list item 2
> > 1. Numbered subitem 1
> > 2. Numbered subitem 2
> >
> > ```python
> > # Code snippet inside nested blockquote
> > for i in range(3):
> > print(i)
> > ```
>
> Back to the outer blockquote.
- `Highlighted Text`: `This text is highlighted`
- **Bold Text**: **This text is bold**
- *Italic Text*: *This text is italicized*
- [Link](https://www.example.com): [This is a link](https://www.example.com)
- Lists:
1. Item 1
2. Item 2
3. Item 3
---
### LaTeX Example
## Mathematical Expressions
You can also use LaTeX for mathematical expressions. Here's an example:
### Inline Math
You can write inline math using the `\( ... \)` syntax. For example, the quadratic formula is given by:
\( x = \frac{-b \pm \sqrt{b^2-4ac}}{2a} \).
- **Equation**: \( f(x) = x^2 + 2x + 1 \)
- **Integral**: \( \int_{0}^{1} x^2 \, dx \)
- **Matrix**:
### Display Math
Display math can be rendered using the `\[ ... \]` syntax. For example, consider the integral:
\[
\int_{-\infty}^{\infty} e^{-x^2} \, dx = \sqrt{\pi}
\]
More complex display equations:
\[
\begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{bmatrix}
E = mc^2 \quad \text{and} \quad F = ma
\]
### Conclusion
---
## Links and Images
### Links
Here are examples of links:
- [OpenAI](https://www.openai.com)
- [GitHub](https://github.com)
### Images
Inline images can be embedded as follows:
![Alt Text for Image](https://via.placeholder.com/150 "Image Title")
Images can also be referenced with links:
[![Linked Image](https://via.placeholder.com/100 "Thumbnail")](https://via.placeholder.com/500 "Full Image")
Markdown and LaTeX can be powerful tools for formatting text and mathematical expressions in your Flutter app. If you have any questions or need further assistance, feel free to ask!
---
## Footnotes
Here is a statement with a footnote.[^1] Another reference can be added here.[^long]
[^1]: This is a simple footnote.
[^long]: This footnote contains a longer explanation to showcase how multiple lines can be formatted in a footnote. It supports Markdown formatting such as **bold** and *italic* text.
---
## Horizontal Rules and Miscellaneous
Horizontal rules can be used to separate sections:
---
### Task List Example
- [x] Write complex Markdown document
- [x] Include LaTeX math expressions
- [ ] Add more Markdown components if needed
### Nested Quotes with Code and Math
> **Example of Nested Components**
>
> - Inline code: `sum = a + b`
> - Math expression: \( \sum_{i=1}^n i = \frac{n(n+1)}{2} \)
> - More text with **bold** formatting.
>
> ```javascript
> // JavaScript code example inside a nested blockquote
> const sum = (n) => (n * (n + 1)) / 2;
> console.log(sum(10));
> ```
---
## Conclusion
This document was created to test the robustness of Markdown parsers and to ensure that all components, including advanced LaTeX expressions and nested structures, are rendered correctly. Enjoy testing and feel free to extend it further!
```
''',
);
File? file;
... ...
... ... @@ -95,15 +95,15 @@ class GptMarkdown extends StatelessWidget {
final UnOrderedListBuilder? unOrderedListBuilder;
/// A method to remove extra lines inside block LaTeX.
String _removeExtraLinesInsideBlockLatex(String text) {
return text.replaceAllMapped(
RegExp(r"\\\[(.*?)\\\]", multiLine: true, dotAll: true),
(match) {
String content = match[0] ?? "";
return content.replaceAllMapped(RegExp(r"\n[\n\ ]+"), (match) => "\n");
},
);
}
// String _removeExtraLinesInsideBlockLatex(String text) {
// return text.replaceAllMapped(
// RegExp(r"\\\[(.*?)\\\]", multiLine: true, dotAll: true),
// (match) {
// String content = match[0] ?? "";
// return content.replaceAllMapped(RegExp(r"\n[\n\ ]+"), (match) => "\n");
// },
// );
// }
@override
Widget build(BuildContext context) {
... ... @@ -124,7 +124,7 @@ class GptMarkdown extends StatelessWidget {
},
);
}
tex = _removeExtraLinesInsideBlockLatex(tex);
// tex = _removeExtraLinesInsideBlockLatex(tex);
return ClipRRect(
child: MdWidget(
tex,
... ...
... ... @@ -2,7 +2,7 @@ part of 'gpt_markdown.dart';
/// Markdown components
abstract class MarkdownComponent {
static final List<MarkdownComponent> components = [
static List<MarkdownComponent> get components => [
CodeBlockMd(),
NewLines(),
BlockQuote(),
... ... @@ -25,7 +25,7 @@ abstract class MarkdownComponent {
IndentMd(),
];
static final List<MarkdownComponent> inlineComponents = [
static List<MarkdownComponent> get inlineComponents => [
ImageMd(),
ATagMd(),
TableMd(),
... ... @@ -68,29 +68,7 @@ abstract class MarkdownComponent {
dotAll: each.exp.isDotAll,
);
if (exp.hasMatch(element)) {
if (each.inline) {
spans.add(each.span(context, element, config));
} else {
spans.addAll([
TextSpan(
text: "\n ",
style: TextStyle(
fontSize: 0,
height: 0,
color: config.style?.color,
),
),
each.span(context, element, config),
TextSpan(
text: "\n ",
style: TextStyle(
fontSize: 0,
height: 0,
color: config.style?.color,
),
),
]);
}
spans.add(each.span(context, element, config));
return "";
}
}
... ... @@ -156,7 +134,12 @@ abstract class BlockMd extends MarkdownComponent {
child: child,
);
}
return WidgetSpan(child: child, alignment: PlaceholderAlignment.middle);
child = Row(children: [Expanded(child: child)]);
return WidgetSpan(
child: child,
alignment: PlaceholderAlignment.baseline,
baseline: TextBaseline.alphabetic,
);
}
Widget build(
... ... @@ -293,7 +276,7 @@ class HrLine extends BlockMd {
/// Checkbox component
class CheckBoxMd extends BlockMd {
@override
String get expString => (r"\[(\x?)\]\ (\S[^\n]*?)$");
String get expString => (r"\[((?:\x|\ ))\]\ (\S[^\n]*?)$");
get onLinkTab => null;
@override
... ... @@ -314,7 +297,7 @@ class CheckBoxMd extends BlockMd {
/// Radio Button component
class RadioButtonMd extends BlockMd {
@override
String get expString => (r"\((\x?)\)\ (\S[^\n]*)$");
String get expString => (r"\(((?:\x|\ ))\)\ (\S[^\n]*)$");
get onLinkTab => null;
@override
... ... @@ -390,7 +373,7 @@ class UnOrderedList extends BlockMd {
) {
var match = this.exp.firstMatch(text);
var child = MdWidget("${match?[1]?.trim()}", false, config: config);
var child = MdWidget("${match?[1]?.trim()}", true, config: config);
return config.unOrderedListBuilder?.call(
context,
... ... @@ -428,7 +411,7 @@ class OrderedList extends BlockMd {
var no = "${match?[1]}";
var child = MdWidget("${match?[2]?.trim()}", false, config: config);
var child = MdWidget("${match?[2]?.trim()}", true, config: config);
return config.orderedListBuilder?.call(
context,
no,
... ... @@ -582,7 +565,8 @@ class ItalicMd extends InlineMd {
class LatexMathMultiLine extends BlockMd {
@override
String get expString => (r"\\\[(((?!\n\n).)*?)\\\]|(\\begin.*?\\end{.*?})");
String get expString => (r"\ *\\\[((?:.)*?)\\\]|(\ *\\begin.*?\\end{.*?})");
// (r"\ *\\\[((?:(?!\n\n\n).)*?)\\\]|(\\begin.*?\\end{.*?})");
@override
RegExp get exp => RegExp(expString, dotAll: true, multiLine: true);
... ... @@ -593,7 +577,7 @@ class LatexMathMultiLine extends BlockMd {
final GptMarkdownConfig config,
) {
var p0 = exp.firstMatch(text.trim());
String mathText = p0?[1] ?? p0?[2] ?? "";
String mathText = p0?[1] ?? p0?[2] ?? '';
var workaround = config.latexWorkaround ?? (String tex) => tex;
var builder =
... ...
... ... @@ -20,24 +20,21 @@ class MdWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
List<InlineSpan> list = [];
list.addAll(
MarkdownComponent.generate(
context,
exp,
// .replaceAllMapped(
// RegExp(
// r"\\\[(.*?)\\\]|(\\begin.*?\\end{.*?})",
// multiLine: true,
// dotAll: true,
// ), (match) {
// //
// String body = (match[1] ?? match[2])?.replaceAll("\n", " ") ?? "";
// return "\\[$body\\]";
// }),
config,
includeGlobalComponents,
),
List<InlineSpan> list = MarkdownComponent.generate(
context,
exp,
// .replaceAllMapped(
// RegExp(
// r"\\\[(.*?)\\\]|(\\begin.*?\\end{.*?})",
// multiLine: true,
// dotAll: true,
// ), (match) {
// //
// String body = (match[1] ?? match[2])?.replaceAll("\n", " ") ?? "";
// return "\\[$body\\]";
// }),
config,
includeGlobalComponents,
);
return config.getRich(
TextSpan(children: list, style: config.style?.copyWith()),
... ...