/usr/lib/python3/dist-packages/klaus/markup.py is in python3-klaus 1.2.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | import os
LANGUAGES = []
def get_renderer(filename):
_, ext = os.path.splitext(filename)
for extensions, renderer in LANGUAGES:
if ext in extensions:
return renderer
def can_render(filename):
return get_renderer(filename) is not None
def render(filename, content=None):
if content is None:
content = open(filename).read()
return get_renderer(filename)(content)
def _load_markdown():
try:
import markdown
except ImportError:
return
def render_markdown(content):
return markdown.markdown(content, extensions=['toc', 'extra'])
LANGUAGES.append((['.md', '.mkdn', '.mdwn', '.markdown'], render_markdown))
def _load_restructured_text():
try:
from docutils.core import publish_parts
from docutils.writers.html4css1 import Writer
except ImportError:
return
def render_rest(content):
# start by h2 and ignore invalid directives and so on
# (most likely from Sphinx)
settings = {'initial_header_level': 2, 'report_level': 'quiet'}
return publish_parts(content,
writer=Writer(),
settings_overrides=settings).get('html_body')
LANGUAGES.append((['.rst', '.rest'], render_rest))
for loader in [_load_markdown, _load_restructured_text]:
loader()
|