1.1 --- a/moinformat/serialisers/moin.py Tue Jul 24 12:58:58 2018 +0200
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,201 +0,0 @@
1.4 -#!/usr/bin/env python
1.5 -
1.6 -"""
1.7 -Moin wiki text serialiser.
1.8 -
1.9 -Copyright (C) 2017, 2018 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 escape_attr, escape_text, Serialiser
1.26 -
1.27 -class MoinSerialiser(Serialiser):
1.28 -
1.29 - "Serialisation of the page."
1.30 -
1.31 - def start_region(self, level, indent, type, extra):
1.32 - out = self.out
1.33 - if level:
1.34 - out(" " * indent + "{" * level)
1.35 -
1.36 - # Produce a header for regions within a top-level region.
1.37 -
1.38 - if type and type != "inline" and level:
1.39 - out("#!%s\n" % type)
1.40 -
1.41 - def end_region(self, level, indent, type, extra):
1.42 - out = self.out
1.43 - if level:
1.44 - out("%s%s" % ("}" * level, extra or ""))
1.45 -
1.46 - def start_block(self):
1.47 - pass
1.48 -
1.49 - def end_block(self):
1.50 - pass
1.51 -
1.52 - def start_defitem(self, pad, extra):
1.53 - self.out((extra and "\n" + extra + "::" or "") + pad)
1.54 -
1.55 - def end_defitem(self, pad, extra):
1.56 - pass
1.57 -
1.58 - def start_defterm(self, pad):
1.59 - self.out(pad)
1.60 -
1.61 - def end_defterm(self, pad):
1.62 - self.out("::")
1.63 -
1.64 - def start_emphasis(self):
1.65 - self.out("''")
1.66 -
1.67 - def end_emphasis(self):
1.68 - self.out("''")
1.69 -
1.70 - def start_heading(self, level, extra, pad):
1.71 - self.out(extra + "=" * level + pad)
1.72 -
1.73 - def end_heading(self, level, pad, extra):
1.74 - self.out(pad + "=" * level + extra)
1.75 -
1.76 - def start_larger(self):
1.77 - self.out("~+")
1.78 -
1.79 - def end_larger(self):
1.80 - self.out("+~")
1.81 -
1.82 - def start_link(self, target):
1.83 - self.out("[[%s" % target)
1.84 -
1.85 - def end_link(self):
1.86 - self.out("]]")
1.87 -
1.88 - def start_linktext(self):
1.89 - self.out("|")
1.90 -
1.91 - def end_linktext(self):
1.92 - pass
1.93 -
1.94 - def start_list(self, indent, marker, num):
1.95 - pass
1.96 -
1.97 - def end_list(self, indent, marker, num):
1.98 - pass
1.99 -
1.100 - def start_listitem(self, indent, marker, space, num):
1.101 - self.out("%s%s%s%s" % (indent * " ", marker, num and "#%s" % num or "", space))
1.102 -
1.103 - def end_listitem(self, indent, marker, space, num):
1.104 - pass
1.105 -
1.106 - def start_monospace(self):
1.107 - self.out("`")
1.108 -
1.109 - def end_monospace(self):
1.110 - self.out("`")
1.111 -
1.112 - def start_smaller(self):
1.113 - self.out("~-")
1.114 -
1.115 - def end_smaller(self):
1.116 - self.out("-~")
1.117 -
1.118 - def start_strong(self):
1.119 - self.out("'''")
1.120 -
1.121 - def end_strong(self):
1.122 - self.out("'''")
1.123 -
1.124 - def start_strikethrough(self):
1.125 - self.out("--(")
1.126 -
1.127 - def end_strikethrough(self):
1.128 - self.out(")--")
1.129 -
1.130 - def start_subscript(self):
1.131 - self.out(",,")
1.132 -
1.133 - def end_subscript(self):
1.134 - self.out(",,")
1.135 -
1.136 - def start_superscript(self):
1.137 - self.out("^")
1.138 -
1.139 - def end_superscript(self):
1.140 - self.out("^")
1.141 -
1.142 - def start_table(self):
1.143 - pass
1.144 -
1.145 - def end_table(self):
1.146 - pass
1.147 -
1.148 - def start_table_attrs(self):
1.149 - self.out("<")
1.150 -
1.151 - def end_table_attrs(self):
1.152 - self.out(">")
1.153 -
1.154 - def start_table_cell(self, attrs):
1.155 - self.out("||")
1.156 - if attrs and not attrs.empty():
1.157 - attrs.to_string(self)
1.158 -
1.159 - def end_table_cell(self):
1.160 - pass
1.161 -
1.162 - def start_table_row(self):
1.163 - pass
1.164 -
1.165 - def end_table_row(self, trailing):
1.166 - self.out("||")
1.167 - self.out(trailing)
1.168 -
1.169 - def start_underline(self):
1.170 - self.out("__")
1.171 -
1.172 - def end_underline(self):
1.173 - self.out("__")
1.174 -
1.175 - def break_(self):
1.176 - self.out("\n")
1.177 -
1.178 - def continuation(self, text):
1.179 - self.out(text)
1.180 -
1.181 - def macro(self, name, args):
1.182 - self.out("<<%s%s>>" % (name, args and "(%s)" % ",".join(args) or ""))
1.183 -
1.184 - def rule(self, length):
1.185 - self.out("-" * length)
1.186 -
1.187 - def table_attr(self, name, value, concise, quote):
1.188 - if concise:
1.189 - if name == "colour": self.out(value)
1.190 - elif name == "colspan": self.out("-%s" % value)
1.191 - elif name == "halign" : self.out(value == "left" and "(" or value == "right" and ")" or ":")
1.192 - elif name == "rowspan": self.out("|%s" % value)
1.193 - elif name == "valign" : self.out(value == "top" and "^" or "v")
1.194 - elif name == "width" : self.out(value)
1.195 - else:
1.196 - self.out("%s%s" % (escape_text(name), value is not None and
1.197 - "=%s%s%s" % (quote or '"', escape_attr(value), quote or '"') or ""))
1.198 -
1.199 - def text(self, s):
1.200 - self.out(s)
1.201 -
1.202 -serialiser = MoinSerialiser
1.203 -
1.204 -# vim: tabstop=4 expandtab shiftwidth=4