File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
src/Html2OpenXml/Expressions/Numbering Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -93,13 +93,20 @@ public override IEnumerable<OpenXmlElement> Interpret(ParsingContext context)
93
93
94
94
// table must be aligned to the list item
95
95
var tables = childElements . OfType < Table > ( ) ;
96
+ var tableIndentation = level * Indentation * 2 ;
96
97
foreach ( var table in tables )
97
98
{
98
99
var tableProperties = table . GetFirstChild < TableProperties > ( ) ;
99
100
if ( tableProperties == null )
100
101
table . PrependChild ( tableProperties = new ( ) ) ;
101
102
102
- tableProperties . TableIndentation ??= new ( ) { Width = level * Indentation * 2 } ;
103
+ tableProperties . TableIndentation ??= new ( ) { Width = tableIndentation } ;
104
+ // ensure to restrain the table width to the list item
105
+ if ( tableProperties . TableWidth ? . Type ? . Value == TableWidthUnitValues . Pct
106
+ && tableProperties . TableWidth ? . Width ? . Value == "5000" )
107
+ {
108
+ tableProperties . TableWidth . Width = ( 5000 - tableIndentation ) . ToString ( ) ;
109
+ }
103
110
}
104
111
105
112
// ensure to filter out any non-paragraph like any nested table
Original file line number Diff line number Diff line change @@ -636,6 +636,10 @@ public void NestedTable_ReturnsAlignedTable()
636
636
Assert . That ( tableProperties , Is . Not . Null ) ;
637
637
Assert . That ( tableProperties . TableIndentation , Is . Not . Null ) ;
638
638
Assert . That ( tableProperties . TableIndentation . Width ? . Value , Is . EqualTo ( 720 * ( i + 1 ) ) ) ;
639
+ Assert . That ( tableProperties . TableWidth , Is . Not . Null ) ;
640
+ Assert . That ( tableProperties . TableWidth . Type ? . Value , Is . EqualTo ( TableWidthUnitValues . Pct ) ) ;
641
+ Assert . That ( tableProperties . TableWidth . Width ? . HasValue , Is . True ) ;
642
+ Assert . That ( Convert . ToInt32 ( tableProperties . TableWidth . Width . Value ) , Is . GreaterThan ( 0 ) . And . LessThan ( 5000 ) ) ;
639
643
}
640
644
}
641
645
}
You can’t perform that action at this time.
0 commit comments