Open Levi-Lesches opened 1 day ago
I opened #8348 with my first pass at the parser, marked as draft because I know you still have some points to address. Here's the new API:
/// A node of the Table of Contents
class TocNode {
/// What level heading this node is.
///
/// This is not defined by what tag it is using, or how many `#` it has, but rather
/// how many levels of nesting have occurred in the document so far. That is to say,
///
/// ```md
/// # Level 1
/// ### Level 2
/// ##### Level 3
/// ```
int level;
/// The list of [TocNode] that are nested under this heading.
List<TocNode> children;
/// The title of the node, as a string.
final String title;
/// The parent heading for this node.
TocNode? parent;
}
Continuing the conversation from #4371, the goal is to create a parser that accepts markdown as input as spits out a list of headings that can be easily formatted into a table of contents or similar.
@isoos From the other thread:
For reference, here is the
TocNode
class:https://github.com/dart-lang/pub-dev/blob/4acdc2bdc3dce95832ad9171f2f2fef4f04a5fad/app/lib/frontend/templates/views/shared/toc.dart#L35-L51
Can you elaborate here:
Node
, but I don't see where we'd want the content to beTocNode
and refactor the admin page to use that?