From 5832a54d1e1e7e5c6229f25c1f1b3afc12f6090d Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Thu, 28 Jan 2021 21:32:23 +0000 Subject: fix running a2x under new package structure Signed-off-by: Matthew Peveler --- asciidoc/a2x.py | 75 +++++----- .../resources/docbook-xsl/asciidoc-docbook-xsl.txt | 65 +++++++++ asciidoc/resources/docbook-xsl/chunked.xsl | 17 +++ asciidoc/resources/docbook-xsl/common.xsl | 106 ++++++++++++++ asciidoc/resources/docbook-xsl/epub.xsl | 35 +++++ asciidoc/resources/docbook-xsl/fo.xsl | 152 +++++++++++++++++++++ asciidoc/resources/docbook-xsl/htmlhelp.xsl | 28 ++++ asciidoc/resources/docbook-xsl/manpage.xsl | 31 +++++ asciidoc/resources/docbook-xsl/text.xsl | 55 ++++++++ asciidoc/resources/docbook-xsl/xhtml.xsl | 14 ++ docbook-xsl/asciidoc-docbook-xsl.txt | 65 --------- docbook-xsl/chunked.xsl | 17 --- docbook-xsl/common.xsl | 106 -------------- docbook-xsl/epub.xsl | 35 ----- docbook-xsl/fo.xsl | 152 --------------------- docbook-xsl/htmlhelp.xsl | 28 ---- docbook-xsl/manpage.xsl | 31 ----- docbook-xsl/text.xsl | 55 -------- docbook-xsl/xhtml.xsl | 14 -- 19 files changed, 543 insertions(+), 538 deletions(-) create mode 100644 asciidoc/resources/docbook-xsl/asciidoc-docbook-xsl.txt create mode 100644 asciidoc/resources/docbook-xsl/chunked.xsl create mode 100644 asciidoc/resources/docbook-xsl/common.xsl create mode 100644 asciidoc/resources/docbook-xsl/epub.xsl create mode 100644 asciidoc/resources/docbook-xsl/fo.xsl create mode 100644 asciidoc/resources/docbook-xsl/htmlhelp.xsl create mode 100644 asciidoc/resources/docbook-xsl/manpage.xsl create mode 100644 asciidoc/resources/docbook-xsl/text.xsl create mode 100644 asciidoc/resources/docbook-xsl/xhtml.xsl delete mode 100644 docbook-xsl/asciidoc-docbook-xsl.txt delete mode 100644 docbook-xsl/chunked.xsl delete mode 100644 docbook-xsl/common.xsl delete mode 100644 docbook-xsl/epub.xsl delete mode 100644 docbook-xsl/fo.xsl delete mode 100644 docbook-xsl/htmlhelp.xsl delete mode 100644 docbook-xsl/manpage.xsl delete mode 100644 docbook-xsl/text.xsl delete mode 100644 docbook-xsl/xhtml.xsl diff --git a/asciidoc/a2x.py b/asciidoc/a2x.py index 8c58af3..32ee88e 100644 --- a/asciidoc/a2x.py +++ b/asciidoc/a2x.py @@ -28,6 +28,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ +import io import os import fnmatch from html.parser import HTMLParser @@ -40,6 +41,7 @@ from urllib.parse import urlparse import zipfile import xml.dom.minidom import mimetypes +from . import asciidoc CONF_DIR = os.path.join(os.path.dirname(__file__), 'resources') METADATA = {} @@ -69,7 +71,7 @@ LYNX = 'lynx' # alternate text file generator. XMLLINT = 'xmllint' # Set to '' to disable. EPUBCHECK = 'epubcheck' # Set to '' to disable. # External executable default options. -ASCIIDOC_OPTS = '' +ASCIIDOC_OPTS = [] BACKEND_OPTS = '' DBLATEX_OPTS = '' FOP_OPTS = '' @@ -418,7 +420,7 @@ class A2X(AttrDict): ''' self.process_options() # Append configuration file options. - self.asciidoc_opts += ' ' + ASCIIDOC_OPTS + self.asciidoc_opts += ASCIIDOC_OPTS self.dblatex_opts += ' ' + DBLATEX_OPTS self.fop_opts += ' ' + FOP_OPTS self.xsltproc_opts += ' ' + XSLTPROC_OPTS @@ -444,27 +446,22 @@ class A2X(AttrDict): conf_files.append(os.path.join(a2xdir, CONF_FILE)) # If the asciidoc executable and conf files are in the a2x directory # then use the local copy of asciidoc and skip the global a2x conf. - asciidoc = os.path.join(a2xdir, 'asciidoc.py') asciidoc_conf = os.path.join(a2xdir, 'asciidoc.conf') - if os.path.isfile(asciidoc) and os.path.isfile(asciidoc_conf): - self.asciidoc = asciidoc - else: - self.asciidoc = None - # From global conf directory. - conf_files.append(os.path.join(CONF_DIR, CONF_FILE)) + + # TODO: CONF_DIR work + # From global conf directory. + # conf_files.append(os.path.join(CONF_DIR, CONF_FILE)) + # From $HOME directory. home_dir = os.environ.get('HOME') if home_dir is not None: conf_files.append(os.path.join(home_dir, '.asciidoc', CONF_FILE)) - # If asciidoc is not local to a2x then search the PATH. - if not self.asciidoc: - self.asciidoc = find_executable(ASCIIDOC) - if not self.asciidoc: - die('unable to find asciidoc: %s' % ASCIIDOC) + # From backend plugin directory. if self.backend is not None: - stdout = shell(self.asciidoc + ' --backend list')[0] - backends = [(i, os.path.split(i)[1]) for i in stdout.splitlines()] + outfile = io.StringIO() + asciidoc.execute('asciidoc', [('--backend', 'list'), ('--out-file', outfile)], []) + backends = [(i, os.path.split(i)[1]) for i in outfile.getvalue().splitlines()] backend_dir = [i[0] for i in backends if i[1] == self.backend] if len(backend_dir) == 0: die('missing %s backend' % self.backend) @@ -531,22 +528,21 @@ class A2X(AttrDict): mimetypes.add_type(mimetype, ext) else: self.resource_files.append(r) - for p in (os.path.dirname(self.asciidoc), CONF_DIR): - for d in ('images', 'stylesheets'): - d = os.path.join(p, d) - if os.path.isdir(d): - self.resource_dirs.append(d) + for d in ('images', 'stylesheets'): + d = os.path.join(CONF_DIR, d) + if os.path.isdir(d): + self.resource_dirs.append(d) verbose('resource files: %s' % self.resource_files) verbose('resource directories: %s' % self.resource_dirs) if not self.doctype and self.format == 'manpage': self.doctype = 'manpage' if self.doctype: - self.asciidoc_opts += ' --doctype %s' % self.doctype + self.asciidoc_opts.append(('--doctype', self.doctype)) for attr in self.attributes: - self.asciidoc_opts += ' --attribute "%s"' % attr + self.asciidoc_opts.append(('--attribute', attr)) # self.xsltproc_opts += ' --nonet' if self.verbose: - self.asciidoc_opts += ' --verbose' + self.asciidoc_opts.append((' --verbose')) self.dblatex_opts += ' -V' if self.icons or self.icons_dir: params = [ @@ -599,17 +595,16 @@ class A2X(AttrDict): ''' return os.path.basename(os.path.splitext(self.asciidoc_file)[0]) + ext - def asciidoc_conf_file(self, path): + @staticmethod + def asciidoc_conf_file(path): ''' Return full path name of file in asciidoc configuration files directory. Search first the directory containing the asciidoc executable then the global configuration file directory. ''' - f = os.path.join(os.path.dirname(self.asciidoc), path) + f = os.path.join(CONF_DIR, path) if not os.path.isfile(f): - f = os.path.join(CONF_DIR, path) - if not os.path.isfile(f): - die('missing configuration file: %s' % f) + die('missing configuration file: %s' % f) return os.path.normpath(f) def xsl_stylesheet(self, file_name=None): @@ -697,8 +692,12 @@ class A2X(AttrDict): if not os.path.isfile(docbook_file): die('missing docbook file: %s' % docbook_file) return - shell('"%s" --backend docbook -a "a2x-format=%s" %s --out-file "%s" "%s"' % - (self.asciidoc, self.format, self.asciidoc_opts, docbook_file, self.asciidoc_file)) + options = self.asciidoc_opts[:] + options.append(('--backend', 'docbook')) + options.append(('-a', 'a2x-format=%s' % self.format)) + options.append(('--out-file', docbook_file)) + asciidoc.reset_asciidoc() + asciidoc.execute('asciidoc', options, [self.asciidoc_file]) if not self.no_xmllint and XMLLINT: shell('"%s" --nonet --noout --valid "%s"' % (XMLLINT, docbook_file)) @@ -869,9 +868,13 @@ class A2X(AttrDict): text_file = self.dst_path('.text') html_file = self.dst_path('.text.html') if self.lynx: - shell('"%s" %s --conf-file "%s" -b html4 -a "a2x-format=%s" -o "%s" "%s"' % - (self.asciidoc, self.asciidoc_opts, self.asciidoc_conf_file('text.conf'), - self.format, html_file, self.asciidoc_file)) + options = self.asciidoc_opts[:] + options.append(('--conf-file', self.asciidoc_conf_file('text.conf'))) + options.append(('-b', 'html4')) + options.append(('-a', 'a2x-format=%s' % self.format)) + options.append(('-o', html_file)) + asciidoc.reset_asciidoc() + asciidoc.execute('asciidoc', options, [self.asciidoc_file]) cmd = '"%s" %s "%s" > "%s"' % (LYNX, LYNX_OPTS, html_file, text_file) shell(cmd) else: @@ -888,6 +891,8 @@ class A2X(AttrDict): def cli(): + global OPTIONS + description = '''A toolchain manager for AsciiDoc (converts Asciidoc text files to other file formats)''' from optparse import OptionParser parser = OptionParser(usage='usage: %prog [OPTIONS] SOURCE_FILE', @@ -995,7 +1000,7 @@ def cli(): opts, args = parser.parse_args(argv) if len(args) != 1: parser.error('incorrect number of arguments') - opts.asciidoc_opts = ' '.join(opts.asciidoc_opts) + opts.asciidoc_opts = [x.split(' ', 1) for x in opts.asciidoc_opts] opts.dblatex_opts = ' '.join(opts.dblatex_opts) opts.fop_opts = ' '.join(opts.fop_opts) opts.xsltproc_opts = ' '.join(opts.xsltproc_opts) diff --git a/asciidoc/resources/docbook-xsl/asciidoc-docbook-xsl.txt b/asciidoc/resources/docbook-xsl/asciidoc-docbook-xsl.txt new file mode 100644 index 0000000..295a7d4 --- /dev/null +++ b/asciidoc/resources/docbook-xsl/asciidoc-docbook-xsl.txt @@ -0,0 +1,65 @@ +AsciiDoc DocBook XSL Stylesheets Notes +====================================== + +Output file customisation is achieved by tweaking the DocBook XSL +stylesheets. I've tried to keep customization to a minimum and +confine it to the separate XSL driver files in the distribution +`./docbook-xsl/` directory (see the User Guide for details). + +To polish some rough edges I've written some patches for the DocBook +XSL stylesheets -- you don't need them but they're documented below +and included in the distribution `./docbook-xsl/` directory. + + +Manually upgrading Debian to the latest DocBook XSL stylesheets +--------------------------------------------------------------- +The DocBook XSL Stylesheets distribution is just a directory full of +text files and you can switch between releases by changing the +directory name in the system XML catalog. + +To upgrade to the latest docbook-xsl stylesheets without having to +wait for the Debian `docbook-xsl` package: + +- Download the latest docbook-xsl tarball from + https://github.com/docbook/xslt10-stylesheets. Bleeding edge snapshots + can be found at https://github.com/docbook/xslt10-stylesheets/releases. + +- Unzip the tarball to `/usr/share/xml/docbook/stylesheet/`: + + $ cd /usr/share/xml/docbook/stylesheet + $ sudo tar -xzf /tmp/docbook-xsl-1.72.0.tar.gz + +- Edit `/etc/xml/docbook-xsl.xml` catalog and replace occurrences of + the current stylesheets directory with the new one (in our example + it would be `/usr/share/xml/docbook/stylesheet/docbook-xsl-1.72.0`. + + $ cd /etc/xml/ + $ sudo cp -p docbook-xsl.xml docbook-xsl.xml.ORIG + $ sudo vi docbook-xsl.xml + + +Customizing Generated Text +-------------------------- +An example +http://www.sagehill.net/docbookxsl/CustomGentext.html#CustomGenText[DocBook +XSL Stylesheets customization file] for formatting chapter titles +without chapter numbering. + +.custom-chapter.xml +--------------------------------------------------------------------- + + + + + + + + +--------------------------------------------------------------------- + +Executed with this 'xsltproc' parameter: + + --param local.l10n.xml document\(\'custom-chapter.xml\'\) + +NOTE: This example is hypothetical -- use the 'xsltproc' +`--stringparam chapter.autolabel 0` option to do the same job. diff --git a/asciidoc/resources/docbook-xsl/chunked.xsl b/asciidoc/resources/docbook-xsl/chunked.xsl new file mode 100644 index 0000000..aafcca0 --- /dev/null +++ b/asciidoc/resources/docbook-xsl/chunked.xsl @@ -0,0 +1,17 @@ + + + + +images/icons/ +images/icons/ + + diff --git a/asciidoc/resources/docbook-xsl/common.xsl b/asciidoc/resources/docbook-xsl/common.xsl new file mode 100644 index 0000000..6a475a1 --- /dev/null +++ b/asciidoc/resources/docbook-xsl/common.xsl @@ -0,0 +1,106 @@ + + + + + + + + + + 1 + 0 + + + + + + +images/icons/ +0 + + + + 0 + #E0E0E0 + + + +images/icons/ + + + margin-left: 0; margin-right: 10%; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +article toc,title +book toc,title,figure,table,example,equation + + +chapter toc,title +part toc,title +preface toc,title +qandadiv toc +qandaset toc +reference toc,title +sect1 toc +sect2 toc +sect3 toc +sect4 toc +sect5 toc +section toc +set toc,title + + + +article nop +book nop + + + + + diff --git a/asciidoc/resources/docbook-xsl/epub.xsl b/asciidoc/resources/docbook-xsl/epub.xsl new file mode 100644 index 0000000..b15748d --- /dev/null +++ b/asciidoc/resources/docbook-xsl/epub.xsl @@ -0,0 +1,35 @@ + + + + + + + + + + + + +/article nop + + +/book nop + + + + + diff --git a/asciidoc/resources/docbook-xsl/fo.xsl b/asciidoc/resources/docbook-xsl/fo.xsl new file mode 100644 index 0000000..5537e8e --- /dev/null +++ b/asciidoc/resources/docbook-xsl/fo.xsl @@ -0,0 +1,152 @@ + + + + + + + + + + +false + +left + + +12 + + pt + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0pt + 0pt + 1pc + + + + + -1pc + 0pt + 0pt + + + + + + 0.75in + 0.75in + + + + + 0.5in + 0.5in + + + + + + + + + + + + + + + + + + 10pt + + + + 14pt + bold + false + always + + + + solid + 1pt + silver + #ffffee + 12pt + 12pt + 6pt + 6pt + 0pt + 12pt + 6pt + 6pt + + + + + + + + + + #E0E0E0 + inherit + + + + + + + auto + + + diff --git a/asciidoc/resources/docbook-xsl/htmlhelp.xsl b/asciidoc/resources/docbook-xsl/htmlhelp.xsl new file mode 100644 index 0000000..ef38fa4 --- /dev/null +++ b/asciidoc/resources/docbook-xsl/htmlhelp.xsl @@ -0,0 +1,28 @@ + + + + + + + + + + +
+
+ + + +
+
+ +
diff --git a/asciidoc/resources/docbook-xsl/manpage.xsl b/asciidoc/resources/docbook-xsl/manpage.xsl new file mode 100644 index 0000000..b5201a5 --- /dev/null +++ b/asciidoc/resources/docbook-xsl/manpage.xsl @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/asciidoc/resources/docbook-xsl/text.xsl b/asciidoc/resources/docbook-xsl/text.xsl new file mode 100644 index 0000000..566884c --- /dev/null +++ b/asciidoc/resources/docbook-xsl/text.xsl @@ -0,0 +1,55 @@ + + + + + + + + + + + + appendix title + article/appendix nop + article toc,title + book toc,title,figure,table,example,equation + chapter title + part toc,title + preface toc,title + qandadiv toc + qandaset toc + reference toc,title + section toc + set toc,title + + + +
+ +
+
+ + +

+ +
+
+ + +
+ +
+
+ + +
diff --git a/asciidoc/resources/docbook-xsl/xhtml.xsl b/asciidoc/resources/docbook-xsl/xhtml.xsl new file mode 100644 index 0000000..cdfe27f --- /dev/null +++ b/asciidoc/resources/docbook-xsl/xhtml.xsl @@ -0,0 +1,14 @@ + + + + + diff --git a/docbook-xsl/asciidoc-docbook-xsl.txt b/docbook-xsl/asciidoc-docbook-xsl.txt deleted file mode 100644 index 295a7d4..0000000 --- a/docbook-xsl/asciidoc-docbook-xsl.txt +++ /dev/null @@ -1,65 +0,0 @@ -AsciiDoc DocBook XSL Stylesheets Notes -====================================== - -Output file customisation is achieved by tweaking the DocBook XSL -stylesheets. I've tried to keep customization to a minimum and -confine it to the separate XSL driver files in the distribution -`./docbook-xsl/` directory (see the User Guide for details). - -To polish some rough edges I've written some patches for the DocBook -XSL stylesheets -- you don't need them but they're documented below -and included in the distribution `./docbook-xsl/` directory. - - -Manually upgrading Debian to the latest DocBook XSL stylesheets ---------------------------------------------------------------- -The DocBook XSL Stylesheets distribution is just a directory full of -text files and you can switch between releases by changing the -directory name in the system XML catalog. - -To upgrade to the latest docbook-xsl stylesheets without having to -wait for the Debian `docbook-xsl` package: - -- Download the latest docbook-xsl tarball from - https://github.com/docbook/xslt10-stylesheets. Bleeding edge snapshots - can be found at https://github.com/docbook/xslt10-stylesheets/releases. - -- Unzip the tarball to `/usr/share/xml/docbook/stylesheet/`: - - $ cd /usr/share/xml/docbook/stylesheet - $ sudo tar -xzf /tmp/docbook-xsl-1.72.0.tar.gz - -- Edit `/etc/xml/docbook-xsl.xml` catalog and replace occurrences of - the current stylesheets directory with the new one (in our example - it would be `/usr/share/xml/docbook/stylesheet/docbook-xsl-1.72.0`. - - $ cd /etc/xml/ - $ sudo cp -p docbook-xsl.xml docbook-xsl.xml.ORIG - $ sudo vi docbook-xsl.xml - - -Customizing Generated Text --------------------------- -An example -http://www.sagehill.net/docbookxsl/CustomGentext.html#CustomGenText[DocBook -XSL Stylesheets customization file] for formatting chapter titles -without chapter numbering. - -.custom-chapter.xml ---------------------------------------------------------------------- - - - - - - - - ---------------------------------------------------------------------- - -Executed with this 'xsltproc' parameter: - - --param local.l10n.xml document\(\'custom-chapter.xml\'\) - -NOTE: This example is hypothetical -- use the 'xsltproc' -`--stringparam chapter.autolabel 0` option to do the same job. diff --git a/docbook-xsl/chunked.xsl b/docbook-xsl/chunked.xsl deleted file mode 100644 index aafcca0..0000000 --- a/docbook-xsl/chunked.xsl +++ /dev/null @@ -1,17 +0,0 @@ - - - - -images/icons/ -images/icons/ - - diff --git a/docbook-xsl/common.xsl b/docbook-xsl/common.xsl deleted file mode 100644 index 6a475a1..0000000 --- a/docbook-xsl/common.xsl +++ /dev/null @@ -1,106 +0,0 @@ - - - - - - - - - - 1 - 0 - - - - - - -images/icons/ -0 - - - - 0 - #E0E0E0 - - - -images/icons/ - - - margin-left: 0; margin-right: 10%; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -article toc,title -book toc,title,figure,table,example,equation - - -chapter toc,title -part toc,title -preface toc,title -qandadiv toc -qandaset toc -reference toc,title -sect1 toc -sect2 toc -sect3 toc -sect4 toc -sect5 toc -section toc -set toc,title - - - -article nop -book nop - - - - - diff --git a/docbook-xsl/epub.xsl b/docbook-xsl/epub.xsl deleted file mode 100644 index b15748d..0000000 --- a/docbook-xsl/epub.xsl +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - -/article nop - - -/book nop - - - - - diff --git a/docbook-xsl/fo.xsl b/docbook-xsl/fo.xsl deleted file mode 100644 index 5537e8e..0000000 --- a/docbook-xsl/fo.xsl +++ /dev/null @@ -1,152 +0,0 @@ - - - - - - - - - - -false - -left - - -12 - - pt - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0pt - 0pt - 1pc - - - - - -1pc - 0pt - 0pt - - - - - - 0.75in - 0.75in - - - - - 0.5in - 0.5in - - - - - - - - - - - - - - - - - - 10pt - - - - 14pt - bold - false - always - - - - solid - 1pt - silver - #ffffee - 12pt - 12pt - 6pt - 6pt - 0pt - 12pt - 6pt - 6pt - - - - - - - - - - #E0E0E0 - inherit - - - - - - - auto - - - diff --git a/docbook-xsl/htmlhelp.xsl b/docbook-xsl/htmlhelp.xsl deleted file mode 100644 index ef38fa4..0000000 --- a/docbook-xsl/htmlhelp.xsl +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - -
-
- - - -
-
- -
diff --git a/docbook-xsl/manpage.xsl b/docbook-xsl/manpage.xsl deleted file mode 100644 index b5201a5..0000000 --- a/docbook-xsl/manpage.xsl +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/docbook-xsl/text.xsl b/docbook-xsl/text.xsl deleted file mode 100644 index 566884c..0000000 --- a/docbook-xsl/text.xsl +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - - - appendix title - article/appendix nop - article toc,title - book toc,title,figure,table,example,equation - chapter title - part toc,title - preface toc,title - qandadiv toc - qandaset toc - reference toc,title - section toc - set toc,title - - - -
- -
-
- - -

- -
-
- - -
- -
-
- - -
diff --git a/docbook-xsl/xhtml.xsl b/docbook-xsl/xhtml.xsl deleted file mode 100644 index cdfe27f..0000000 --- a/docbook-xsl/xhtml.xsl +++ /dev/null @@ -1,14 +0,0 @@ - - - - - -- cgit v1.2.1