1111using ColorCode . Parsing ;
1212using ColorCode . Styling ;
1313using Markdig . Extensions . Tables ;
14+ using Markdig . Extensions . TaskLists ;
1415using Markdig . Syntax ;
1516using Markdig . Syntax . Inlines ;
1617using OpenGptChat . Common . Models ;
@@ -123,7 +124,10 @@ public FrameworkElement RenderBlock(Block block)
123124
124125 private FrameworkElement RenderContainerBlock ( ContainerBlock containerBlock )
125126 {
126- StackPanel documentElement = new StackPanel ( ) ;
127+ StackPanel documentElement = new StackPanel ( )
128+ {
129+ Margin = new Thickness ( 0 , 0 , 0 , NormalSize )
130+ } ;
127131
128132 foreach ( var renderedBlock in RenderBlocks ( containerBlock ) )
129133 documentElement . Children . Add ( renderedBlock ) ;
@@ -136,6 +140,7 @@ public FrameworkElement RenderTable(Table table)
136140 Border tableElement = new Border ( )
137141 {
138142 BorderThickness = new Thickness ( 0 , 0 , 1 , 1 ) ,
143+ Margin = new Thickness ( 0 , 0 , 0 , NormalSize )
139144 } ;
140145
141146 Grid tableContentElement = new Grid ( ) ;
@@ -183,6 +188,8 @@ public FrameworkElement RenderTable(Table table)
183188 cellElement
184189 . BindTableBorder ( ) ;
185190
191+ cellContentElement . Margin = new Thickness ( 0 ) ;
192+
186193 if ( rowIndex % 2 == 1 )
187194 cellElement . BindTableStripe ( ) ;
188195
@@ -210,7 +217,7 @@ public FrameworkElement RenderListBlock(ListBlock listBlock)
210217
211218 Border listElement = new Border ( )
212219 {
213- Margin = new Thickness ( NormalSize / 2 , 0 , 0 , NormalSize / 2 )
220+ Margin = new Thickness ( NormalSize / 2 , 0 , 0 , NormalSize )
214221 } ;
215222
216223 Grid listContentElement = new Grid ( ) ;
@@ -237,10 +244,17 @@ public FrameworkElement RenderListBlock(ListBlock listBlock)
237244 }
238245
239246 int index = 0 ;
247+ FrameworkElement ? lastRenderedItemBlock = null ;
240248 foreach ( var itemBlock in listBlock )
241249 {
242250 if ( RenderBlock ( itemBlock ) is FrameworkElement renderedItemBlock )
243251 {
252+ lastRenderedItemBlock = renderedItemBlock ;
253+ renderedItemBlock . Margin = renderedItemBlock . Margin with
254+ {
255+ Bottom = renderedItemBlock . Margin . Bottom / 4
256+ } ;
257+
244258 TextBlock marker = new TextBlock ( ) ;
245259 Grid . SetRow ( marker , index ) ;
246260 Grid . SetColumn ( marker , 0 ) ;
@@ -257,6 +271,12 @@ public FrameworkElement RenderListBlock(ListBlock listBlock)
257271 }
258272 }
259273
274+ if ( lastRenderedItemBlock != null )
275+ lastRenderedItemBlock . Margin = lastRenderedItemBlock . Margin with
276+ {
277+ Bottom = 0
278+ } ;
279+
260280 return listElement ;
261281 }
262282
@@ -266,7 +286,7 @@ public FrameworkElement RenderThematicBreakBlock(ThematicBreakBlock thematicBrea
266286 {
267287 HorizontalAlignment = HorizontalAlignment . Stretch ,
268288 Height = 1 ,
269- Margin = new Thickness ( 0 , 0 , 0 , 6 )
289+ Margin = new Thickness ( 0 , 0 , 0 , NormalSize )
270290 } ;
271291
272292 thematicBreakElement
@@ -288,7 +308,7 @@ public FrameworkElement RenderFencedCodeBlock(FencedCodeBlock fencedCodeBlock)
288308 Border codeElement = new Border ( )
289309 {
290310 CornerRadius = new CornerRadius ( 3 ) ,
291- Margin = new Thickness ( 0 , 0 , 0 , NormalSize / 2 )
311+ Margin = new Thickness ( 0 , 0 , 0 , NormalSize )
292312 } ;
293313
294314 TextBlock codeContentElement = new TextBlock ( )
@@ -335,7 +355,7 @@ public FrameworkElement RenderCodeBlock(CodeBlock codeBlock)
335355 Border codeElement = new Border ( )
336356 {
337357 CornerRadius = new CornerRadius ( 3 ) ,
338- Margin = new Thickness ( 0 , 0 , 0 , NormalSize / 2 )
358+ Margin = new Thickness ( 0 , 0 , 0 , NormalSize )
339359 } ;
340360
341361 TextBlock codeContentElement = new TextBlock ( )
@@ -373,7 +393,7 @@ public FrameworkElement RenderQuoteBlock(QuoteBlock quoteBlock)
373393 BorderThickness = new Thickness ( NormalSize / 3 , 0 , 0 , 0 ) ,
374394 CornerRadius = new CornerRadius ( NormalSize / 4 ) ,
375395 Padding = new Thickness ( NormalSize / 2 , 0 , 0 , 0 ) ,
376- Margin = new Thickness ( 0 , 0 , 0 , NormalSize / 2 ) ,
396+ Margin = new Thickness ( 0 , 0 , 0 , NormalSize ) ,
377397 } ;
378398
379399 StackPanel quoteContentPanel = new StackPanel ( ) ;
@@ -392,35 +412,26 @@ public FrameworkElement RenderQuoteBlock(QuoteBlock quoteBlock)
392412
393413 public FrameworkElement RenderHeadingBlock ( HeadingBlock headingBlock )
394414 {
395- double ? fontSize = headingBlock . Level switch
415+ double fontSize = headingBlock . Level switch
396416 {
397417 1 => Heading1Size ,
398418 2 => Heading2Size ,
399419 3 => Heading3Size ,
400420 4 => Heading4Size ,
401- _ => null
421+ _ => NormalSize
402422 } ;
403423
404424 TextBlock headingElement = new TextBlock ( )
405425 {
426+ FontSize = fontSize ,
406427 FontWeight = FontWeights . Medium ,
407- // Margin 后面计算
428+ Margin = new Thickness ( 0 , 0 , 0 , NormalSize )
408429 } ;
409430
410431 headingElement
411432 . BindMainForeground ( )
412433 . BindMainBackground ( ) ;
413434
414- if ( fontSize . HasValue )
415- {
416- headingElement . FontSize = fontSize . Value ;
417- headingElement . Margin = new Thickness ( 0 , 0 , 0 , fontSize . Value / 2 ) ;
418- }
419- else
420- {
421- headingElement . Margin = new Thickness ( 0 , 0 , 0 , headingElement . FontSize / 2 ) ;
422- }
423-
424435 if ( headingBlock . Inline != null )
425436 headingElement . Inlines . AddRange (
426437 RenderInlines ( headingBlock . Inline ) ) ;
@@ -433,7 +444,7 @@ public FrameworkElement RenderParagraphBlock(ParagraphBlock paragraphBlock)
433444 TextBlock paragraphElement = new TextBlock ( )
434445 {
435446 TextWrapping = TextWrapping . Wrap ,
436- Margin = new Thickness ( 0 , 0 , 0 , NormalSize / 2 ) ,
447+ Margin = new Thickness ( 0 , 0 , 0 , NormalSize ) ,
437448
438449 FontSize = NormalSize ,
439450 } ;
@@ -507,12 +518,25 @@ public WpfDocs.Inline RenderInline(Inline inline)
507518 {
508519 return RenderContainerInline ( containerInline ) ;
509520 }
521+ else if ( inline is TaskList taskListInline )
522+ {
523+ return RenderTaskListInline ( taskListInline ) ;
524+ }
510525 else
511526 {
512527 return new WpfDocs . Run ( ) ;
513528 }
514529 }
515530
531+ private WpfDocs . Inline RenderTaskListInline ( TaskList taskListInline )
532+ {
533+ return new CheckBox ( )
534+ {
535+ IsChecked = taskListInline . Checked ,
536+ IsEnabled = false ,
537+ } . WrapWithContainer ( ) ;
538+ }
539+
516540 private WpfDocs . Inline RenderAutolinkInline ( AutolinkInline autolinkInline )
517541 {
518542 return new WpfDocs . Run ( autolinkInline . Url ) ;
0 commit comments