getTagAttributes method
Implementation
List<TagKeyValue> getTagAttributes() {
if (op.attributes.code == true && !op.isLink()) {
return <TagKeyValue>[];
}
final Map<String, String>? customTagAttributes = getCustomTagAttributes();
final List<TagKeyValue> customAttr =
customTagAttributes?.entries.map((MapEntry<String, String> entry) => makeAttr(entry.key, entry.value)).toList() ?? <TagKeyValue>[];
final List<String> classes = getCssClasses();
final List<TagKeyValue> tagAttrs = customAttr;
if (classes.isNotEmpty) {
tagAttrs.add(makeAttr('class', classes.join(' ')));
}
final List<String> styles = getCssStyles();
if (styles.isNotEmpty) {
tagAttrs.add(makeAttr('style', styles.join(';')));
}
if (op.isImage()) {
if (isTruthy(op.attributes.width)) {
tagAttrs.add(makeAttr('width', op.attributes.width!));
}
tagAttrs.add(makeAttr('src', op.insert.value));
return tagAttrs;
}
if (op.isACheckList()) {
tagAttrs.add(makeAttr('data-checked', op.isCheckedList() ? 'true' : 'false'));
return tagAttrs;
}
if (op.isFormula()) {
return tagAttrs;
}
if (op.isVideo()) {
tagAttrs.addAll(<TagKeyValue>[
makeAttr('frameborder', '0'),
makeAttr('allowfullscreen', 'true'),
makeAttr('src', op.insert.value),
]);
return tagAttrs;
}
if (op.isMentions()) {
final Mention mention = op.attributes.mention!;
if (isTruthy(mention.class_)) {
tagAttrs.add(makeAttr('class', mention.class_!));
}
if (isTruthy(mention.endPoint) && isTruthy(mention.slug)) {
tagAttrs.add(makeAttr('href', '${mention.endPoint!}/${mention.slug!}'));
} else {
tagAttrs.add(makeAttr('href', 'about:blank'));
}
if (isTruthy(mention.target)) {
tagAttrs.add(makeAttr('target', mention.target!));
}
return tagAttrs;
}
if (op.isCodeBlock() && op.attributes['code-block'] is String) {
tagAttrs.add(makeAttr('data-language', op.attributes['code-block']));
return tagAttrs;
}
if (op.isContainerBlock()) {
return tagAttrs;
}
if (op.isLink()) {
tagAttrs.addAll(getLinkAttrs());
}
return tagAttrs;
}