File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ def content
1313
1414 def content = ( args )
1515 @node . content = args
16+ # Without xml:space="preserve", Word drops leading and trailing spaces.
17+ @node [ 'xml:space' ] = 'preserve' if args . to_s . match? ( /\A \s |\s \z / )
1618 end
1719
1820 def initialize ( node )
Original file line number Diff line number Diff line change 2323
2424 expect ( node . content ) . to eq ( 'world' )
2525 end
26+
27+ # Regression tests for #187: without xml:space="preserve", Word drops
28+ # leading and trailing spaces of a w:t.
29+ it 'marks the node xml:space="preserve" when the content has a trailing space' do
30+ text . content = 'Jane '
31+
32+ expect ( node . to_xml ) . to eq ( '<w:t xml:space="preserve">Jane </w:t>' )
33+ end
34+
35+ it 'marks the node xml:space="preserve" when the content has a leading space' do
36+ text . content = ' end'
37+
38+ expect ( node . to_xml ) . to eq ( '<w:t xml:space="preserve"> end</w:t>' )
39+ end
40+
41+ it 'does not add xml:space when the content has no surrounding whitespace' do
42+ text . content = 'Jane'
43+
44+ expect ( node . to_xml ) . to eq ( '<w:t>Jane</w:t>' )
45+ end
46+
47+ it 'keeps an existing xml:space="preserve"' do
48+ node = w_node ( '<w:t xml:space="preserve"> a </w:t>' )
49+
50+ described_class . new ( node ) . content = 'b'
51+
52+ expect ( node . to_xml ) . to eq ( '<w:t xml:space="preserve">b</w:t>' )
53+ end
2654 end
2755end
You can’t perform that action at this time.
0 commit comments