Created
September 15, 2023 11:33
-
-
Save rileyhawk1417/8e8ed1e4da288765d3ea66a1796d451e to your computer and use it in GitHub Desktop.
Bulleted List node suggestion for handling children
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//NOTE: Helper functions | |
String childNode(String node) { | |
String tmpWord = ''; | |
final spacesRegex = RegExp(r'(\s+)- '); | |
const spacesPerLevel = 2; | |
int level = 1; | |
if (node.startsWith(' ') && node.contains('- ')) { | |
final spaces = spacesRegex.firstMatch(node)!.group(1)!.length; | |
level = (spaces / spacesPerLevel).ceil(); | |
tmpWord = node.substring(level); | |
} | |
return tmpWord; | |
} | |
bool checkChild(String child) { | |
if (child.startsWith(' ')) { | |
return true; | |
} | |
return false; | |
} | |
bool checkParent(String parent) { | |
if (parent.startsWith('- ') && | |
(parent.contains('- ', 0) || parent.contains('- ', 1))) { | |
return true; | |
} | |
return false; | |
} | |
String firstNode(String node) { | |
String parentList = ''; | |
if (node.startsWith('- ') && | |
(node.contains('- ', 0) || node.contains('- ', 1))) { | |
final String firstWord = node.substring(2); | |
parentList = node.substring(2); | |
return firstWord; | |
} | |
return parentList; | |
// return null; | |
} | |
return bulletedListNode( | |
//NOTE: Just prints double the parent | |
attributes: checkParent(firstNode(line)) | |
? { | |
'delta': decoder.convert(firstNode(line)).toJson(), | |
} | |
: {}, | |
//NOTE: Child node works fine although | |
children: checkChild(childNode(line)) | |
? [ | |
bulletedListNode( | |
attributes: { | |
'delta': | |
decoder.convert(childNode(line).substring(2)).toJson() | |
}, | |
), | |
] | |
: [], | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment