@@ -90,17 +90,38 @@ public override IEnumerable<OpenXmlElement> Interpret(ParsingContext context)
90
90
var expression = new BlockElementExpression ( liNode ) ;
91
91
var childElements = expression . Interpret ( context ) ;
92
92
if ( ! childElements . Any ( ) ) continue ;
93
- Paragraph p = ( Paragraph ) childElements . First ( ) ;
94
-
95
- p . ParagraphProperties ??= new ( ) ;
96
- p . ParagraphProperties . ParagraphStyleId = GetStyleIdForListItem ( context . DocumentStyle , liNode ) ;
97
- p . ParagraphProperties . NumberingProperties = new NumberingProperties {
98
- NumberingLevelReference = new ( ) { Val = level - 1 } ,
99
- NumberingId = new ( ) { Val = listContext . InstanceId }
100
- } ;
101
- if ( listContext . Dir . HasValue ) {
102
- p . ParagraphProperties . BiDi = new ( ) {
103
- Val = OnOffValue . FromBoolean ( listContext . Dir == DirectionMode . Rtl )
93
+
94
+ // ensure to filter out any non-paragraph like any nested table
95
+ var paragraphs = childElements . OfType < Paragraph > ( ) ;
96
+ var listItemStyleId = GetStyleIdForListItem ( context . DocumentStyle , liNode ) ;
97
+
98
+ if ( paragraphs . Any ( ) )
99
+ {
100
+ var p = paragraphs . First ( ) ;
101
+ p . ParagraphProperties ??= new ( ) ;
102
+ p . ParagraphProperties . ParagraphStyleId = listItemStyleId ;
103
+ p . ParagraphProperties ! . NumberingProperties ??= new NumberingProperties {
104
+ NumberingLevelReference = new ( ) { Val = level - 1 } ,
105
+ NumberingId = new ( ) { Val = listContext . InstanceId }
106
+ } ;
107
+ if ( listContext . Dir . HasValue ) {
108
+ p . ParagraphProperties . BiDi = new ( ) {
109
+ Val = OnOffValue . FromBoolean ( listContext . Dir == DirectionMode . Rtl )
110
+ } ;
111
+ }
112
+ }
113
+
114
+ // any standalone paragraphs must be aligned (indented) along its current level
115
+ foreach ( var p in paragraphs . Skip ( 1 ) )
116
+ {
117
+ // if this is a list item paragraph, skip it
118
+ if ( p . ParagraphProperties ? . NumberingProperties is not null )
119
+ continue ;
120
+
121
+ p . ParagraphProperties ??= new ( ) ;
122
+ p . ParagraphProperties . ParagraphStyleId ??= ( ParagraphStyleId ? ) listItemStyleId ! . CloneNode ( true ) ;
123
+ p . ParagraphProperties . Indentation = new ( ) {
124
+ Left = ( level * Indentation * 2 ) . ToString ( )
104
125
} ;
105
126
}
106
127
0 commit comments