fix: support export markdown with inline math equation (#1164)
This commit is contained in:
parent
2dbc203b14
commit
7cc5d25788
2 changed files with 31 additions and 1 deletions
|
|
@ -15,8 +15,13 @@ class DeltaMarkdownEncoder extends Converter<Delta, String> {
|
|||
if (op is TextInsert) {
|
||||
final attributes = op.attributes;
|
||||
if (attributes != null) {
|
||||
final formula = attributes[BuiltInAttributeKey.formula] ?? '';
|
||||
buffer.write(_prefixSyntax(attributes));
|
||||
buffer.write(op.text);
|
||||
if (formula.isNotEmpty) {
|
||||
buffer.write(formula);
|
||||
} else {
|
||||
buffer.write(op.text);
|
||||
}
|
||||
buffer.write(_suffixSyntax(attributes));
|
||||
} else {
|
||||
buffer.write(op.text);
|
||||
|
|
@ -52,6 +57,10 @@ class DeltaMarkdownEncoder extends Converter<Delta, String> {
|
|||
syntax += '[';
|
||||
}
|
||||
|
||||
if (attributes[BuiltInAttributeKey.formula] != null) {
|
||||
syntax += r'$';
|
||||
}
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
|
|
@ -83,6 +92,10 @@ class DeltaMarkdownEncoder extends Converter<Delta, String> {
|
|||
syntax += '_';
|
||||
}
|
||||
|
||||
if (attributes[BuiltInAttributeKey.formula] != null) {
|
||||
syntax += r'$';
|
||||
}
|
||||
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -137,5 +137,22 @@ void main() async {
|
|||
'***<u>`Welcome`</u>*** ***~~to~~*** ***[AppFlowy](https://appflowy.io)***',
|
||||
);
|
||||
});
|
||||
|
||||
test('formula', () {
|
||||
final delta = Delta(
|
||||
operations: [
|
||||
TextInsert('This is a formula:'),
|
||||
TextInsert(
|
||||
'\$',
|
||||
attributes: {
|
||||
BuiltInAttributeKey.formula: 'E = MC ^ 2',
|
||||
},
|
||||
),
|
||||
TextInsert('.'),
|
||||
],
|
||||
);
|
||||
final result = DeltaMarkdownEncoder().convert(delta);
|
||||
expect(result, 'This is a formula:\$E = MC ^ 2\$.');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue