1
- /* Copyright (C) Olivier Nizet https://github.com/onizet/html2openxml - All Rights Reserved
1
+ /* Copyright (C) Olivier Nizet https://github.com/onizet/html2openxml - All Rights Reserved
2
2
*
3
3
* This source is subject to the Microsoft Permissive License.
4
4
* Please see the License.txt file for more information.
@@ -161,7 +161,15 @@ private ListContext ConcretiseInstance(ParsingContext context, int abstractNumId
161
161
int overrideLevelIndex = 0 ;
162
162
var isOrderedTag = node . NodeName . Equals ( "ol" , StringComparison . OrdinalIgnoreCase ) ;
163
163
var dir = node . GetTextDirection ( ) ;
164
- if ( ! instanceId . HasValue || context . Converter . ContinueNumbering == false )
164
+
165
+ // be sure to restart to 1 any nested ordered list
166
+ if ( currentLevel > 0 && isOrderedTag )
167
+ {
168
+ instanceId = IncrementInstanceId ( context , abstractNumId , isReusable : false ) ;
169
+ overrideLevelIndex = currentLevel ;
170
+ listContext = new ListContext ( listStyle , abstractNumId , instanceId . Value , currentLevel + 1 , dir ) ;
171
+ }
172
+ else if ( ! instanceId . HasValue || context . Converter . ContinueNumbering == false )
165
173
{
166
174
// create a new instance of that list template
167
175
instanceId = IncrementInstanceId ( context , abstractNumId , isReusable : context . Converter . ContinueNumbering ) ;
@@ -176,13 +184,6 @@ private ListContext ConcretiseInstance(ParsingContext context, int abstractNumId
176
184
instanceId = IncrementInstanceId ( context , abstractNumId , isReusable : false ) ;
177
185
listContext = new ListContext ( listStyle , abstractNumId , instanceId . Value , 1 , dir ) ;
178
186
}
179
- // be sure to restart to 1 any nested ordered list
180
- else if ( currentLevel > 0 && isOrderedTag )
181
- {
182
- instanceId = IncrementInstanceId ( context , abstractNumId , isReusable : false ) ;
183
- overrideLevelIndex = currentLevel ;
184
- listContext = new ListContext ( listStyle , abstractNumId , instanceId . Value , currentLevel + 1 , dir ) ;
185
- }
186
187
else
187
188
{
188
189
return new ListContext ( listStyle , abstractNumId , instanceId . Value , currentLevel + 1 , dir ) ;
@@ -215,20 +216,39 @@ private ListContext ConcretiseInstance(ParsingContext context, int abstractNumId
215
216
private static string GetListName ( IElement listNode , string ? parentName = null )
216
217
{
217
218
var styleAttributes = listNode . GetStyles ( ) ;
219
+ bool orderedList = listNode . NodeName . Equals ( "ol" , StringComparison . OrdinalIgnoreCase ) ;
218
220
string ? type = styleAttributes [ "list-style-type" ] ;
219
221
222
+ if ( orderedList && string . IsNullOrEmpty ( type ) )
223
+ {
224
+ type = ListTypeToListStyleType ( listNode . GetAttribute ( "type" ) ) ;
225
+ }
226
+
220
227
if ( string . IsNullOrEmpty ( type ) || ! supportedListTypes . Contains ( type ! ) )
221
228
{
222
229
if ( parentName != null && IsCascadingStyle ( parentName ) )
223
230
return parentName ! ;
224
231
225
- bool orderedList = listNode . NodeName . Equals ( "ol" , StringComparison . OrdinalIgnoreCase ) ;
226
232
type = orderedList ? "decimal" : "disc" ;
227
233
}
228
234
229
235
return type ! ;
230
236
}
231
237
238
+ /// <summary>
239
+ /// Map ordered list style attribute values to css list-style-type.
240
+ /// Valid types are "1|a|A|i|I": https://w3schools.com/tags/att_ol_type.asp
241
+ /// </summary>
242
+ private static string ? ListTypeToListStyleType ( string ? type ) => type switch
243
+ {
244
+ "1" => "decimal" ,
245
+ "a" => "lower-alpha" ,
246
+ "A" => "upper-alpha" ,
247
+ "i" => "lower-roman" ,
248
+ "I" => "upper-roman" ,
249
+ _ => null
250
+ } ;
251
+
232
252
/// <summary>
233
253
/// Resolve the <see cref="ParagraphStyleId"/> of a list element node,
234
254
/// based on its css class if provided and if matching.
@@ -256,4 +276,4 @@ private static bool IsCascadingStyle(string styleName)
256
276
{
257
277
return styleName == "decimal-tiered" ;
258
278
}
259
- }
279
+ }
0 commit comments