fix: html encoder not adding multiple text decorations (#424)
* fix: html encoder not adding multiple text decorations * fix: html encoder with multiple attributes more test added
This commit is contained in:
parent
9105812cbc
commit
72d6c52f25
4 changed files with 143 additions and 4 deletions
|
|
@ -203,7 +203,7 @@
|
|||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0920;
|
||||
LastUpgradeCheck = 1300;
|
||||
LastUpgradeCheck = 1430;
|
||||
ORGANIZATIONNAME = "";
|
||||
TargetAttributes = {
|
||||
33CC10EC2044A3C60003C045 = {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1300"
|
||||
LastUpgradeVersion = "1430"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
|
|
|||
|
|
@ -48,6 +48,10 @@ class DeltaHTMLEncoder extends Converter<Delta, List<dom.Node>> {
|
|||
..attributes['href'] = href
|
||||
..append(domText);
|
||||
}
|
||||
//backgroud color and attribute color is added than that was ignoring now all attributes handled according to attributes
|
||||
if (attributes.backgroundColor != null || attributes.color != null) {
|
||||
return convertMultipleAttributeTextInsertToDomNode(text, attributes);
|
||||
}
|
||||
|
||||
final keyToTag = {
|
||||
AppFlowyRichTextKeys.bold: HTMLTags.strong,
|
||||
|
|
@ -126,8 +130,9 @@ class DeltaHTMLEncoder extends Converter<Delta, List<dom.Node>> {
|
|||
if (attributes.bold) {
|
||||
cssMap['font-weight'] = 'bold';
|
||||
}
|
||||
|
||||
if (attributes.underline) {
|
||||
if (attributes.underline && attributes.strikethrough) {
|
||||
cssMap['text-decoration'] = 'underline line-through';
|
||||
} else if (attributes.underline) {
|
||||
cssMap['text-decoration'] = 'underline';
|
||||
} else if (attributes.strikethrough) {
|
||||
cssMap['text-decoration'] = 'line-through';
|
||||
|
|
|
|||
|
|
@ -113,5 +113,139 @@ void main() async {
|
|||
"<p><strong>Welcome to AppFlowy</strong></p>",
|
||||
);
|
||||
});
|
||||
test('underline', () {
|
||||
final node = paragraphNode(
|
||||
attributes: {
|
||||
'delta': (Delta()
|
||||
..insert(
|
||||
text,
|
||||
attributes: {
|
||||
'underline': true,
|
||||
},
|
||||
))
|
||||
.toJson(),
|
||||
},
|
||||
);
|
||||
|
||||
expect(
|
||||
const HTMLTextNodeParser()
|
||||
.transformNodeToHTMLString(node, encodeParsers: parser),
|
||||
"<p><u>Welcome to AppFlowy</u></p>",
|
||||
);
|
||||
});
|
||||
test('strikethrough', () {
|
||||
final node = paragraphNode(
|
||||
attributes: {
|
||||
'delta': (Delta()
|
||||
..insert(
|
||||
text,
|
||||
attributes: {
|
||||
'strikethrough': true,
|
||||
},
|
||||
))
|
||||
.toJson(),
|
||||
},
|
||||
);
|
||||
|
||||
expect(
|
||||
const HTMLTextNodeParser()
|
||||
.transformNodeToHTMLString(node, encodeParsers: parser),
|
||||
"<p><del>Welcome to AppFlowy</del></p>",
|
||||
);
|
||||
});
|
||||
test('underline and strikethrough', () {
|
||||
final node = paragraphNode(
|
||||
attributes: {
|
||||
'delta': (Delta()
|
||||
..insert(
|
||||
text,
|
||||
attributes: {
|
||||
'strikethrough': true,
|
||||
'underline': true,
|
||||
},
|
||||
))
|
||||
.toJson(),
|
||||
},
|
||||
);
|
||||
|
||||
expect(
|
||||
const HTMLTextNodeParser()
|
||||
.transformNodeToHTMLString(node, encodeParsers: parser),
|
||||
'''<p><span style="text-decoration: underline line-through">Welcome to AppFlowy</span></p>''',
|
||||
);
|
||||
});
|
||||
test('multiple attributes Test with background and text color', () {
|
||||
final node = paragraphNode(
|
||||
attributes: {
|
||||
'delta': (Delta()
|
||||
..insert(
|
||||
text,
|
||||
attributes: {
|
||||
'bold': true,
|
||||
'italic': true,
|
||||
"underline": true,
|
||||
"strikethrough": true,
|
||||
"bg_color": "0x6000bcf0",
|
||||
"font_color": "0xff2196f3",
|
||||
},
|
||||
))
|
||||
.toJson(),
|
||||
},
|
||||
);
|
||||
|
||||
expect(
|
||||
const HTMLTextNodeParser()
|
||||
.transformNodeToHTMLString(node, encodeParsers: parser),
|
||||
'''<p><span style="font-weight: bold; text-decoration: underline line-through; font-style: italic; background-color: rgba(0, 188, 240, 96); color: rgba(33, 150, 243, 255)">Welcome to AppFlowy</span></p>''',
|
||||
);
|
||||
});
|
||||
test('multiple attributes Test with background', () {
|
||||
final node = paragraphNode(
|
||||
attributes: {
|
||||
'delta': (Delta()
|
||||
..insert(
|
||||
text,
|
||||
attributes: {
|
||||
'bold': true,
|
||||
'italic': true,
|
||||
"underline": true,
|
||||
"strikethrough": true,
|
||||
"bg_color": "0x6000bcf0",
|
||||
},
|
||||
))
|
||||
.toJson(),
|
||||
},
|
||||
);
|
||||
|
||||
expect(
|
||||
const HTMLTextNodeParser()
|
||||
.transformNodeToHTMLString(node, encodeParsers: parser),
|
||||
'''<p><span style="font-weight: bold; text-decoration: underline line-through; font-style: italic; background-color: rgba(0, 188, 240, 96)">Welcome to AppFlowy</span></p>''',
|
||||
);
|
||||
});
|
||||
test('multiple attributes Test with text color', () {
|
||||
final node = paragraphNode(
|
||||
attributes: {
|
||||
'delta': (Delta()
|
||||
..insert(
|
||||
text,
|
||||
attributes: {
|
||||
'bold': true,
|
||||
'italic': true,
|
||||
"underline": true,
|
||||
"strikethrough": true,
|
||||
"font_color": "0xff2196f3",
|
||||
},
|
||||
))
|
||||
.toJson(),
|
||||
},
|
||||
);
|
||||
|
||||
expect(
|
||||
const HTMLTextNodeParser()
|
||||
.transformNodeToHTMLString(node, encodeParsers: parser),
|
||||
'''<p><span style="font-weight: bold; text-decoration: underline line-through; font-style: italic; color: rgba(33, 150, 243, 255)">Welcome to AppFlowy</span></p>''',
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue