diff --git a/lib/structs.dart b/lib/structs.dart index 4672792..b9dbad3 100644 --- a/lib/structs.dart +++ b/lib/structs.dart @@ -1,6 +1,7 @@ //data structures import 'dart:typed_data'; +import 'package:markdown/markdown.dart' as md; class GetThreadResponse { final int id; @@ -151,6 +152,48 @@ class AttachmentResponse { } class AugmentTree { - List children = []; - AugmentTree? node; + List children = []; + + String data = ''; + AugmentTree? parent; + String ogTag = ''; + String numbering = ''; + + void setData(String data) { + this.data = data; + } + + static String _intToLetter(int index) { + return String.fromCharCode('a'.runes.first + index); + } + + void addNumbering({String prefix = ''}) { + //if called in root, numbers them all + for (int i = 0; i < children.length; i++) { + final child = children[i]; + String childNumbering; + bool parentIsLettered = prefix.contains(RegExp(r'[a-z]')); + if (prefix.isEmpty) { + parentIsLettered = false; + } else { + parentIsLettered = prefix.runes.last >= 'a'.runes.first && + prefix.runes.last <= 'z'.runes.first; + } + + if (prefix.isEmpty) { + // Top-level children (direct children of the original root being numbered) get 1, 2, 3... + childNumbering = (i + 1).toString(); + } else if (parentIsLettered) { + // Deeper children get '1a', '1b', '2a', '2b', etc. + childNumbering = '$prefix${i + 1}'; + } else { + childNumbering = '$prefix${_intToLetter(i)}'; + } + + child.numbering = childNumbering; + + // Recursively call for children + child.addNumbering(prefix: childNumbering); + } + } }