/usr/lib/python3/dist-packages/tldr/parser.py is in tldr-py 0.7.0-2.
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 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import io
import click
from tldr.config import get_config
def parse_page(page):
"""Parse the command man page."""
colors = get_config()['colors']
with io.open(page, encoding='utf-8') as f:
lines = f.readlines()
output_lines = []
for line in lines[1:]:
if is_headline(line):
continue
elif is_description(line):
output_lines.append(click.style(line.replace('>', ' '),
fg=colors['description']))
elif is_old_usage(line):
output_lines.append(click.style(line, fg=colors['usage']))
elif is_code_example(line):
line = ' ' + line if line.startswith('`') else line[2:]
output_lines.append(click.style(line.replace('`', ''),
fg=colors['command']))
elif is_line_break(line):
output_lines.append(click.style(line))
else:
output_lines.append(click.style('- ' + line, fg=colors['usage']))
return output_lines
def is_headline(line):
return line.startswith(('#', '='))
def is_description(line):
return line.startswith('>')
def is_old_usage(line):
return line.startswith('-')
def is_code_example(line):
return line.startswith(('`', ' '))
def is_line_break(line):
return line.startswith("\n")
|