From 822fd6056e18fce07ead73bd190c59df5e929e6d Mon Sep 17 00:00:00 2001 From: Stefan Sauer Date: Tue, 27 Feb 2018 07:47:13 +0100 Subject: [PATCH] mkhtml2: move db2html to the gtkdoc package Add tooling infrastructure for gtkdoc-mkhtml2 (previously db2html). This lets use reuse code from the other modeuls without hacks. --- Makefile.am | 5 +++++ configure.ac | 1 + gtkdoc-mkhtml2.in | 41 +++++++++++++++++++++++++++++++++++ tools/db2html.py => gtkdoc/mkhtml2.py | 30 ++++++++----------------- 4 files changed, 56 insertions(+), 21 deletions(-) create mode 100644 gtkdoc-mkhtml2.in rename tools/db2html.py => gtkdoc/mkhtml2.py (97%) diff --git a/Makefile.am b/Makefile.am index 4d69bf1..e23ed41 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,6 +9,7 @@ bin_SCRIPTS = \ gtkdoc-fixxref \ gtkdoc-mkdb \ gtkdoc-mkhtml \ + gtkdoc-mkhtml2 \ gtkdoc-mkman \ gtkdoc-mkpdf \ gtkdoc-rebase \ @@ -43,6 +44,7 @@ pylibdata_DATA = \ gtkdoc/md_to_db.py \ gtkdoc/mkdb.py \ gtkdoc/mkhtml.py \ + gtkdoc/mkhtml2.py \ gtkdoc/mkman.py \ gtkdoc/mkpdf.py \ gtkdoc/rebase.py \ @@ -85,6 +87,7 @@ CLEANFILES = \ gtkdoc-fixxrefc \ gtkdoc-mkdbc \ gtkdoc-mkhtmlc \ + gtkdoc-mkhtml2c \ gtkdoc-mkmanc \ gtkdoc-mkpdfc \ gtkdoc-rebasec \ @@ -97,6 +100,7 @@ CLEANFILES = \ gtkdoc/md_to_db.pyc \ gtkdoc/mkdb.pyc \ gtkdoc/mkhtml.pyc \ + gtkdoc/mkhtml2.pyc \ gtkdoc/mkman.pyc \ gtkdoc/mkpdf.pyc \ gtkdoc/rebase.pyc \ @@ -110,6 +114,7 @@ DISTCLEANFILES = \ gtkdocize \ gtkdoc-mkdb \ gtkdoc-mkhtml \ + gtkdoc-mkhtml2 \ gtkdoc-mkman \ gtkdoc-mkpdf \ gtk-doc.pc \ diff --git a/configure.ac b/configure.ac index a579a35..319dfb1 100644 --- a/configure.ac +++ b/configure.ac @@ -248,6 +248,7 @@ AC_CONFIG_FILES([gtkdoc-depscan], [chmod +x gtkdoc-depscan]) AC_CONFIG_FILES([gtkdoc-fixxref], [chmod +x gtkdoc-fixxref]) AC_CONFIG_FILES([gtkdoc-mkdb], [chmod +x gtkdoc-mkdb]) AC_CONFIG_FILES([gtkdoc-mkhtml], [chmod +x gtkdoc-mkhtml]) +AC_CONFIG_FILES([gtkdoc-mkhtml2], [chmod +x gtkdoc-mkhtml2]) AC_CONFIG_FILES([gtkdoc-mkman], [chmod +x gtkdoc-mkman]) AC_CONFIG_FILES([gtkdoc-mkpdf], [chmod +x gtkdoc-mkpdf]) AC_CONFIG_FILES([gtkdoc-rebase], [chmod +x gtkdoc-rebase]) diff --git a/gtkdoc-mkhtml2.in b/gtkdoc-mkhtml2.in new file mode 100644 index 0000000..b532a30 --- /dev/null +++ b/gtkdoc-mkhtml2.in @@ -0,0 +1,41 @@ +#!@PYTHON@ +# -*- python; coding: utf-8 -*- +# +# gtk-doc - GTK DocBook documentation generator. +# Copyright (C) 2018 Stefan Sauer +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +import argparse +import sys +sys.path.append('@PYTHON_PACKAGE_DIR@') + +from gtkdoc import common, config, mkhtml2 + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description='gtkdoc-mkhtml version %s - generate documentation in html format' % config.version) + parser.add_argument('--version', action='version', version=config.version) + parser.add_argument('args', nargs='*', + help='DRIVER_FILE') + + options = parser.parse_args() + if len(options.args) != 1: + sys.exit('Too few arguments') + + common.setup_logging() + + sys.exit(mkhtml2.run(options)) diff --git a/tools/db2html.py b/gtkdoc/mkhtml2.py similarity index 97% rename from tools/db2html.py rename to gtkdoc/mkhtml2.py index 639ed46..bd96694 100644 --- a/tools/db2html.py +++ b/gtkdoc/mkhtml2.py @@ -2,7 +2,7 @@ # -*- python; coding: utf-8 -*- # # gtk-doc - GTK DocBook documentation generator. -# Copyright (C) 2017 Stefan Sauer +# Copyright (C) 2018 Stefan Sauer # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,8 +21,9 @@ """Prototype for builtin docbook processing -The tool loades the main xml document (-docs.xml) and chunks it +The tool loads the main xml document (-docs.xml) and chunks it like the xsl-stylesheets would do. For that it resolves all the xml-includes. +Each chunk is converted to htnml using python functions. In contrast to our previous approach of running gtkdoc-mkhtml + gtkdoc-fixxref, this tools will replace both without relying on external tools such as xsltproc @@ -30,7 +31,6 @@ and source-highlight. TODO: convert the docbook-xml to html - more chunk converters -- refentry/index nav headers - check each docbook tag if it can contain #PCDATA, if not don't check for xml.text - integrate syntax-highlighing from fixxref @@ -46,10 +46,10 @@ Requirements: sudo pip3 install anytree lxml Examples: -python3 tools/db2html.py tests/gobject/docs/tester-docs.xml +./gtkdoc-mkhtml2 tests/gobject/docs/tester-docs.xml ll tests/gobject/docs/db2html -python3 tools/db2html.py tests/bugs/docs/tester-docs.xml +./gtkdoc-mkhtml2 tests/bugs/docs/tester-docs.xml ll tests/bugs/docs/db2html cp tests/bugs/docs/html/*.{css,png} tests/bugs/docs/db2html/ xdg-open tests/bugs/docs/db2html/index.html @@ -68,11 +68,7 @@ import sys from anytree import Node, PreOrderIter from lxml import etree -# TODO(ensonic): requires gtk-doc to be installed, rewrite later -sys.path.append('/usr/share/gtk-doc/python') -from gtkdoc.fixxref import NoLinks -from gtkdoc import common - +from .fixxref import NoLinks # http://www.sagehill.net/docbookxsl/Chunking.html CHUNK_TAGS = [ @@ -887,14 +883,6 @@ def main(index_file): # - keywords under 'functions' from all refsect2 and refsect3 -if __name__ == '__main__': - parser = argparse.ArgumentParser( - description='db2html - chunk docbook') - parser.add_argument('sources', nargs='*') - options = parser.parse_args() - if len(options.sources) != 1: - sys.exit('Expect one source file argument.') - - common.setup_logging() - - sys.exit(main(options.sources[0])) +def run(options): + document = options.args[0] + sys.exit(main(document)) -- 2.11.4.GIT