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