@@ -40,26 +40,43 @@ public override IEnumerable<OpenXmlElement> Interpret (ParsingContext context)
40
40
41
41
paragraph ??= new ( childElements ) ;
42
42
paragraph . ParagraphProperties ??= new ( ) ;
43
- paragraph . ParagraphProperties . ParagraphStyleId =
44
- context . DocumentStyle . GetParagraphStyle ( context . DocumentStyle . DefaultStyles . HeadingStyle + level ) ;
45
-
43
+
46
44
var runElement = childElements . FirstOrDefault ( ) ;
47
45
if ( runElement != null && context . Converter . SupportsHeadingNumbering && IsNumbering ( runElement ) )
48
46
{
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 ) )
52
48
{
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 ) ;
54
69
}
55
70
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 ) ;
63
80
}
64
81
65
82
return [ paragraph ] ;
0 commit comments