struct for markdown, with a numbering algorithm for each node that goes in the form of #a#b#c
This commit is contained in:
		
							parent
							
								
									654520ad3a
								
							
						
					
					
						commit
						8568eafba3
					
				
					 1 changed files with 45 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -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<AugmentTree> 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);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue