# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of pylint.
#
# pylint is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option) any
# later version.
#
# pylint is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with pylint. If not, see .
"""HTML formatting drivers for ureports"""
from pylint.reporters.ureports import BaseWriter
class HTMLWriter(BaseWriter):
"""format layouts as HTML"""
def __init__(self, snippet=None):
super(HTMLWriter, self).__init__()
self.snippet = snippet
def begin_format(self):
"""begin to format a layout"""
super(HTMLWriter, self).begin_format()
if self.snippet is None:
self.writeln(u'')
self.writeln(u'
')
def end_format(self):
"""finished to format a layout"""
if self.snippet is None:
self.writeln(u'')
self.writeln(u'')
def visit_section(self, layout):
"""display a section as html, using div + h[section level]"""
self.section += 1
self.writeln(u'')
self.format_children(layout)
self.writeln(u'
')
self.section -= 1
def visit_title(self, layout):
"""display a title using """
self.write(u'' % self.section)
self.format_children(layout)
self.writeln(u'' % self.section)
def visit_table(self, layout):
"""display a table as html"""
self.writeln(u'')
table_content = self.get_table_content(layout)
for i, row in enumerate(table_content):
if i == 0 and layout.rheaders:
self.writeln(u'' % (u'even' if i % 2 else u'odd'))
for j, cell in enumerate(row):
cell = cell or u' '
if (layout.rheaders and i == 0) or \
(layout.cheaders and j == 0):
self.writeln(u'%s | ' % cell)
else:
self.writeln(u'%s | ' % cell)
self.writeln(u'
')
self.writeln(u'
')
def visit_paragraph(self, layout):
"""display links (using )"""
self.write(u'
')
self.format_children(layout)
self.write(u'
')
def visit_verbatimtext(self, layout):
"""display verbatim text (using )"""
self.write(u'')
self.write(layout.data.replace(u'&', u'&').replace(u'<', u'<'))
self.write(u'
')
def visit_text(self, layout):
"""add some text"""
data = layout.data
if layout.escaped:
data = data.replace(u'&', u'&').replace(u'<', u'<')
self.write(data)