paul@38 | 1 | #!/usr/bin/env python |
paul@38 | 2 | |
paul@38 | 3 | """ |
paul@38 | 4 | Moin wiki serialisers. |
paul@38 | 5 | |
paul@331 | 6 | Copyright (C) 2017, 2018, 2023 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@40 | 22 | from moinformat.serialisers.manifest import serialisers |
paul@38 | 23 | |
paul@38 | 24 | # Top-level functions. |
paul@38 | 25 | |
paul@333 | 26 | def get_serialiser(name, doctype=None): |
paul@96 | 27 | |
paul@333 | 28 | """ |
paul@333 | 29 | Return the main serialiser class for the format having the given 'name'. |
paul@333 | 30 | If 'doctype' is indicated, obtain a serialiser class specific to that |
paul@333 | 31 | document type. Otherwise, a general Moin serialiser class is obtained. |
paul@333 | 32 | """ |
paul@96 | 33 | |
paul@333 | 34 | return serialisers["%s.%s" % (name, doctype or "moin")] |
paul@96 | 35 | |
paul@165 | 36 | def make_serialiser(metadata, format=None): |
paul@96 | 37 | |
paul@96 | 38 | """ |
paul@165 | 39 | Return a serialiser instance using the given 'metadata' and optional |
paul@165 | 40 | 'format'. |
paul@96 | 41 | """ |
paul@96 | 42 | |
paul@165 | 43 | return metadata.get_serialiser(format) |
paul@96 | 44 | |
paul@165 | 45 | def serialise(doc, serialiser): |
paul@46 | 46 | |
paul@165 | 47 | "Serialise 'doc' using the given 'serialiser' instance." |
paul@46 | 48 | |
paul@165 | 49 | serialiser.reset() |
paul@331 | 50 | doc.visit(serialiser) |
paul@100 | 51 | return serialiser.get_output() |
paul@38 | 52 | |
paul@38 | 53 | # vim: tabstop=4 expandtab shiftwidth=4 |