From 7389919bb491b78373ea2197800988b3a61cf0ce Mon Sep 17 00:00:00 2001 From: Ben Steinberg Date: Sat, 21 Sep 2019 01:13:29 -0400 Subject: Preserve built-in styles in DOCX with custom style (#5670) This commit prevents custom styles on divs and spans from overriding styles on certain elements inside them, like headings, blockquotes, and links. On those elements, the "native" style is required for the element to display correctly. This change also allows nesting of custom styles; in order to do so, it removes the default "Compact" style applied to Plain blocks, except when inside a table. --- test/docx/custom-style-preserve.native | 15 +++++++++++++++ test/docx/golden/custom_style_preserve.docx | Bin 0 -> 10595 bytes test/docx/golden/document-properties.docx | Bin 10358 -> 10350 bytes 3 files changed, 15 insertions(+) create mode 100644 test/docx/custom-style-preserve.native create mode 100644 test/docx/golden/custom_style_preserve.docx (limited to 'test/docx') diff --git a/test/docx/custom-style-preserve.native b/test/docx/custom-style-preserve.native new file mode 100644 index 000000000..859f71c20 --- /dev/null +++ b/test/docx/custom-style-preserve.native @@ -0,0 +1,15 @@ +[Para [Span ("",[],[("custom-style","MyStyle")]) [Str "This",Space,Str "span",Note [Para [Str "Neither",Space,Str "footnote",Space,Str "nor",Space,Str "footnote",Space,Str "reference",Space,Str "should",Space,Str "get",Space,Str "a",Space,Str "custom",Space,Str "style",Space,Str "from",Space,Str "its",Space,Str "span."]],Space,Str "should",Space,Str "have",Space,Str "a",Space,Str "custom",Space,Str "style",Space,Str "(",Link ("",[],[]) [Str "link"] ("http://example.com/",""),Str "),"],Space,Str "but",Space,Str "the",Space,Str "text",Space,Str "after",Space,Str "the",Space,Str "comma",Space,Str "shouldn\8217t,",Space,Str "nor",Space,Str "should",Space,Str "the",Space,Str "link."] +,Div ("",[],[("custom-style","MyOtherStyle")]) + [Para [Str "The",Space,Str "contents",Space,Str "of",Space,Str "this",Space,Str "div",Space,Str "should",Space,Str "have",Space,Str "a",Space,Str "custom",Space,Str "style,",Space,Str "but",Space,Link ("",[],[]) [Str "this",Space,Str "link",Space,Str "should",Space,Str "not"] ("http://example.com/",""),Str "."] + ,Header 2 ("this-header-should-not-have-the-divs-custom-style",[],[]) [Str "This",Space,Str "header",Space,Str "should",Space,Str "not",Space,Str "have",Space,Str "the",Space,Str "div\8217s",Space,Str "custom",Space,Str "style"] + ,BlockQuote + [Para [Str "This",Space,Str "blockquote",Space,Str "should",Space,Str "not."]] + ,CodeBlock ("",[],[]) "# This code block should not." + ,Para [Str "But",Space,Str "this",Space,Str "paragraph",Space,Str "should.",Note [Para [Str "Neither",Space,Str "footnote",Space,Str "nor",Space,Str "footnote",Space,Str "reference",Space,Str "should",Space,Str "get",Space,Str "a",Space,Str "custom",Space,Str "style",Space,Str "from",Space,Str "its",Space,Str "div."]]]] +,Div ("",[],[("custom-style","MyOuterStyle")]) + [Div ("",[],[("custom-style","MyInnerStyle")]) + [Para [Str "This",Space,Str "should",Space,Str "have",Space,Str "MyInnerStyle."] + ,Header 3 ("this-heading-should-not",[],[]) [Str "This",Space,Str "heading",Space,Str "should",Space,Str "not"]] + ,Para [Str "This",Space,Str "should",Space,Str "have",Space,Str "MyOuterStyle,",Space,Str "but",Space,Str "the",Space,Str "following",Space,Str "elision",Space,Str "should",Space,Str "have",Space,Str "its",SoftBreak,Str "own",Space,Str "style.",Space,Span ("",[],[("custom-style","Elision")]) [Str "..."]] + ,BlockQuote + [Para [Str "This",Space,Str "blockquote",Space,Str "should",Space,Str "include",Space,Strong [Str "bold",Space,Str "text",Space,Str "with",Space,Str "an",Space,Str "elision:",SoftBreak,Span ("",[],[("custom-style","Elision")]) [Str "..."]]]]]] diff --git a/test/docx/golden/custom_style_preserve.docx b/test/docx/golden/custom_style_preserve.docx new file mode 100644 index 000000000..06371d51e Binary files /dev/null and b/test/docx/golden/custom_style_preserve.docx differ diff --git a/test/docx/golden/document-properties.docx b/test/docx/golden/document-properties.docx index 00c78bc0f..8bb498e02 100644 Binary files a/test/docx/golden/document-properties.docx and b/test/docx/golden/document-properties.docx differ -- cgit v1.2.3