File tree Expand file tree Collapse file tree 3 files changed +26
-3
lines changed
ReverseMarkdown/Converters Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -889,6 +889,24 @@ public void WhenTable_CellContainsBr_PreserveBrAndConvertToGFMTable()
889889 } ) ;
890890 }
891891
892+ [ Fact ]
893+ public void WhenTable_HasEmptyRow_DropsEmptyRow ( )
894+ {
895+ const string html =
896+ @"<table><tr><td>abc</td></tr><tr></tr></table>" ;
897+ var expected = $ "{ Environment . NewLine } { Environment . NewLine } ";
898+ expected += $ "| <!----> |{ Environment . NewLine } ";
899+ expected += $ "| --- |{ Environment . NewLine } ";
900+ expected += $ "| abc |{ Environment . NewLine } ";
901+ expected += Environment . NewLine ;
902+
903+ CheckConversion ( html , expected , new Config
904+ {
905+ GithubFlavored = true ,
906+ TableWithoutHeaderRowHandling = Config . TableWithoutHeaderRowHandlingOption . EmptyRow ,
907+ } ) ;
908+ }
909+
892910 [ Fact ]
893911 public void When_BR_With_GitHubFlavored_Config_ThenConvertToGFM_BR ( )
894912 {
Original file line number Diff line number Diff line change @@ -51,8 +51,8 @@ private static string EmptyHeader(HtmlNode node)
5151 underlineRowItems . Add ( "---" ) ;
5252 }
5353
54- var headerRow = $ "| { headerRowItems . Aggregate ( ( item1 , item2 ) => item1 + " | " + item2 ) } |{ Environment . NewLine } ";
55- var underlineRow = $ "| { underlineRowItems . Aggregate ( ( item1 , item2 ) => item1 + " | " + item2 ) } |{ Environment . NewLine } ";
54+ var headerRow = $ "| { string . Join ( " | " , headerRowItems ) } |{ Environment . NewLine } ";
55+ var underlineRow = $ "| { string . Join ( " | " , underlineRowItems ) } |{ Environment . NewLine } ";
5656
5757 return headerRow + underlineRow ;
5858 }
Original file line number Diff line number Diff line change @@ -17,6 +17,11 @@ public override string Convert(HtmlNode node)
1717 {
1818 var content = TreatChildren ( node ) . TrimEnd ( ) ;
1919 var underline = "" ;
20+
21+ if ( string . IsNullOrWhiteSpace ( content ) )
22+ {
23+ return "" ;
24+ }
2025
2126 if ( IsTableHeaderRow ( node ) || UseFirstRowAsHeaderRow ( node ) )
2227 {
@@ -61,7 +66,7 @@ private string UnderlineFor(HtmlNode node)
6166 cols . Add ( "---" ) ;
6267 }
6368
64- var colsAggregated = cols . Aggregate ( ( item1 , item2 ) => item1 + " | " + item2 ) ;
69+ var colsAggregated = string . Join ( " | " , cols ) ;
6570
6671 return $ "| { colsAggregated } |{ Environment . NewLine } ";
6772 }
You can’t perform that action at this time.
0 commit comments