You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, for my note-taking app I need to display the beginning of a note as plain text in the notes list as a preview of the note's content.
I would like to include checkboxes, by replacing the with emojis (✅ and ⬜). I could later extend this to also supports lists for example, but I'll stick to checkboxes for now.
I have already written this code that parses the Operations, but it doesn't always work (especially when there are multiple lines with the same checkbox and no text and they get unified in the same Operation with multiple new lines). Before trying to improve it or extend it, I want to know if there is a better way?
Stringget contentPreview {
var content ='';
// Here 'document' is a ParchmentDocumentfor (final child in document.root.children) {
final operations = child.toDelta().toList();
for (var i =0; i < operations.length; i++) {
final operation = operations[i];
// Skip horizontal rulesif (operation.data isMap&&
(operation.data asMap).containsKey('_type') &&
(operation.data asMap)['_type'] =='hr') {
continue;
}
final nextOperation = i == operations.length -1?null: operations[i +1];
final checklist = nextOperation !=null&&
nextOperation.attributes !=null&&
nextOperation.attributes!.containsKey('block') &&
nextOperation.attributes!['block'] =='cl';
if (checklist) {
final checked = nextOperation.attributes!.containsKey('checked');
content +='${checked ? '✅' : '⬜'} ${operation.value}';
} else {
content += operation.value.toString();
}
}
}
return content.trim();
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, for my note-taking app I need to display the beginning of a note as plain text in the notes list as a preview of the note's content.
I would like to include checkboxes, by replacing the with emojis (✅ and ⬜). I could later extend this to also supports lists for example, but I'll stick to checkboxes for now.
I have already written this code that parses the
Operation
s, but it doesn't always work (especially when there are multiple lines with the same checkbox and no text and they get unified in the sameOperation
with multiple new lines). Before trying to improve it or extend it, I want to know if there is a better way?Beta Was this translation helpful? Give feedback.
All reactions