@@ -40,26 +40,43 @@ public override IEnumerable<OpenXmlElement> Interpret (ParsingContext context)
4040
4141 paragraph ??= new ( childElements ) ;
4242 paragraph . ParagraphProperties ??= new ( ) ;
43- paragraph . ParagraphProperties . ParagraphStyleId =
44- context . DocumentStyle . GetParagraphStyle ( context . DocumentStyle . DefaultStyles . HeadingStyle + level ) ;
45-
43+
4644 var runElement = childElements . FirstOrDefault ( ) ;
4745 if ( runElement != null && context . Converter . SupportsHeadingNumbering && IsNumbering ( runElement ) )
4846 {
49- var abstractNumId = GetOrCreateListTemplate ( context , HeadingNumberingName ) ;
50- var instanceId = GetListInstance ( abstractNumId ) ;
51- if ( ! instanceId . HasValue )
47+ if ( string . Equals ( context . DocumentStyle . DefaultStyles . HeadingStyle , context . DocumentStyle . DefaultStyles . NumberedHeadingStyle ) )
5248 {
53- instanceId = IncrementInstanceId ( context , abstractNumId ) ;
49+ // Only apply the numbering if a custom numbered heading style has not been defined.
50+ // If the user defined a custom numbered heading style (with numbering), Word has
51+ // the numbering automatically done.
52+ // Defining a numbering here messes that up, so we only add the numbering if
53+ // a specific numbering heading style has not been provided
54+ var abstractNumId = GetOrCreateListTemplate ( context , HeadingNumberingName ) ;
55+ var instanceId = GetListInstance ( abstractNumId ) ;
56+
57+ if ( ! instanceId . HasValue )
58+ {
59+ instanceId = IncrementInstanceId ( context , abstractNumId ) ;
60+ }
61+
62+ var numbering = context . MainPart . NumberingDefinitionsPart ! . Numbering ! ;
63+ numbering . Append (
64+ new NumberingInstance (
65+ new AbstractNumId ( ) { Val = abstractNumId }
66+ )
67+ { NumberID = instanceId } ) ;
68+ SetNumbering ( paragraph , level - '0' , instanceId . Value ) ;
5469 }
5570
56- var numbering = context . MainPart . NumberingDefinitionsPart ! . Numbering ! ;
57- numbering . Append (
58- new NumberingInstance (
59- new AbstractNumId ( ) { Val = abstractNumId }
60- )
61- { NumberID = instanceId } ) ;
62- SetNumbering ( paragraph , level - '0' , instanceId . Value ) ;
71+ // Apply numbered heading style
72+ paragraph . ParagraphProperties . ParagraphStyleId =
73+ context . DocumentStyle . GetParagraphStyle ( context . DocumentStyle . DefaultStyles . NumberedHeadingStyle + level ) ;
74+ }
75+ else
76+ {
77+ // Apply normal heading style
78+ paragraph . ParagraphProperties . ParagraphStyleId =
79+ context . DocumentStyle . GetParagraphStyle ( context . DocumentStyle . DefaultStyles . HeadingStyle + level ) ;
6380 }
6481
6582 return [ paragraph ] ;
0 commit comments