11use std:: io:: Write ;
22
3- use acdc_parser:: { DescriptionList , DescriptionListItem , ListItem , OrderedList , UnorderedList } ;
3+ use acdc_parser:: {
4+ DescriptionList , DescriptionListItem , ListItem , ListItemCheckedStatus , OrderedList ,
5+ UnorderedList ,
6+ } ;
47
58use crate :: { Processor , Render , RenderOptions } ;
69
@@ -41,6 +44,7 @@ impl Render for OrderedList {
4144}
4245
4346/// Render nested list items hierarchically
47+ #[ tracing:: instrument( skip( w, processor) ) ]
4448fn render_nested_list_items < W : Write > (
4549 items : & [ ListItem ] ,
4650 w : & mut W ,
@@ -62,21 +66,45 @@ fn render_nested_list_items<W: Write>(
6266 // Render item at current level
6367 writeln ! ( w, "<li>" ) ?;
6468 writeln ! ( w, "<p>" ) ?;
69+ render_checked_status ( item. checked . as_ref ( ) , w) ?;
6570 crate :: inlines:: render_inlines ( & item. content , w, processor, options) ?;
6671 writeln ! ( w, "</p>" ) ?;
6772
6873 // Check if next items are nested (higher level)
6974 if i + 1 < items. len ( ) && items[ i + 1 ] . level > expected_level {
7075 // Find all items at the next level
7176 let next_level = items[ i + 1 ] . level ;
77+ let inner_item = & items[ i + 1 ] ;
7278
7379 // Open nested list
7480 if is_ordered {
75- writeln ! ( w, "<div class=\" olist arabic\" >" ) ?;
76- writeln ! ( w, "<ol class=\" arabic\" >" ) ?;
81+ writeln ! ( w, "<div class=\" olist arabic" ) ?;
82+ if inner_item. checked . is_some ( ) {
83+ writeln ! ( w, " checklist\" >" ) ?;
84+ } else {
85+ writeln ! ( w, "\" >" ) ?;
86+ }
87+
88+ write ! ( w, "<ol class=\" arabic" ) ?;
89+ if inner_item. checked . is_some ( ) {
90+ writeln ! ( w, " checklist\" >" ) ?;
91+ } else {
92+ writeln ! ( w, "\" >" ) ?;
93+ }
7794 } else {
78- writeln ! ( w, "<div class=\" ulist\" >" ) ?;
79- writeln ! ( w, "<ul>" ) ?;
95+ // check if the item is a checkbox item
96+ write ! ( w, "<div class=\" ulist" ) ?;
97+ if inner_item. checked . is_some ( ) {
98+ writeln ! ( w, " checklist\" >" ) ?;
99+ } else {
100+ writeln ! ( w, "\" >" ) ?;
101+ }
102+ write ! ( w, "<ul" ) ?;
103+ if inner_item. checked . is_some ( ) {
104+ writeln ! ( w, " class=\" checklist\" >" ) ?;
105+ } else {
106+ writeln ! ( w, ">" ) ?;
107+ }
80108 }
81109
82110 // Recursively render nested items
@@ -111,11 +139,7 @@ fn render_nested_list_items<W: Write>(
111139 } else {
112140 // Item at higher level than expected, shouldn't happen in well-formed input
113141 // but handle gracefully by treating as same level
114- writeln ! ( w, "<li>" ) ?;
115- writeln ! ( w, "<p>" ) ?;
116- crate :: inlines:: render_inlines ( & item. content , w, processor, options) ?;
117- writeln ! ( w, "</p>" ) ?;
118- writeln ! ( w, "</li>" ) ?;
142+ item. render ( w, processor, options) ?;
119143 i += 1 ;
120144 }
121145 }
@@ -133,6 +157,7 @@ impl Render for ListItem {
133157 ) -> Result < ( ) , Self :: Error > {
134158 writeln ! ( w, "<li>" ) ?;
135159 writeln ! ( w, "<p>" ) ?;
160+ render_checked_status ( self . checked . as_ref ( ) , w) ?;
136161 crate :: inlines:: render_inlines ( & self . content , w, processor, options) ?;
137162 writeln ! ( w, "</p>" ) ?;
138163 writeln ! ( w, "</li>" ) ?;
@@ -185,3 +210,20 @@ impl Render for DescriptionListItem {
185210 Ok ( ( ) )
186211 }
187212}
213+
214+ #[ tracing:: instrument( skip( w) ) ]
215+ fn render_checked_status < W : Write > (
216+ checked : Option < & ListItemCheckedStatus > ,
217+ w : & mut W ,
218+ ) -> Result < ( ) , crate :: Error > {
219+ match checked {
220+ Some ( ListItemCheckedStatus :: Checked ) => {
221+ write ! ( w, "✓ " ) ?; // Checked box
222+ }
223+ Some ( ListItemCheckedStatus :: Unchecked ) => {
224+ write ! ( w, "❏ " ) ?; // Unchecked box
225+ }
226+ None => { }
227+ }
228+ Ok ( ( ) )
229+ }
0 commit comments