-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprocess_prismjs.xml
203 lines (181 loc) · 5.64 KB
/
process_prismjs.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
<?xml version="1.0" encoding="UTF-8"?>
<!--ant-->
<!--
This file is part of the DITA-OT Prism-JS Plug-in project.
See the accompanying LICENSE file for applicable licenses.
-->
<project
xmlns:if="ant:if"
xmlns:unless="ant:unless"
xmlns:dita="http://dita-ot.sourceforge.net"
name="fox.jason.prismjs"
>
<target name="prismjs.css.copy">
<condition property="prism.use.theme" value="bootstrap-contrast">
<or>
<equals arg1="${bootstrap.theme}" arg2="cerulean"/>
<equals arg1="${bootstrap.theme}" arg2="darkly"/>
<equals arg1="${bootstrap.theme}" arg2="flatly"/>
<equals arg1="${bootstrap.theme}" arg2="sandstone"/>
<equals arg1="${bootstrap.theme}" arg2="spacelab"/>
<equals arg1="${bootstrap.theme}" arg2="zephyr"/>
</or>
</condition>
<condition property="prism.use.theme" value="bootstrap-vapor">
<equals arg1="${bootstrap.theme}" arg2="vapor"/>
</condition>
<condition property="prism.use.theme" value="bootstrap" else="default">
<isset property="dita.plugin.net.infotexture.dita-bootstrap.dir"/>
</condition>
<property
name="prism.css.theme"
value="${dita.plugin.fox.jason.prismjs.dir}/css/${prism.use.theme}-theme.css"
/>
<loadfile property="theme.css" srcFile="${prism.css.theme}"/>
<echo
append="true"
message="${line.separator}${theme.css}"
file="${extend.css.file}"
/>
<property
name="prismjs.css.file"
value="${dita.plugin.fox.jason.prismjs.dir}/css/style.css"
/>
<loadfile property="prism.css" srcFile="${prismjs.css.file}"/>
<echo
append="true"
message="${line.separator}${prism.css}"
file="${extend.css.file}"
/>
</target>
<target name="highlight.check">
<!-- Only run the Highlight transform for HTML or PDF -->
<condition property="prismjs.highlightable">
<or>
<equals arg1="${out.ext}" arg2=".html"/>
<isset property="axf.formatter.output-format"/>
<isset property="fop.formatter.output-format"/>
<isset property="xep.formatter.output-format"/>
<!-- add any additional missing transtypes here -->
<contains string="${transtype}" substring="HTML" casesensitive="no"/>
<contains string="${transtype}" substring="PDF" casesensitive="no"/>
<contains
string="${transtype}"
substring="eclipsehelp"
casesensitive="no"
/>
</or>
</condition>
<condition property="is.html">
<equals arg1="${out.ext}" arg2=".html"/>
</condition>
<condition property="prismjs.memory">
<and>
<equals arg1="${store-type}" arg2="memory"/>
<isset property="prismjs.highlightable"/>
</and>
</condition>
<dita-ot-echo id="PRSM004W" if:set="prismjs.memory"/>
</target>
<!--
Check if Node is installed.
-->
<target
name="node.check"
if="prismjs.highlightable"
description="Ensure that Node.js is available">
<!-- For Unix run node as an executable -->
<exec
executable="node"
dir="${dita.dir}"
osfamily="unix"
taskname="node"
resultproperty="node.result"
outputproperty="node.out"
failonerror="false"
failifexecutionfails="false"
>
<arg line="-v"/>
</exec>
<!-- For Windows run from a DOS command -->
<exec
executable="cmd"
dir="${dita.dir}"
osfamily="windows"
taskname="node"
resultproperty="node.result"
outputproperty="node.out"
failonerror="false"
failifexecutionfails="false"
>
<arg value="/C"/>
<arg value="node -v"/>
</exec>
<condition property="node.installed">
<equals arg1="${node.result}" arg2="0"/>
</condition>
<dita-ot-fail unless:set="node.installed" id="PRSM003F"/>
</target>
<target name="highlight.init">
<typedef file="${dita.plugin.fox.jason.prismjs.dir}/resource/antlib.xml"/>
<property
name="prismjs.node.script"
value="${dita.plugin.fox.jason.prismjs.dir}/resource/node-prism.js"
/>
<tempfile
deleteonexit="true"
destdir="${dita.temp.dir}"
property="prismjs.temp.file"
suffix=".js"
/>
<copy
file="${dita.plugin.fox.jason.prismjs.dir}/resource/prism.js"
toFile="${prismjs.temp.file}"
/>
<tempfile
deleteonexit="true"
destdir="${dita.temp.dir}"
property="prismjs.unknown.file"
suffix=".txt"
/>
<touch file="${prismjs.unknown.file}"/>
<property
name="prism.component.dir"
value="${dita.plugin.fox.jason.prismjs.dir}/resource/components"
/>
</target>
<target
name="highlight"
if="prismjs.highlightable"
description="Highlight codeblocks using Prism.js">
<basename property="prism.temp.dirname" file="${dita.temp.dir}"/>
<restrict id="prismjs.ditafileset">
<ditafileset processingRole="normal">
<excludes format="ditamap"/>
<excludes format="ditaval"/>
<excludes format="image"/>
</ditafileset>
<and>
<or>
<contains text="<codeph"/>
<contains text="<codeblock"/>
</or>
<name regex="\/${prism.temp.dirname}\/" handledirsep="true"/>
</and>
</restrict>
<pathconvert
property="prismjs.ditafiles"
refid="prismjs.ditafileset"
pathsep=";"
>
<map from="file:" to=""/>
</pathconvert>
<iterate-ditafiles
list="${prismjs.ditafiles}"
macro="highlight-dita-file"
unless:blank="${prismjs.ditafiles}"
/>
</target>
<target name="prismjs" depends="highlight.init, highlight"/>
<target name="prismjs.init" depends="highlight.check, node.check"/>
</project>