paul@38 | 1 | #!/usr/bin/env python |
paul@38 | 2 | |
paul@38 | 3 | """ |
paul@38 | 4 | Moin wiki serialisers. |
paul@38 | 5 | |
paul@46 | 6 | Copyright (C) 2017, 2018 Paul Boddie <paul@boddie.org.uk> |
paul@38 | 7 | |
paul@38 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@38 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@38 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@38 | 11 | version. |
paul@38 | 12 | |
paul@38 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@38 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@38 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@38 | 16 | details. |
paul@38 | 17 | |
paul@38 | 18 | You should have received a copy of the GNU General Public License along with |
paul@38 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@38 | 20 | """ |
paul@38 | 21 | |
paul@96 | 22 | from moinformat.links import make_linker |
paul@40 | 23 | from moinformat.serialisers.manifest import serialisers |
paul@85 | 24 | from moinformat.serialisers.moin.moin import MoinSerialiser |
paul@38 | 25 | |
paul@38 | 26 | # Top-level functions. |
paul@38 | 27 | |
paul@96 | 28 | def get_serialiser(name): |
paul@96 | 29 | |
paul@96 | 30 | "Return the main serialiser class for the format having the given 'name'." |
paul@96 | 31 | |
paul@96 | 32 | return serialisers["%s.moin" % name] |
paul@96 | 33 | |
paul@96 | 34 | def make_serialiser(name, linker=None): |
paul@96 | 35 | |
paul@96 | 36 | """ |
paul@96 | 37 | Return a serialiser instance for the format having the given 'name'. |
paul@96 | 38 | |
paul@96 | 39 | The optional 'linker' is used to control which linking scheme is used with |
paul@96 | 40 | the serialiser, with the default having the same name as the serialiser. |
paul@96 | 41 | """ |
paul@96 | 42 | |
paul@96 | 43 | linker = linker or make_linker(name, "") |
paul@96 | 44 | return get_serialiser(name)(formats=serialisers, linker=linker) |
paul@96 | 45 | |
paul@94 | 46 | def serialise(doc, serialiser=None): |
paul@46 | 47 | |
paul@94 | 48 | """ |
paul@94 | 49 | Serialise 'doc' using the given 'serialiser' instance or the Moin serialiser |
paul@94 | 50 | if omitted. |
paul@94 | 51 | """ |
paul@46 | 52 | |
paul@38 | 53 | l = [] |
paul@94 | 54 | serialiser = serialiser or MoinSerialiser(formats=serialisers) |
paul@94 | 55 | serialiser.out = l.append |
paul@94 | 56 | doc.to_string(serialiser) |
paul@38 | 57 | return "".join(l) |
paul@38 | 58 | |
paul@38 | 59 | # vim: tabstop=4 expandtab shiftwidth=4 |