1 { fetchurl, lib, stdenv, python3
2 , fetchFromGitHub, autoreconfHook
4 , enableStandardFeatures ? false
25 # if true, enable all the below filters and backends
26 , enableExtraPlugins ? false
28 # unzip is needed to extract filter and backend plugins
31 , enableDitaaFilter ? false, jre
32 , enableMscgenFilter ? false, mscgen
33 , enableDiagFilter ? false, blockdiag, seqdiag, actdiag, nwdiag
34 , enableQrcodeFilter ? false, qrencode
35 , enableMatplotlibFilter ? false, matplotlib, numpy
36 , enableAafigureFilter ? false, aafigure, recursivePthLoader
38 , enableDeckjsBackend ? false
39 , enableOdfBackend ? false
41 # java is problematic on some platforms, where it is unfree
49 _enableDitaaFilter = (enableExtraPlugins && enableJava) || enableDitaaFilter;
50 _enableMscgenFilter = enableExtraPlugins || enableMscgenFilter;
51 _enableDiagFilter = enableExtraPlugins || enableDiagFilter;
52 _enableQrcodeFilter = enableExtraPlugins || enableQrcodeFilter;
53 _enableMatplotlibFilter = enableExtraPlugins || enableMatplotlibFilter;
54 _enableAafigureFilter = enableExtraPlugins || enableAafigureFilter;
55 _enableDeckjsBackend = enableExtraPlugins || enableDeckjsBackend;
56 _enableOdfBackend = enableExtraPlugins || enableOdfBackend;
62 ditaaFilterSrc = fetchurl {
63 url = "https://asciidoc-ditaa-filter.googlecode.com/files/ditaa-filter-1.1.zip";
64 sha256 = "0p7hm2a1xywx982ia3vg4c0lam5sz0xknsc10i2a5vswy026naf6";
67 mscgenFilterSrc = fetchurl {
68 url = "https://asciidoc-mscgen-filter.googlecode.com/files/mscgen-filter-1.2.zip";
69 sha256 = "1nfwmj375gpv5dn9i770pjv59aihzy2kja0fflsk96xwnlqsqq61";
72 diagFilterSrc = fetchurl {
73 # unfortunately no version number
74 url = "https://asciidoc-diag-filter.googlecode.com/files/diag_filter.zip";
75 sha256 = "1qlqrdbqkdqqgfdhjsgdws1al0sacsyq6jmwxdfy7r8k7bv7n7mm";
78 qrcodeFilterSrc = fetchurl {
79 url = "https://asciidoc-qrencode-filter.googlecode.com/files/qrcode-filter-1.0.zip";
80 sha256 = "0h4bql1nb4y4fmg2yvlpfjhvy22ln8jsaxdr10f8bfcg5lr0zkxs";
83 # there are no archives or tags, using latest commit in master branch as per 2013-09-22
84 matplotlibFilterSrc = let commit = "75f0d009629f93f33fab04b83faca20cc35dd358"; in fetchurl {
85 name = "mplw-${commit}.tar.gz";
86 url = "https://api.github.com/repos/lvv/mplw/tarball/${commit}";
87 sha256 = "0yfhkm2dr8gnp0fcg25x89hwiymkri2m5cyqzmzragzwj0hbmcf1";
90 aafigureFilterSrc = fetchurl {
91 url = "https://asciidoc-aafigure-filter.googlecode.com/files/aafigure-filter-1.1.zip";
92 sha256 = "1hq2s30dvmv5dqvj0xm1qwdwafhgm9w1iyr0lr0c40cyk8h00j8j";
99 deckjsBackendSrc = fetchurl {
100 url = "https://github.com/downloads/houqp/asciidoc-deckjs/deckjs-1.6.2.zip";
101 sha256 = "1siy1j8naj5irrrrv5bfgl4d8nal6j9pyahy4f50wmrr9wv59s46";
104 # the odf backend is actually two plugins: odt + odp
105 odtBackendSrc = fetchurl {
106 url = "https://github.com/downloads/dagwieers/asciidoc-odf/odt-backend-0.1.zip";
107 sha256 = "1zaa97h9sx6ncxcdkl1x3ggydi7f8kjgvrnpjnkjiizi45k350kw";
110 odpBackendSrc = fetchurl {
111 url = "https://github.com/downloads/dagwieers/asciidoc-odf/odp-backend-0.1.zip";
112 sha256 = "08ya4bskygzqkfqwjllpg31qc5k08xp2k78z9b2480g8y57bfy10";
115 in python3.pkgs.buildPythonApplication rec {
117 + lib.optionalString enableStandardFeatures "-full"
118 + lib.optionalString enableExtraPlugins "-with-plugins";
121 src = fetchFromGitHub {
122 owner = "asciidoc-py";
123 repo = "asciidoc-py";
125 hash = "sha256-TqC0x9xB6e2d6Wc9bgnlqgZVOmYHmUUKfE/CKAiEtag=";
128 nativeBuildInputs = [
134 # install filters early, so their shebangs are patched too
135 postPatch = with lib; ''
136 mkdir -p "$out/etc/asciidoc/filters"
137 mkdir -p "$out/etc/asciidoc/backends"
138 '' + optionalString _enableDitaaFilter ''
139 echo "Extracting ditaa filter"
140 unzip -d "$out/etc/asciidoc/filters/ditaa" "${ditaaFilterSrc}"
141 sed -i -e "s|java -jar|${jre}/bin/java -jar|" \
142 "$out/etc/asciidoc/filters/ditaa/ditaa2img.py"
143 '' + optionalString _enableMscgenFilter ''
144 echo "Extracting mscgen filter"
145 unzip -d "$out/etc/asciidoc/filters/mscgen" "${mscgenFilterSrc}"
146 sed -i -e "s|filter-wrapper.py mscgen|filter-wrapper.py ${mscgen}/bin/mscgen|" \
147 "$out/etc/asciidoc/filters/mscgen/mscgen-filter.conf"
148 '' + optionalString _enableDiagFilter ''
149 echo "Extracting diag filter"
150 unzip -d "$out/etc/asciidoc/filters/diag" "${diagFilterSrc}"
152 -e "s|filter='blockdiag|filter=\'${blockdiag}/bin/blockdiag|" \
153 -e "s|filter='seqdiag|filter=\'${seqdiag}/bin/seqdiag|" \
154 -e "s|filter='actdiag|filter=\'${actdiag}/bin/actdiag|" \
155 -e "s|filter='nwdiag|filter=\'${nwdiag}/bin/nwdiag|" \
156 -e "s|filter='packetdiag|filter=\'${nwdiag}/bin/packetdiag|" \
157 "$out/etc/asciidoc/filters/diag/diag-filter.conf"
158 '' + optionalString _enableQrcodeFilter ''
159 echo "Extracting qrcode filter"
160 unzip -d "$out/etc/asciidoc/filters/qrcode" "${qrcodeFilterSrc}"
161 sed -i -e "s|systemcmd('qrencode|systemcmd('${qrencode}/bin/qrencode|" \
162 "$out/etc/asciidoc/filters/qrcode/qrcode2img.py"
163 '' + optionalString _enableMatplotlibFilter ''
164 echo "Extracting mpl (matplotlib) filter"
165 mkdir -p "$out/etc/asciidoc/filters/mpl"
166 tar xvf "${matplotlibFilterSrc}" -C "$out/etc/asciidoc/filters/mpl" --strip-components=1
167 # Stop asciidoc from loading mpl/.old/chart-filter.conf
168 rm -rf "$out/etc/asciidoc/filters/mpl/.old"
169 # Add matplotlib and numpy to sys.path
170 matplotlib_path="$(toPythonPath ${matplotlib})"
171 numpy_path="$(toPythonPath ${numpy})"
172 sed -i "/^import.*sys/asys.path.append(\"$matplotlib_path\"); sys.path.append(\"$numpy_path\");" \
173 "$out/etc/asciidoc/filters/mpl/mplw.py"
174 '' + optionalString _enableAafigureFilter ''
175 echo "Extracting aafigure filter"
176 unzip -d "$out/etc/asciidoc/filters/aafigure" "${aafigureFilterSrc}"
177 # Add aafigure to sys.path (and it needs recursive-pth-loader)
178 pth_loader_path="$(toPythonPath ${recursivePthLoader})"
179 aafigure_path="$(toPythonPath ${aafigure})"
180 sed -i "/^import.*sys/asys.path.append(\"$pth_loader_path\"); sys.path.append(\"$aafigure_path\"); import sitecustomize" \
181 "$out/etc/asciidoc/filters/aafigure/aafig2img.py"
182 '' + optionalString _enableDeckjsBackend ''
183 echo "Extracting deckjs backend"
184 unzip -d "$out/etc/asciidoc/backends/deckjs" "${deckjsBackendSrc}"
185 '' + optionalString _enableOdfBackend ''
186 echo "Extracting odf backend (odt + odp)"
187 unzip -d "$out/etc/asciidoc/backends/odt" "${odtBackendSrc}"
188 unzip -d "$out/etc/asciidoc/backends/odp" "${odpBackendSrc}"
189 # The odt backend has a TODO note about removing this hardcoded path, but
190 # the odp backend already has that fix. Copy it here until fixed upstream.
191 sed -i "s|'/etc/asciidoc/backends/odt/asciidoc.ott'|os.path.dirname(__file__),'asciidoc.ott'|" \
192 "$out/etc/asciidoc/backends/odt/a2x-backend.py"
193 '' + (if enableStandardFeatures then ''
194 sed -e "s|dot|${graphviz}/bin/dot|g" \
195 -e "s|neato|${graphviz}/bin/neato|g" \
196 -e "s|twopi|${graphviz}/bin/twopi|g" \
197 -e "s|circo|${graphviz}/bin/circo|g" \
198 -e "s|fdp|${graphviz}/bin/fdp|g" \
199 -i "asciidoc/resources/filters/graphviz/graphviz2png.py"
201 sed -e "s|run('latex|run('${texlive}/bin/latex|g" \
202 -e "s|cmd = 'dvipng'|cmd = '${texlive}/bin/dvipng'|g" \
203 -e "s|cmd = 'dvisvgm'|cmd = '${texlive}/bin/dvisvgm'|g" \
204 -i "asciidoc/resources/filters/latex/latex2img.py"
206 sed -e "s|run('abc2ly|run('${lilypond}/bin/abc2ly|g" \
207 -e "s|run('lilypond|run('${lilypond}/bin/lilypond|g" \
208 -e "s|run('convert|run('${imagemagick.out}/bin/convert|g" \
209 -i "asciidoc/resources/filters/music/music2png.py"
211 sed -e 's|filter="source-highlight|filter="${sourceHighlight}/bin/source-highlight|' \
212 -e 's|filter="highlight|filter="${highlight}/bin/highlight|' \
213 -e 's|filter="pygmentize|filter="${pygments}/bin/pygmentize|' \
214 -i "asciidoc/resources/filters/source/source-highlight-filter.conf"
216 # ENV is custom environment passed to programs that a2x invokes. Here we
217 # use it to work around an impurity in the tetex package; tetex tools
218 # cannot find their neighbours (e.g. pdflatex doesn't find mktextfm).
219 # We can remove PATH= when those impurities are fixed.
220 # TODO: Is this still necessary when using texlive?
221 sed -e "s|^ENV =.*|ENV = dict(XML_CATALOG_FILES='${docbook_xml_dtd_45}/xml/dtd/docbook/catalog.xml ${docbook_xsl_ns}/xml/xsl/docbook/catalog.xml ${docbook_xsl}/xml/xsl/docbook/catalog.xml', PATH='${lib.makeBinPath [ texlive coreutils gnused ]}', **(dict(filter(lambda v: v[0] == 'SOURCE_DATE_EPOCH', os.environ.items()))))|" \
222 -e "s|^ASCIIDOC =.*|ASCIIDOC = '$out/bin/asciidoc'|" \
223 -e "s|^XSLTPROC =.*|XSLTPROC = '${libxslt.bin}/bin/xsltproc'|" \
224 -e "s|^DBLATEX =.*|DBLATEX = '${dblatexFull}/bin/dblatex'|" \
225 ${optionalString enableJava ''-e "s|^FOP =.*|FOP = '${fop}/bin/fop'|"''} \
226 -e "s|^W3M =.*|W3M = '${w3m}/bin/w3m'|" \
227 -e "s|^LYNX =.*|LYNX = '${lynx}/bin/lynx'|" \
228 -e "s|^XMLLINT =.*|XMLLINT = '${libxml2.bin}/bin/xmllint'|" \
229 -e "s|^EPUBCHECK =.*|EPUBCHECK = '${epubcheck}/bin/epubcheck'|" \
232 sed -e "s|^ENV =.*|ENV = dict(XML_CATALOG_FILES='${docbook_xml_dtd_45}/xml/dtd/docbook/catalog.xml ${docbook_xsl_ns}/xml/xsl/docbook/catalog.xml ${docbook_xsl}/xml/xsl/docbook/catalog.xml', **(dict(filter(lambda v: v[0] == 'SOURCE_DATE_EPOCH', os.environ.items()))))|" \
233 -e "s|^XSLTPROC =.*|XSLTPROC = '${libxslt.bin}/bin/xsltproc'|" \
234 -e "s|^XMLLINT =.*|XMLLINT = '${libxml2.bin}/bin/xmllint'|" \
238 for f in $(grep -R --files-with-matches "2002-11-25") ; do
239 substituteInPlace $f --replace "2002-11-25" "1980-01-02"
240 substituteInPlace $f --replace "00:37:42" "00:00:00"
242 '' + lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ''
243 # We want to use asciidoc from the build platform to build the documentation.
244 substituteInPlace Makefile.in \
245 --replace "python3 -m asciidoc.a2x" "${buildPackages.asciidoc}/bin/a2x"
253 installManPage doc/asciidoc.1 doc/a2x.1 doc/testasciidoc.1
256 checkInputs = with python3.pkgs; [
270 description = "Text-based document generation system";
272 AsciiDoc is a text document format for writing notes, documentation,
273 articles, books, ebooks, slideshows, web pages, man pages and blogs.
274 AsciiDoc files can be translated to many formats including HTML, PDF,
277 AsciiDoc is highly configurable: both the AsciiDoc source file syntax and
278 the backend output markups (which can be almost any type of SGML/XML
279 markup) can be customized and extended by the user.
281 sourceProvenance = with sourceTypes; [
283 ] ++ lib.optional _enableDitaaFilter binaryBytecode;
284 homepage = "https://asciidoc-py.github.io/";
285 changelog = "https://github.com/asciidoc-py/asciidoc-py/blob/${version}/CHANGELOG.adoc";
286 license = licenses.gpl2Plus;
287 platforms = platforms.unix;
288 maintainers = with maintainers; [ bjornfor dotlambda ];