paul@341 | 1 | #!/usr/bin/env python |
paul@341 | 2 | |
paul@341 | 3 | """ |
paul@341 | 4 | HTML serialiser. |
paul@341 | 5 | |
paul@341 | 6 | Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk> |
paul@341 | 7 | |
paul@341 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@341 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@341 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@341 | 11 | version. |
paul@341 | 12 | |
paul@341 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@341 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@341 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@341 | 16 | details. |
paul@341 | 17 | |
paul@341 | 18 | You should have received a copy of the GNU General Public License along with |
paul@341 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@341 | 20 | """ |
paul@341 | 21 | |
paul@341 | 22 | from moinformat.serialisers.common import Serialiser |
paul@341 | 23 | |
paul@341 | 24 | |
paul@341 | 25 | |
paul@341 | 26 | # The serialiser class. |
paul@341 | 27 | |
paul@341 | 28 | class HTMLSerialiser(Serialiser): |
paul@341 | 29 | |
paul@341 | 30 | "Serialisation of HTML fragments." |
paul@341 | 31 | |
paul@341 | 32 | input_formats = ["html"] |
paul@341 | 33 | formats = ["html"] |
paul@341 | 34 | |
paul@341 | 35 | def attribute(self, attribute): |
paul@341 | 36 | self.out(attribute.name) |
paul@341 | 37 | if attribute.value is not None: |
paul@341 | 38 | self.out("=") |
paul@341 | 39 | self.visit(attribute.value) |
paul@341 | 40 | |
paul@341 | 41 | def attribute_value(self, attribute_value): |
paul@341 | 42 | self.out("%s%s%s" % (attribute_value.quote, attribute_value.value, attribute_value.quote)) |
paul@341 | 43 | |
paul@341 | 44 | def element(self, element): |
paul@341 | 45 | self.out("<%s" % element.name) |
paul@341 | 46 | for attribute in element.attributes: |
paul@341 | 47 | self.out(" ") |
paul@341 | 48 | self.visit(attribute) |
paul@341 | 49 | self.out(">") |
paul@341 | 50 | self.container(element) |
paul@341 | 51 | self.out("</%s>" % element.name) |
paul@341 | 52 | |
paul@341 | 53 | def comment(self, comment): |
paul@341 | 54 | self.out("<%s>" % comment.value) |
paul@341 | 55 | |
paul@341 | 56 | def directive(self, directive): |
paul@341 | 57 | self.out("<%s>" % directive.value) |
paul@341 | 58 | |
paul@341 | 59 | def inclusion(self, inclusion): |
paul@341 | 60 | self.out("<%s>" % inclusion.value) |
paul@341 | 61 | |
paul@341 | 62 | def node(self, node): |
paul@341 | 63 | self.out(node.value) |
paul@341 | 64 | |
paul@341 | 65 | text = node |
paul@341 | 66 | |
paul@341 | 67 | def fragment(self, fragment): |
paul@341 | 68 | self.container(fragment) |
paul@341 | 69 | |
paul@341 | 70 | serialiser = HTMLSerialiser |
paul@341 | 71 | |
paul@341 | 72 | # vim: tabstop=4 expandtab shiftwidth=4 |