-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathnginx.py
More file actions
31 lines (27 loc) · 1.18 KB
/
Copy pathnginx.py
File metadata and controls
31 lines (27 loc) · 1.18 KB
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
from lxml.html import builder
from showdocs import structs
from showdocs.filters import common
class DirectiveFilter(common.Filter):
def process(self):
for e in self.root.cssselect('div.directive[id]'):
attr = {'data-showdocs': e.get('id'), 'class': structs.decorate.BLOCK}
wrapped = builder.E('div', attr)
eidx = e.getparent().index(e)
e.getparent()[eidx] = wrapped
wrapped.append(e)
for e in self.root.cssselect('div[data-showdocs]'):
eidx = e.getparent().index(e)
siblings = []
for sibling in e.itersiblings():
if sibling.tag == 'div' and sibling.get('data-showdocs'):
break
# devdocs appends this at the end, stop here.
if sibling.get('class') == '_attribution':
break
siblings.append(sibling)
del e.getparent()[eidx + 1:eidx + len(siblings)]
for s in siblings:
e.append(s)
for e in self.root.cssselect('div[data-showdocs] code strong'):
e.set('data-showdocs', e.text)
e.classes.add(structs.decorate.BACK)