Skip to content

Commit 815484e

Browse files
authored
Merge pull request #14 from coderthoughts/fix-replace_sq
Reimplement text grep and replace using the new XML parser
2 parents b59d8ad + b35fa60 commit 815484e

File tree

15 files changed

+703
-41
lines changed

15 files changed

+703
-41
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "docxtools"
3-
version = "0.6.0"
3+
version = "0.6.1-SNAPSHOT"
44
edition = "2021"
55

66
[dependencies]

src/bin/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@ enum Commands {
2828
/// List the links in the document to the console
2929
Links(LinksArgs),
3030

31-
/// Search the text in the document like 'grep'
32-
#[command(name = "_grep")]
31+
/// Search the text in the document
3332
Grep(GrepArgs),
3433

3534
/// Search and replace in document text and tables
36-
#[command(name = "_replace")]
3735
Replace(ReplaceArgs),
3836

3937
/// Search and replace hyperlinks in the document

src/test/test_tree2/word/document.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<w:rPr>
5757
<w:lang w:val="en-US"/>
5858
</w:rPr>
59-
<w:t>And some some more text</w:t>
59+
<w:t>And some some some more text</w:t>
6060
</w:r>
6161
<w:r w:rsidR="00B47895">
6262
<w:rPr>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/><Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/><Override PartName="/word/settings.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"/><Override PartName="/word/webSettings.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml"/><Override PartName="/word/fontTable.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"/><Override PartName="/word/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/><Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/><Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/></Types>

src/test/test_tree5/_rels/.rels

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/></Relationships>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"><Template>Normal.dotm</Template><TotalTime>1</TotalTime><Pages>1</Pages><Words>25</Words><Characters>147</Characters><Application>Microsoft Office Word</Application><DocSecurity>0</DocSecurity><Lines>1</Lines><Paragraphs>1</Paragraphs><ScaleCrop>false</ScaleCrop><Company></Company><LinksUpToDate>false</LinksUpToDate><CharactersWithSpaces>171</CharactersWithSpaces><SharedDoc>false</SharedDoc><HyperlinksChanged>false</HyperlinksChanged><AppVersion>16.0000</AppVersion></Properties>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><dc:title></dc:title><dc:subject></dc:subject><dc:creator>David Bosschaert</dc:creator><cp:keywords></cp:keywords><dc:description></dc:description><cp:lastModifiedBy>David Bosschaert</cp:lastModifiedBy><cp:revision>12</cp:revision><dcterms:created xsi:type="dcterms:W3CDTF">2024-01-10T14:44:00Z</dcterms:created><dcterms:modified xsi:type="dcterms:W3CDTF">2024-01-11T15:34:00Z</dcterms:modified></cp:coreProperties>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings" Target="webSettings.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings" Target="settings.xml"/><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/><Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/><Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable" Target="fontTable.xml"/></Relationships>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:oel="http://schemas.microsoft.com/office/2019/extlst" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16cex="http://schemas.microsoft.com/office/word/2018/wordml/cex" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16="http://schemas.microsoft.com/office/word/2018/wordml" xmlns:w16sdtdh="http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se w16cid w16 w16cex w16sdtdh wp14">
3+
<w:body>
4+
<w:p w14:paraId="02E73067" w14:textId="7A388614" w:rsidR="00F91FDE" w:rsidRPr="009E18F5" w:rsidRDefault="008D3912">
5+
<w:pPr>
6+
<w:rPr>
7+
<w:lang w:val="en-US"/>
8+
</w:rPr>
9+
</w:pPr>
10+
<w:r>
11+
<w:rPr>
12+
<w:lang w:val="en-US"/>
13+
</w:rPr>
14+
<w:t>Notwithstanding the eventual re</w:t>
15+
</w:r>
16+
<w:r w:rsidRPr="00C848EB">
17+
<w:rPr>
18+
<w:lang w:val="en-US"/>
19+
</w:rPr>
20+
<w:t>sult</w:t>
21+
</w:r>
22+
<w:r>
23+
<w:rPr>
24+
<w:lang w:val="en-US"/>
25+
</w:rPr>
26+
<w:t>ing quotations punters were agreeable to a technocratic compromise.</w:t>
27+
</w:r>
28+
<w:r w:rsidR="00F91FDE">
29+
<w:rPr>
30+
<w:lang w:val="en-US"/>
31+
</w:rPr>
32+
<w:br/>
33+
<w:t>Here’s ano</w:t>
34+
</w:r>
35+
<w:r w:rsidR="00F91FDE" w:rsidRPr="00871B04">
36+
<w:rPr>
37+
<w:lang w:val="en-US"/>
38+
</w:rPr>
39+
<w:t>ther line of te</w:t>
40+
</w:r>
41+
<w:r w:rsidR="00F91FDE" w:rsidRPr="009E18F5">
42+
<w:rPr>
43+
<w:lang w:val="en-US"/>
44+
</w:rPr>
45+
<w:t>xt.</w:t>
46+
</w:r>
47+
</w:p>
48+
<w:p w14:paraId="79854F5F" w14:textId="57F47D9A" w:rsidR="00F91FDE" w:rsidRPr="008D3912" w:rsidRDefault="00F91FDE">
49+
<w:pPr>
50+
<w:rPr>
51+
<w:lang w:val="en-US"/>
52+
</w:rPr>
53+
</w:pPr>
54+
<w:r w:rsidRPr="009E18F5">
55+
<w:rPr>
56+
<w:lang w:val="en-US"/>
57+
</w:rPr>
58+
<w:t>And th</w:t>
59+
</w:r>
60+
<w:r>
61+
<w:rPr>
62+
<w:lang w:val="en-US"/>
63+
</w:rPr>
64+
<w:t xml:space="preserve">is text is in the </w:t>
65+
</w:r>
66+
<w:r w:rsidRPr="00680CCD">
67+
<w:rPr>
68+
<w:lang w:val="en-US"/>
69+
</w:rPr>
70+
<w:t>next para</w:t>
71+
</w:r>
72+
<w:r>
73+
<w:rPr>
74+
<w:lang w:val="en-US"/>
75+
</w:rPr>
76+
<w:t>graph.</w:t>
77+
</w:r>
78+
</w:p>
79+
<w:sectPr w:rsidR="00F91FDE" w:rsidRPr="008D3912">
80+
<w:pgSz w:w="11906" w:h="16838"/>
81+
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/>
82+
<w:cols w:space="708"/>
83+
<w:docGrid w:linePitch="360"/>
84+
</w:sectPr>
85+
</w:body>
86+
</w:document>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<w:fonts xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16cex="http://schemas.microsoft.com/office/word/2018/wordml/cex" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16="http://schemas.microsoft.com/office/word/2018/wordml" xmlns:w16sdtdh="http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" mc:Ignorable="w14 w15 w16se w16cid w16 w16cex w16sdtdh"><w:font w:name="Calibri"><w:panose1 w:val="020F0502020204030204"/><w:charset w:val="00"/><w:family w:val="swiss"/><w:pitch w:val="variable"/><w:sig w:usb0="E4002EFF" w:usb1="C200247B" w:usb2="00000009" w:usb3="00000000" w:csb0="000001FF" w:csb1="00000000"/></w:font><w:font w:name="Times New Roman"><w:panose1 w:val="02020603050405020304"/><w:charset w:val="00"/><w:family w:val="roman"/><w:pitch w:val="variable"/><w:sig w:usb0="E0002EFF" w:usb1="C000785B" w:usb2="00000009" w:usb3="00000000" w:csb0="000001FF" w:csb1="00000000"/></w:font><w:font w:name="Calibri Light"><w:panose1 w:val="020F0302020204030204"/><w:charset w:val="00"/><w:family w:val="swiss"/><w:pitch w:val="variable"/><w:sig w:usb0="E4002EFF" w:usb1="C200247B" w:usb2="00000009" w:usb3="00000000" w:csb0="000001FF" w:csb1="00000000"/></w:font></w:fonts>

0 commit comments

Comments
 (0)