paul@41 | 1 | #!/usr/bin/env python |
paul@41 | 2 | |
paul@41 | 3 | """ |
paul@41 | 4 | Moin wiki table serialiser. |
paul@41 | 5 | |
paul@85 | 6 | Copyright (C) 2017, 2018 Paul Boddie <paul@boddie.org.uk> |
paul@41 | 7 | |
paul@41 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@41 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@41 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@41 | 11 | version. |
paul@41 | 12 | |
paul@41 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@41 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@41 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@41 | 16 | details. |
paul@41 | 17 | |
paul@41 | 18 | You should have received a copy of the GNU General Public License along with |
paul@41 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@41 | 20 | """ |
paul@41 | 21 | |
paul@85 | 22 | from moinformat.serialisers.moin.moin import MoinSerialiser |
paul@41 | 23 | |
paul@85 | 24 | class MoinTableSerialiser(MoinSerialiser): |
paul@41 | 25 | |
paul@41 | 26 | "Serialisation of the page." |
paul@41 | 27 | |
paul@41 | 28 | def init(self): |
paul@41 | 29 | self.first_cell = False |
paul@41 | 30 | self.first_row = False |
paul@41 | 31 | |
paul@41 | 32 | def start_table(self): |
paul@41 | 33 | self.first_row = True |
paul@41 | 34 | |
paul@41 | 35 | def start_table_cell(self, attrs): |
paul@41 | 36 | if not self.first_cell: |
paul@41 | 37 | self.out("||") |
paul@41 | 38 | else: |
paul@41 | 39 | self.first_cell = False |
paul@41 | 40 | |
paul@41 | 41 | if attrs and not attrs.empty(): |
paul@41 | 42 | attrs.to_string(self) |
paul@41 | 43 | |
paul@41 | 44 | def start_table_row(self): |
paul@41 | 45 | self.first_cell = True |
paul@41 | 46 | if not self.first_row: |
paul@41 | 47 | self.out("==") |
paul@41 | 48 | else: |
paul@41 | 49 | self.first_row = False |
paul@41 | 50 | |
paul@41 | 51 | def end_table_row(self, trailing): |
paul@41 | 52 | self.out(trailing) |
paul@41 | 53 | |
paul@85 | 54 | serialiser = MoinTableSerialiser |
paul@41 | 55 | |
paul@41 | 56 | # vim: tabstop=4 expandtab shiftwidth=4 |