• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- coding: utf-8 -*-
2# Copyright 2019 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Utilities for generating html."""
7
8
9def GetPageHeader(page_title):
10  return """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
11"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
12<html>
13<head>
14<style type="text/css">
15table
16{
17border-collapse:collapse;
18}
19table, td, th
20{
21border:1px solid black;
22}
23</style>
24<script type="text/javascript">
25function displayRow(id){
26  var row = document.getElementById("group_"+id);
27  if (row.style.display == '')  row.style.display = 'none';
28    else row.style.display = '';
29  }
30</script>
31<title>%s</title>
32</head>
33<body>
34
35""" % page_title
36
37
38def GetListHeader():
39  return '<ul>'
40
41
42def GetListItem(text):
43  return '<li>%s</li>' % text
44
45
46def GetListFooter():
47  return '</ul>'
48
49
50def GetList(items):
51  return '<ul>%s</ul>' % ''.join(['<li>%s</li>' % item for item in items])
52
53
54def GetParagraph(text):
55  return '<p>%s</p>' % text
56
57
58def GetFooter():
59  return '</body>\n</html>'
60
61
62def GetHeader(text, h=1):
63  return '<h%s>%s</h%s>' % (h, text, h)
64
65
66def GetTableHeader(headers):
67  row = ''.join(['<th>%s</th>' % header for header in headers])
68  return '<table><tr>%s</tr>' % row
69
70
71def GetTableFooter():
72  return '</table>'
73
74
75def FormatLineBreaks(text):
76  return text.replace('\n', '<br/>')
77
78
79def GetTableCell(text):
80  return '<td>%s</td>' % FormatLineBreaks(str(text))
81
82
83def GetTableRow(columns):
84  return '<tr>%s</tr>' % '\n'.join([GetTableCell(column) for column in columns])
85
86
87def GetTable(headers, rows):
88  table = [GetTableHeader(headers)]
89  table.extend([GetTableRow(row) for row in rows])
90  table.append(GetTableFooter())
91  return '\n'.join(table)
92
93
94def GetLink(link, text):
95  return "<a href='%s'>%s</a>" % (link, text)
96