1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/moinformat/serialisers/html/html.py Sat Jul 01 00:43:48 2023 +0200
1.3 @@ -0,0 +1,72 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +HTML serialiser.
1.8 +
1.9 +Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk>
1.10 +
1.11 +This program is free software; you can redistribute it and/or modify it under
1.12 +the terms of the GNU General Public License as published by the Free Software
1.13 +Foundation; either version 3 of the License, or (at your option) any later
1.14 +version.
1.15 +
1.16 +This program is distributed in the hope that it will be useful, but WITHOUT
1.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.19 +details.
1.20 +
1.21 +You should have received a copy of the GNU General Public License along with
1.22 +this program. If not, see <http://www.gnu.org/licenses/>.
1.23 +"""
1.24 +
1.25 +from moinformat.serialisers.common import Serialiser
1.26 +
1.27 +
1.28 +
1.29 +# The serialiser class.
1.30 +
1.31 +class HTMLSerialiser(Serialiser):
1.32 +
1.33 + "Serialisation of HTML fragments."
1.34 +
1.35 + input_formats = ["html"]
1.36 + formats = ["html"]
1.37 +
1.38 + def attribute(self, attribute):
1.39 + self.out(attribute.name)
1.40 + if attribute.value is not None:
1.41 + self.out("=")
1.42 + self.visit(attribute.value)
1.43 +
1.44 + def attribute_value(self, attribute_value):
1.45 + self.out("%s%s%s" % (attribute_value.quote, attribute_value.value, attribute_value.quote))
1.46 +
1.47 + def element(self, element):
1.48 + self.out("<%s" % element.name)
1.49 + for attribute in element.attributes:
1.50 + self.out(" ")
1.51 + self.visit(attribute)
1.52 + self.out(">")
1.53 + self.container(element)
1.54 + self.out("</%s>" % element.name)
1.55 +
1.56 + def comment(self, comment):
1.57 + self.out("<%s>" % comment.value)
1.58 +
1.59 + def directive(self, directive):
1.60 + self.out("<%s>" % directive.value)
1.61 +
1.62 + def inclusion(self, inclusion):
1.63 + self.out("<%s>" % inclusion.value)
1.64 +
1.65 + def node(self, node):
1.66 + self.out(node.value)
1.67 +
1.68 + text = node
1.69 +
1.70 + def fragment(self, fragment):
1.71 + self.container(fragment)
1.72 +
1.73 +serialiser = HTMLSerialiser
1.74 +
1.75 +# vim: tabstop=4 expandtab shiftwidth=4