blob: 688955ffa4579b8f9d7c8e95308800972662ef91 [file] [log] [blame]
# -*- coding: utf-8 -*-
# Copyright 2019 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Utilities for generating html."""
def GetPageHeader(page_title):
return """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<style type="text/css">
table, td, th
border:1px solid black;
<script type="text/javascript">
function displayRow(id){
var row = document.getElementById("group_"+id);
if ( == '') = 'none';
else = '';
""" % page_title
def GetListHeader():
return '<ul>'
def GetListItem(text):
return '<li>%s</li>' % text
def GetListFooter():
return '</ul>'
def GetList(items):
return '<ul>%s</ul>' % ''.join(['<li>%s</li>' % item for item in items])
def GetParagraph(text):
return '<p>%s</p>' % text
def GetFooter():
return '</body>\n</html>'
def GetHeader(text, h=1):
return '<h%s>%s</h%s>' % (h, text, h)
def GetTableHeader(headers):
row = ''.join(['<th>%s</th>' % header for header in headers])
return '<table><tr>%s</tr>' % row
def GetTableFooter():
return '</table>'
def FormatLineBreaks(text):
return text.replace('\n', '<br/>')
def GetTableCell(text):
return '<td>%s</td>' % FormatLineBreaks(str(text))
def GetTableRow(columns):
return '<tr>%s</tr>' % '\n'.join([GetTableCell(column) for column in columns])
def GetTable(headers, rows):
table = [GetTableHeader(headers)]
table.extend([GetTableRow(row) for row in rows])
return '\n'.join(table)
def GetLink(link, text):
return "<a href='%s'>%s</a>" % (link, text)