# HG changeset patch # User Paul Boddie # Date 1562001809 -7200 # Node ID f034ee75cc12a99d1ddcc5a26708660ab4b4cea7 # Parent aebf7d06b6cd8ddaf613cb1212d0273ac95fbb38# Parent e54e87e26a074b9810784c9ea005b97ebd29c91c Merged changes from the default branch. diff -r aebf7d06b6cd -r f034ee75cc12 docs/COPYING.txt --- a/docs/COPYING.txt Thu May 30 23:33:15 2019 +0200 +++ b/docs/COPYING.txt Mon Jul 01 19:23:29 2019 +0200 @@ -1,6 +1,9 @@ Licence Agreement ----------------- +All original work in this distribution is covered by the following copyright +and licensing information: + Copyright (C) 2017, 2018, 2019 Paul Boddie This program is free software; you can redistribute it and/or modify it under @@ -15,3 +18,31 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . + +---- + +Other code has been incorporated into this distribution and is covered by the +following copyrights: + +moinformat/resources/notugly.xsl: + +Copyright (c) 2012 Vidar Hokstad +Copyright (c) 2016, 2019 Paul Boddie + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff -r aebf7d06b6cd -r f034ee75cc12 moinformat/resources/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/moinformat/resources/__init__.py Mon Jul 01 19:23:29 2019 +0200 @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +""" +Resources. + +Copyright (C) 2019 Paul Boddie + +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 3 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, see . +""" + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r aebf7d06b6cd -r f034ee75cc12 moinformat/resources/fixlinks.xsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/moinformat/resources/fixlinks.xsl Mon Jul 01 19:23:29 2019 +0200 @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + / + + + + + + # + + + + + + + + + + + + + + + + + + + + + + diff -r aebf7d06b6cd -r f034ee75cc12 moinformat/resources/notugly.xsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/moinformat/resources/notugly.xsl Mon Jul 01 19:23:29 2019 +0200 @@ -0,0 +1,584 @@ + + + + + + + +font-size:10px; font-family:sans-serif; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fill- + + + stop-color:;stop-opacity:1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + shadow + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + black + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fill: black; stroke: none; fill-opacity:0.3 + translate(3,3) + + + + + + + fill: none; stroke: black; stroke-opacity:0.3 + translate(3,3) + + + + + + + + + + + + + + + + + + + + + + + + black + + + + + + + + + + + + + + + + + + + + + + + + + + fill: url(#); + + + fill: none; + + + stroke: ; + stroke: ; + stroke: black; + + + + + + + + fill: url(#fill-); + fill: url(#); + + + + diff -r aebf7d06b6cd -r f034ee75cc12 moinformat/serialisers/html/graphviz.py --- a/moinformat/serialisers/html/graphviz.py Thu May 30 23:33:15 2019 +0200 +++ b/moinformat/serialisers/html/graphviz.py Mon Jul 01 19:23:29 2019 +0200 @@ -97,6 +97,16 @@ format = self.directives.get("format", ["svg"])[0] transforms = self.directives.get("transform", []) + # Add transforms if appropriate. + # NOTE: Maybe move this to the Graphviz class itself. + + document_index = self.metadata.get("document_index") + + if document_index and "fixlinks" not in transforms: + transforms.insert(0, "fixlinks") + + # Determine the inline status, with only SVG being appropriate. + inline = format == "svg" # Non-inline graph output is stored for a known page only. @@ -136,7 +146,7 @@ # Configure Graphviz and invoke it. graphviz = Graphviz(filter, text) - graphviz.call(format, transforms, filename) + graphviz.call(format, transforms, filename, self.metadata) # Obtain any metadata. diff -r aebf7d06b6cd -r f034ee75cc12 moinformat/utils/graphviz.py --- a/moinformat/utils/graphviz.py Thu May 30 23:33:15 2019 +0200 +++ b/moinformat/utils/graphviz.py Mon Jul 01 19:23:29 2019 +0200 @@ -20,7 +20,8 @@ """ from moinformat.errors import ProcessingError -from os.path import exists, join +from moinformat.resources import __file__ as resources_file +from os.path import exists, join, split from StringIO import StringIO from subprocess import Popen, PIPE from xml.sax.saxutils import XMLGenerator @@ -30,7 +31,6 @@ # Configurable paths and locations. -DIAGRAM_TOOLS_PATH = "/home/paulb/Software/Graphical/diagram-tools" GRAPHVIZ_PATH = "/usr/bin" XSLT_PROCESSOR = "/usr/bin/xsltproc" @@ -48,8 +48,11 @@ # XSL transformations for SVG output. +RESOURCES_PATH = split(resources_file)[0] + TRANSFORMS = { - "notugly" : join(DIAGRAM_TOOLS_PATH, "notugly.xsl"), + "fixlinks" : (join(RESOURCES_PATH, "fixlinks.xsl"), ["document_index"]), + "notugly" : (join(RESOURCES_PATH, "notugly.xsl"), []), } @@ -133,9 +136,12 @@ else: return join(GRAPHVIZ_PATH, filter) -def transform_output(process, format, transforms): +def transform_output(process, format, transforms, params): - "Transform the output from 'process' as 'format' using 'transforms'." + """ + Transform the output from 'process' as 'format' using 'transforms' and + 'params'. + """ # No transformation can occur if the processor is missing. @@ -146,19 +152,28 @@ # preceding one, with the first accepting the initial Graphviz output. for transform in transforms: - stylesheet = TRANSFORMS.get(transform) + stylesheet, stylesheet_params = TRANSFORMS.get(transform) # Ignore unrecognised or missing stylesheets. if not stylesheet or not exists(stylesheet): continue + # Build the command parameters. + + command_params = [] + + for param in stylesheet_params: + value = params.get(param) + if value: + command_params += ["--stringparam", param, value] + # Invoke the processor, indicating standard input as the source # document. - # Example: /usr/bin/dot /usr/local/share/diagram-tools/notugly.xsl - + # Example: /usr/bin/xsltproc notugly.xsl - process = Popen( - [XSLT_PROCESSOR, stylesheet, "-"], + [XSLT_PROCESSOR] + command_params + [stylesheet, "-"], shell=False, stdin=process.stdout, stdout=PIPE, @@ -204,12 +219,14 @@ self.filter = filter self.text = text - def call(self, format, transforms=None, filename=None): + def call(self, format, transforms=None, filename=None, params=None): """ Invoke Graphviz to produce output in the given 'format'. Any 'transforms' are used to transform the output, if appropriate. Any given 'filename' is used to write to a file. + + Any 'params' are used to parameterise any transformations. """ program = get_program(self.filter) @@ -237,7 +254,7 @@ # Chain the invocation to transformations, if appropriate. if svg and transforms: - end = transform_output(start, format, transforms) + end = transform_output(start, format, transforms, params) # Send the graph to the filter.