@@ -50,8 +50,20 @@ protected int GetOrCreateListTemplate(ParsingContext context, string listName)
5050
5151 Numbering numberingPart = context . MainPart . NumberingDefinitionsPart ! . Numbering ! ;
5252
53+ AbstractNum abstractNum ;
54+
5355 // at this stage, we have sanitized the list style so it's safe to grab them from the predefined template lists
54- var abstractNum = predefinedNumberingLists [ listName ] ;
56+ if ( predefinedNumberingLists . TryGetValue ( listName , out var predefined ) )
57+ {
58+ // If it's a predefined style, we clone it as usual
59+ abstractNum = ( AbstractNum ) predefined . CloneNode ( true ) ;
60+ }
61+ else
62+ {
63+ // If not found in predefined lists, listName contains a custom bullet character (e.g., "-")
64+ abstractNum = CreateCustomBulletAbstractNum ( listName ) ;
65+ }
66+
5567 abstractNum = ( AbstractNum ) abstractNum . CloneNode ( true ) ;
5668 abstractNum . AbstractNumberId = IncrementAbstractNumId ( context , numberingPart ) ;
5769 var level1 = abstractNum . GetFirstChild < Level > ( ) ! ;
@@ -216,6 +228,38 @@ private void InitNumberingIds(ParsingContext context)
216228 isInitialized = true ;
217229 }
218230
231+ /// <summary>
232+ /// Generates a custom abstract numbering definition for unordered lists using a specific symbol.
233+ /// </summary>
234+ /// <param name="customSymbol">The custom character or string to be used as the list bullet.</param>
235+ /// <returns>An <see cref="AbstractNum"/> instance configured with the custom bullet symbol across all levels.</returns>
236+ private AbstractNum CreateCustomBulletAbstractNum ( string customSymbol )
237+ {
238+ var abstractNum = new AbstractNum {
239+ AbstractNumDefinitionName = new ( ) { Val = customSymbol } ,
240+ MultiLevelType = new ( ) { Val = MultiLevelValues . HybridMultilevel }
241+ } ;
242+
243+ for ( var lvlIndex = 0 ; lvlIndex <= MaxLevel ; lvlIndex ++ )
244+ {
245+ abstractNum . Append ( new Level {
246+ StartNumberingValue = new ( ) { Val = 1 } ,
247+ NumberingFormat = new ( ) { Val = NumberFormatValues . Bullet } ,
248+ LevelIndex = lvlIndex ,
249+ LevelText = new ( ) { Val = string . Format ( customSymbol , lvlIndex + 1 ) } ,
250+ LevelJustification = new ( ) { Val = LevelJustificationValues . Left } ,
251+ PreviousParagraphProperties = new ( ) {
252+ Indentation = new ( ) {
253+ Left = ( ( lvlIndex + 1 ) * Indentation * 2 ) . ToString ( ) ,
254+ Hanging = Indentation . ToString ( )
255+ }
256+ }
257+ } ) ;
258+ }
259+
260+ return abstractNum ;
261+ }
262+
219263 /// <summary>
220264 /// Predefined template of lists.
221265 /// </summary>
@@ -230,6 +274,7 @@ private static IReadOnlyDictionary<string, AbstractNum> InitKnownLists()
230274 ( "disc" , NumberFormatValues . Bullet , "•" ) ,
231275 ( "square" , NumberFormatValues . Bullet , "▪" ) ,
232276 ( "circle" , NumberFormatValues . Bullet , "o" ) ,
277+ ( "dash" , NumberFormatValues . Bullet , "-" ) ,
233278 ( "upper-alpha" , NumberFormatValues . UpperLetter , "%{0}." ) ,
234279 ( "lower-alpha" , NumberFormatValues . LowerLetter , "%{0}." ) ,
235280 ( "upper-roman" , NumberFormatValues . UpperRoman , "%{0}." ) ,
@@ -299,4 +344,4 @@ private static IReadOnlyDictionary<string, AbstractNum> InitKnownLists()
299344 return knownAbstractNums ;
300345#endif
301346 }
302- }
347+ }
0 commit comments