paul@41 | 1 | #!/usr/bin/env python |
paul@41 | 2 | |
paul@41 | 3 | """ |
paul@41 | 4 | Moin wiki table serialiser. |
paul@41 | 5 | |
paul@331 | 6 | Copyright (C) 2017, 2018, 2021, 2023 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@301 | 28 | input_formats = ["table"] |
paul@301 | 29 | |
paul@41 | 30 | def init(self): |
paul@41 | 31 | self.first_cell = False |
paul@41 | 32 | self.first_row = False |
paul@41 | 33 | |
paul@331 | 34 | def table(self, table): |
paul@41 | 35 | self.first_row = True |
paul@331 | 36 | self.container(table) |
paul@41 | 37 | |
paul@331 | 38 | def table_cell(self, table_cell): |
paul@41 | 39 | if not self.first_cell: |
paul@331 | 40 | self.out(table_cell.leading) |
paul@41 | 41 | self.out("||") |
paul@41 | 42 | else: |
paul@41 | 43 | self.first_cell = False |
paul@41 | 44 | |
paul@331 | 45 | self.out(table_cell.padding) |
paul@331 | 46 | self.container(table_cell) |
paul@331 | 47 | |
paul@331 | 48 | def table_row(self, table_row): |
paul@41 | 49 | self.first_cell = True |
paul@331 | 50 | |
paul@41 | 51 | if not self.first_row: |
paul@331 | 52 | self.out(table_row.leading) |
paul@41 | 53 | self.out("==") |
paul@331 | 54 | self.out(table_row.padding) |
paul@41 | 55 | else: |
paul@41 | 56 | self.first_row = False |
paul@41 | 57 | |
paul@331 | 58 | self.container(table_row) |
paul@331 | 59 | self.out(table_row.trailing) |
paul@41 | 60 | |
paul@331 | 61 | def continuation(self, continuation): |
paul@331 | 62 | self.out(continuation.text) |
paul@149 | 63 | |
paul@85 | 64 | serialiser = MoinTableSerialiser |
paul@41 | 65 | |
paul@41 | 66 | # vim: tabstop=4 expandtab shiftwidth=4 |