@@ -27,6 +27,7 @@ class BlockElementExpression: PhrasingElementExpression
27
27
{
28
28
private readonly OpenXmlLeafElement [ ] ? defaultStyleProperties ;
29
29
protected readonly ParagraphProperties paraProperties = new ( ) ;
30
+ protected TableProperties ? tableProperties ;
30
31
// some style attributes, such as borders or bgcolor, will convert this node to a framed container
31
32
protected bool renderAsFramed ;
32
33
private HtmlBorder styleBorder ;
@@ -115,22 +116,44 @@ protected override IEnumerable<OpenXmlElement> Interpret (
115
116
public override void CascadeStyles ( OpenXmlElement element )
116
117
{
117
118
base . CascadeStyles ( element ) ;
118
- if ( ! paraProperties . HasChildren || element is not Paragraph paragraph )
119
+ if ( ! paraProperties . HasChildren )
119
120
return ;
120
121
121
- paragraph . ParagraphProperties ??= new ParagraphProperties ( ) ;
122
-
123
- var knownTags = new HashSet < string > ( ) ;
124
- foreach ( var prop in paragraph . ParagraphProperties )
122
+ if ( element is Paragraph paragraph )
125
123
{
126
- if ( ! knownTags . Contains ( prop . LocalName ) )
127
- knownTags . Add ( prop . LocalName ) ;
128
- }
124
+ paragraph . ParagraphProperties ??= new ParagraphProperties ( ) ;
129
125
130
- foreach ( var prop in paraProperties )
126
+ var knownTags = new HashSet < string > ( ) ;
127
+ foreach ( var prop in paragraph . ParagraphProperties )
128
+ {
129
+ if ( ! knownTags . Contains ( prop . LocalName ) )
130
+ knownTags . Add ( prop . LocalName ) ;
131
+ }
132
+
133
+ foreach ( var prop in paraProperties )
134
+ {
135
+ if ( ! knownTags . Contains ( prop . LocalName ) )
136
+ paragraph . ParagraphProperties . AddChild ( prop . CloneNode ( true ) ) ;
137
+ }
138
+ }
139
+ else if ( tableProperties != null && element is Table table )
131
140
{
132
- if ( ! knownTags . Contains ( prop . LocalName ) )
133
- paragraph . ParagraphProperties . AddChild ( prop . CloneNode ( true ) ) ;
141
+ var props = table . GetFirstChild < TableProperties > ( ) ;
142
+ if ( props is null )
143
+ return ;
144
+
145
+ var knownTags = new HashSet < string > ( ) ;
146
+ foreach ( var prop in props )
147
+ {
148
+ if ( ! knownTags . Contains ( prop . LocalName ) )
149
+ knownTags . Add ( prop . LocalName ) ;
150
+ }
151
+
152
+ foreach ( var prop in tableProperties )
153
+ {
154
+ if ( ! knownTags . Contains ( prop . LocalName ) )
155
+ props . AddChild ( prop . CloneNode ( true ) ) ;
156
+ }
134
157
}
135
158
}
136
159
@@ -170,9 +193,12 @@ protected override void ComposeStyles (ParsingContext context)
170
193
171
194
JustificationValues ? align = Converter . ToParagraphAlign ( styleAttributes ! [ "text-align" ] ) ;
172
195
if ( ! align . HasValue ) align = Converter . ToParagraphAlign ( node . GetAttribute ( "align" ) ) ;
196
+ if ( ! align . HasValue ) align = Converter . ToParagraphAlign ( styleAttributes [ "justify-content" ] ) ;
173
197
if ( align . HasValue )
174
198
{
175
199
paraProperties . Justification = new ( ) { Val = align } ;
200
+ tableProperties ??= new ( ) ;
201
+ tableProperties . TableJustification = new ( ) { Val = align . Value . ToTableRowAlignment ( ) } ;
176
202
}
177
203
178
204
@@ -194,7 +220,7 @@ protected override void ComposeStyles (ParsingContext context)
194
220
}
195
221
196
222
var margin = styleAttributes . GetMargin ( "margin" ) ;
197
- Indentation ? indentation = null ;
223
+ Indentation ? indentation = null ;
198
224
if ( ! margin . IsEmpty )
199
225
{
200
226
if ( margin . Top . IsFixed || margin . Bottom . IsFixed )
0 commit comments