Skip to content

Instantly share code, notes, and snippets.

@sirex
Created August 14, 2014 06:43
Show Gist options
  • Save sirex/1443b46ce0974b909b18 to your computer and use it in GitHub Desktop.
Save sirex/1443b46ce0974b909b18 to your computer and use it in GitHub Desktop.
Comparison of lightweigh markup languages.
<!DOCTYPE html>
<html>
<head>
<style>
.source-block {
}
.output-block {
}
.box {
overflow-y: auto;
padding: 4px;
border: 1px solid black;
height: 400px;
width: 45%;
margin: 10px;
float: left;
}
</style>
</head>
<body>
{% for sample in samples %}
<h1>{{ sample.name }}</h1>
<div class="box source-block">{{ sample.source }}</div>
<div class="box output-block">{{ sample.output }}</div>
{% endfor %}
</body>
</html>
Feature docutils Markdown markdown2
pypi-ranking.info 684 559 100
last release 2014-07-14 2014-05-22 2014-03-07

Heading 1

Content.

bin/pip: bin/python requirements.txt
bin/pip install -r requirements.txt
bin/python:
virtualenv .
import collections
import docutils.core
from pygments import highlight
from pygments.lexers import get_lexer_for_filename
from pygments.formatters import HtmlFormatter
from pathlib import Path
from jinja2 import Environment
from jinja2 import FileSystemLoader
Sample = collections.namedtuple('Sample', ['name', 'filename', 'render'])
def render_docutils(source):
overrides = {'input_encoding': 'utf-8'}
parts = docutils.core.publish_parts(
source=source,
writer_name='html',
settings_overrides=overrides
)
fragment = parts['html_body']
return fragment
SAMPLES = [
Sample('docutils', 'docutils.rst', render_docutils),
]
def main():
output = Path('output')
output.exists() or output.mkdir(parents=True)
formatter = HtmlFormatter(cssclass="source")
env = Environment(loader=FileSystemLoader('.'))
template = env.get_template('base.html')
samples = []
for sample in SAMPLES:
lexer = get_lexer_for_filename(sample.filename)
source = Path(sample.filename)
with source.open('rb') as f:
code = f.read()
target = (output / sample.filename).with_suffix('.html')
with target.open('wb') as f:
f.write('<html><body>It works.</body></html>')
samples.append({
'name': sample.name,
'source': highlight(code, lexer, formatter),
'output': sample.render(code),
})
html = template.render(samples=samples)
with (output / 'index.html').open('wb') as f:
f.write(html)
if __name__ == '__main__':
main()
Jinja2==2.7.3
Markdown==2.4.1
MarkupSafe==0.23
Pygments==1.6
argparse==1.2.1
distribute==0.6.24
docutils==0.12
markdown2==2.2.1
pathlib==1.0
wsgiref==0.1.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment