Skip to content

Instantly share code, notes, and snippets.

@aaronchall
Last active October 12, 2015 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronchall/d8c735e5206531189af0 to your computer and use it in GitHub Desktop.
Save aaronchall/d8c735e5206531189af0 to your computer and use it in GitHub Desktop.
23 lines of Python, generate 67 lines of HTML
API:
def main():
nav = Nav([UnorderedList([ListItem([Link('foo/link', 'foo text')]),
ListItem([Link('bar/link', 'bar text')])])])
htmlobjs = Document(
head=Head(title='Example',
elems=[Keywords(['python', 'html']),
Description('demo page'),
Author('Aaron Hall'),
]),
body=Body([
Header([nav]),
Section(['This is a section.']),
Article([H1('Top Level Topic'),
P(['This is a paragraph under the article']),
H2('2nd level heading'),
P(['Another paragraph, with a {link} to back it up.'.format(
link=Link('http://foo/bar', 'linky'))]),
]),
Aside(['This <aside> could be a floaty sidebar']),
Footer([nav, 'Maybe this footer could float on the side on a wide screen']),
]),
)
Output:
<!DOCTYPE html>
<html lang="en">
<head>
<title>
Example
</title>
<meta charset="UTF-8">
<meta content="python, html" name="keywords">
<meta content="demo page" name="description">
<meta content="Aaron Hall" name="author">
</head>
<body>
<header>
<nav>
<ul>
<li>
<a href="foo/link">
foo text
</a>
</li>
<li>
<a href="bar/link">
bar text
</a>
</li>
</ul>
</nav>
</header>
<section>
This is a section.
</section>
<article>
<h1>
Top Level Topic
</h1>
<p>
This is a paragraph under the article
</p>
<h2>
2nd level heading
</h2>
<p>
Another paragraph, with a <a href="http://foo/bar">
linky
</a> to back it up.
</p>
</article>
<aside>
This <aside> could be a floaty sidebar
</aside>
<footer>
<nav>
<ul>
<li>
<a href="foo/link">
foo text
</a>
</li>
<li>
<a href="bar/link">
bar text
</a>
</li>
</ul>
</nav>
Maybe this footer could float on the side on a wide screen
</footer>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment