MoinLight

Annotated moinformat/serialisers/moin/graphviz.py

301:d81233407d70
2021-10-06 Paul Boddie Introduced support for multiple identifiers when registering components, thus supporting format aliases such as "dot" for "graphviz" and "wiki" for "moin", also eliminating the superfluous wiki parser.
paul@101 1
#!/usr/bin/env python
paul@101 2
paul@101 3
"""
paul@101 4
Moin Graphviz region serialiser.
paul@101 5
paul@301 6
Copyright (C) 2018, 2021 Paul Boddie <paul@boddie.org.uk>
paul@101 7
paul@101 8
This program is free software; you can redistribute it and/or modify it under
paul@101 9
the terms of the GNU General Public License as published by the Free Software
paul@101 10
Foundation; either version 3 of the License, or (at your option) any later
paul@101 11
version.
paul@101 12
paul@101 13
This program is distributed in the hope that it will be useful, but WITHOUT
paul@101 14
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
paul@101 15
FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
paul@101 16
details.
paul@101 17
paul@101 18
You should have received a copy of the GNU General Public License along with
paul@101 19
this program.  If not, see <http://www.gnu.org/licenses/>.
paul@101 20
"""
paul@101 21
paul@101 22
from moinformat.serialisers.common import Serialiser
paul@101 23
paul@101 24
class MoinGraphvizSerialiser(Serialiser):
paul@101 25
paul@101 26
    "Serialisation of the page."
paul@101 27
paul@301 28
    input_formats = ["graphviz", "dot"]
paul@301 29
    formats = ["moin", "wiki"]
paul@301 30
paul@101 31
    def start_block(self):
paul@101 32
        pass
paul@101 33
paul@101 34
    def end_block(self):
paul@101 35
        pass
paul@101 36
paul@188 37
    def directive(self, key, value, directive):
paul@188 38
        if directive:
paul@188 39
            self.out("#%s\n" % directive)
paul@188 40
        else:
paul@188 41
            self.out("//%s%s\n" % (value and "%s=" % key or key, value or ""))
paul@101 42
paul@101 43
    def text(self, text):
paul@101 44
        self.out(text)
paul@101 45
paul@101 46
serialiser = MoinGraphvizSerialiser
paul@101 47
paul@101 48
# vim: tabstop=4 expandtab shiftwidth=4