-
Notifications
You must be signed in to change notification settings - Fork 11
/
build-word2dita.xml
254 lines (211 loc) · 9.08 KB
/
build-word2dita.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<?xml version="1.0" encoding="UTF-8"?>
<project name="org.dita4publishers.word2dita" default="word2dita">
<!-- NOTE: This is copied from build_init.xml in the main OT.
The dita.plugin.org.dita.base.dir property may or may not be set
automatically.
-->
<xmlcatalog id="dita.catalog">
<catalogpath path="${dita.plugin.org.dita.base.dir}/catalog-dita.xml"/>
</xmlcatalog>
<!--
<tstamp/>
-->
<target name="checkWordDoc">
<available property="w2d.have.word.doc" file="${word.doc}"/>
</target>
<target name="checkParameters" depends="checkWordDoc"
unless="w2d.have.word.doc"
>
<echo message=" [ERROR] Could not find Word document '${word.doc}'"/>
<echo message=" [ERROR] You must specify the parameter 'word.doc' with the full path to the Word DOCX file to be converted."
level="error"
/>
</target>
<target name="word2dita" description="Converts a Word DOCX document to DITA maps and topics"
depends="checkParameters, doWord2Dita"
>
</target>
<target name="initProperties">
<dirname property="w2d.base.dir" file="${ant.file}"/>
<property name="w2d.temp.dir" location="${basedir}/temp"/>
<property name="w2d.out.dir" location="${w2d.temp.dir}/dita"/>
<property name="xsl.dir" location="${w2d.base.dir}/xsl"/>
<property name="w2d.debug.xslt" value="false"/><!-- Set to "true" to turn on XSLT debug messages -->
<property name="w2d.clean.output.dir" value="false"/>
<condition property="clean.temp.dir" value="true">
<not>
<isset property="w2d.clean.temp.dir"/>
</not>
</condition>
<condition property="clean.temp.dir" value="${w2d.clean.temp.dir}">
<isset property="w2d.clean.temp.dir"/>
</condition>
<condition property="doCleanTempDir" value="true">
<or>
<equals arg1="clean.temp.dir" arg2="true"/>
<equals arg1="clean.temp.dir" arg2="yes"/>
<equals arg1="clean.temp.dir" arg2="on"/>
</or>
</condition>
<property name="word.doc" value="word.doc not set"/>
<basename
property="word.doc.basename"
file="${word.doc}"
suffix=".docx"
/>
<property name="w2d.defaultStyleToTagMap"
location="${xsl.dir}/word-builtin-styles-style2tagmap.xml"/>
<condition property="w2d.style-to-tag-map" value="${w2d.defaultStyleToTagMap}">
<not>
<isset property="w2d.style-to-tag-map"/>
</not>
</condition>
<condition property="w2d.generate.navtitles" value="true">
<not>
<isset property="w2d.generate.navtitles"/>
</not>
</condition>
<condition property="w2d.language" value="en-US">
<not>
<isset property="w2d.language"/>
</not>
</condition>
<condition property="w2d.topic.extension" value=".dita">
<not>
<isset property="w2d.topic.extension"/>
</not>
</condition>
<condition property="w2d.root.map.name" value="${word.doc.basename}">
<and>
<not>
<isset property="w2d.root.topic.name"/>
</not>
<not>
<isset property="w2d.root.map.name"/>
</not>
</and>
</condition>
<condition property="w2d.root.topic.name" value="${word.doc.basename}" >
<and>
<not>
<isset property="w2d.root.topic.name"/>
</not>
<not>
<isset property="w2d.root.map.name"/>
</not>
</and>
</condition>
<condition property="w2d.root.output.filename" value="${w2d.root.topic.name}${w2d.topic.extension}">
<and>
<isset property="w2d.root.topic.name"/>
<not>
<isset property="w2d.root.output.filename"/>
</not>
<not>
<isset property="w2d.root.map.name"/>
</not>
</and>
</condition>
<condition property="w2d.root.output.filename" value="delete.me">
<and>
<isset property="w2d.root.map.name"/>
<not>
<isset property="w2d.root.output.filename"/>
</not>
</and>
</condition>
<property name="w2d.word2dita.xslt" location="${xsl.dir}/docx2dita.xsl"/>
<condition property="w2p.do.clean.output.dir">
<or>
<equals arg1="${w2d.clean.output.dir}" arg2="true" casesensitive="false"/>
<equals arg1="${w2d.clean.output.dir}" arg2="yes" casesensitive="false"/>
<equals arg1="${w2d.clean.output.dir}" arg2="on" casesensitive="false"/>
</or>
</condition>
<echo message="+++ word2dita-specific properties:"/>
<echoproperties format="text" regex="^(w2d*)" taskname="echo"/>
</target>
<target name="doWord2Dita" depends="initProperties">
<mkdir dir="${w2d.temp.dir}"/>
<property name="word.document.xml.path" location="${w2d.temp.dir}/${word.doc.basename}/word/document.xml"/>
<antcall target="unzipWordDoc"/>
<echo message="w2d.style-to-tag-map='${w2d.style-to-tag-map}'"/>
<antcall target="transformWordToDita">
<param name="word.document.xml.path" value="${word.document.xml.path}"/>
</antcall>
<antcall target="clean.temp"/>
</target>
<target name="clean.temp" if="doCleanTempDir">
<delete dir="${w2d.temp.dir}" failonerror="true" includeemptydirs="true">
<include name="**/*"/>
</delete>
</target>
<target name="unzipWordDoc">
<unzip dest="${w2d.temp.dir}/${word.doc.basename}" overwrite="yes"
src="${word.doc}"
>
</unzip>
</target>
<target name="cleanOutputDir" if="w2p.do.clean.output.dir">
<echo message="[INFO] Cleaning output directory ${w2d.out.dir}..."/>
<delete dir="${w2d.out.dir}" failonerror="true" includeemptydirs="true">
<include name="**/*"/>
</delete>
</target>
<target name="transformWordToDita" depends="cleanOutputDir">
<echo message="[INFO] Creating output directory ${w2d.out.dir}..."/>
<echo message="[INFO] Creating output file ${w2d.root.output.filename}..."/>
<mkdir dir="${w2d.out.dir}"/>
<makeurl property="styleMapUri.url" file="${w2d.style-to-tag-map}"/>
<makeurl property="outputDir.url" file="${w2d.out.dir}"/>
<makeurl property="mediaDirUri.url" file="${w2d.media.dir}" validate="false"/>
<echo message="[INFO] Generating DITA documents from Word document in output directory ${w2d.out.dir}..."/>
<echo message="[INFO] Using XSLT ${w2d.word2dita.xslt}..."/>
<xslt style="${w2d.word2dita.xslt}"
in="${word.document.xml.path}"
out="${w2d.out.dir}/${w2d.root.output.filename}"
>
<param name="styleMapUri" expression="${styleMapUri.url}"/>
<param name="mediaDirUri" expression="${mediaDirUri.url}" if="w2d.media.dir"/>
<param name="rootMapName" expression="${w2d.root.map.name}" if="w2d.root.map.name"/>
<!-- NOTE: Last value specified wins, so put w2d.root.topic.name last -->
<param name="rootTopicName" expression="${w2d.root.map.name}" if="w2d.root.map.name"/>
<param name="rootTopicName" expression="${w2d.root.topic.name}" if="w2d.root.topic.name"/>
<param name="submapNamePrefix" expression="${w2d.submap.name.prefix}" if="w2d.submap.name.prefix"/>
<param name="outputDir" expression="${outputDir.url}"/>
<param name="debug" expression="${w2d.debug.xslt}"/>
<param name="rawPlatformString" expression="${os.name}"/>
<param name="filterBr" expression="${w2d.filter.br}" if="w2d.filter.br"/>
<param name="filterTabs" expression="${w2d.filter.tabs}" if="w2d.filter.tabs"/>
<param name="includeWordBackPointers" expression="${w2d.include.word.backpointers}" if="w2d.include.word.backpointers"/>
<param name="topicExtension" expression="${w2d.topic.extension}" if="w2d.topic.extension"/>
<param name="includeWordBookmarks" expression="${w2d.include.word.bookmarks}" if="w2d.include.word.bookmarks"/>
<param name="fileNamePrefix" expression="${w2d.filename.prefix}" if="w2d.filename.prefix"/>
<param name="submapNamePrefix" expression="${w2d.submap.name.prefix}" if="w2d.submap.name.prefix"/>
<param name="language" expression="${w2d.language}" if="w2d.language"/>
<param name="generateNavtitles" expression="${w2d.generate.navtitles}"
if="w2d.generate.navtitles"
/>
<param name="topicNumberFormat" expression="${w2d.topic.number.format}"
if="w2d.topic.number.format"
/>
<param name="mapNumberFormat" expression="${w2d.map.number.format}"
if="w2d.map.number.format"
/>
<param name="tableWidthsProportional" expression="${w2d.table.widths.proportional}"
if="w2d.table.widths.proportional"
/>
<param name="ditaVersion" expression="${w2d.dita.version}" if="w2d.ditaversion"/>
<!-- Issue 79: Make capture of format overrides switchable -->
<param name="putFormatOverridesInOutputclass" expression="${w2d.put.format.overrides.in.outputclass}" if="w2d.put.format.overrides.in.outputclass"/>
<!-- Issue 79: Make capture of format overrides switchable -->
<param name="putFormatOverridesInBaseAtt" expression="${w2d.put.format.overrides.in.base.att}" if="w2d.put.format.overrides.in.base.att"/>
<!-- Issue 82: Make putStyleNameInOutputclass switchable -->
<param name="putStyleNameInOutputclass" expression="${w2d.put.style.name.in.outputclass}" if="w2d.put.style.name.in.outputclass"/>
<!-- Issue 82: Make putStyleNameInBaseAtt switchable -->
<param name="putStyleNameInBaseAtt" expression="${w2d.put.style.name.in.base.att}" if="w2d.put.style.name.in.base.att"/>
<xmlcatalog refid="dita.catalog"></xmlcatalog>
</xslt>
<echo>[INFO] Transform complete</echo>
</target>
</project>