paul@40 | 1 | #!/usr/bin/env python |
paul@40 | 2 | |
paul@40 | 3 | """ |
paul@40 | 4 | Moin wiki parsers. |
paul@40 | 5 | |
paul@88 | 6 | Copyright (C) 2017, 2018 Paul Boddie <paul@boddie.org.uk> |
paul@40 | 7 | |
paul@40 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@40 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@40 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@40 | 11 | version. |
paul@40 | 12 | |
paul@40 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@40 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@40 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@40 | 16 | details. |
paul@40 | 17 | |
paul@40 | 18 | You should have received a copy of the GNU General Public License along with |
paul@40 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@40 | 20 | """ |
paul@40 | 21 | |
paul@40 | 22 | from moinformat.parsers.manifest import parsers |
paul@88 | 23 | from moinformat.parsers.moin import MoinParser |
paul@40 | 24 | |
paul@42 | 25 | # Top-level functions. |
paul@42 | 26 | |
paul@96 | 27 | def get_parser(name="moin"): |
paul@96 | 28 | |
paul@96 | 29 | "Return the parser class supporting the format with the given 'name'." |
paul@96 | 30 | |
paul@96 | 31 | return parsers[name] |
paul@96 | 32 | |
paul@165 | 33 | def make_parser(metadata, name="moin"): |
paul@96 | 34 | |
paul@165 | 35 | "Return a parser instance using the given 'metadata' and optional 'name'." |
paul@96 | 36 | |
paul@165 | 37 | return metadata.get_parser(name) |
paul@96 | 38 | |
paul@88 | 39 | def parse(s, parser=None): |
paul@88 | 40 | |
paul@88 | 41 | "Parse 's' with 'parser' or the Moin format parser if omitted." |
paul@88 | 42 | |
paul@165 | 43 | parser = parser or MoinParser() |
paul@88 | 44 | return parser.parse(s) |
paul@42 | 45 | |
paul@40 | 46 | # vim: tabstop=4 expandtab shiftwidth=4 |