/
default.py
69 lines (64 loc) · 1.99 KB
/
default.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""LEXOR: DEFAULT Writer Style
The goal of this style is to take any file, treat it as HTML and
write it in the lexor format. The lexor format is still being
developed. It will essentially be derived from Markdown, Kramdown,
pandoc and other preprocessors out there.
"""
from lexor import init, load_aux
INFO = init(
version=(0, 0, 1, 'rc', 3),
lang='lexor',
type='writer',
description='Writes files in the lexor format.',
url='http://jmlopez-rod.github.io/lexor-lang/lexor-writer-default',
author='Manuel Lopez',
author_email='jmlopez.rod@gmail.com',
license='BSD License',
path=__file__
)
DEFAULTS = {
'width': '70',
'add_block': '',
'del_block': '',
'header': 'setext',
'hashheader': 'closed',
}
MOD = load_aux(INFO)
MAPPING = {
'list_item': MOD['list'].LexorListItemNW,
'ul': MOD['list'].ListNW,
'ol': 'ul',
'li': MOD['list'].ListItemNW,
'a': MOD['nw'].AnchorNW,
'em': MOD['inline'].EmNW,
'i': 'em',
'strong': MOD['inline'].StrongNW,
'hr': MOD['nw'].HRuleNW,
'h1': MOD['header'].HeaderNW,
'p': MOD['paragraph'].ParagraphNW,
'#document': MOD['nw'].DocumentNW,
'#text': MOD['nw'].TextNW,
'#entity': MOD['nw'].EntityNW,
'#comment': MOD['nw'].CommentNW,
'#doctype': MOD['nw'].DoctypeNW,
'#cdata-section': MOD['nw'].CDataNW,
'__default__': MOD['nw'].DefaultNW,
}
for item in ['h2', 'h3', 'h4', 'h5', 'h6']:
MAPPING[item] = 'h1'
def pre_process(writer, _):
"""Sets the default width for the writer. """
writer.disable_raw()
writer.enable_wrap()
writer.header = writer.defaults['header']
writer.width = int(writer.defaults['width'])
writer.pre_node = 0
writer.list_level = 0
for name in writer.defaults['add_block'].split(','):
if name and name not in MOD['nw'].BLOCK:
MOD['nw'].BLOCK.append(name)
for name in writer.defaults['del_block'].split(','):
try:
MOD['nw'].BLOCK.remove(name)
except ValueError:
pass