Add fix_decorator_classes.
This commit is contained in:
parent
ada3fc4caa
commit
b1627517c8
1 changed files with 23 additions and 1 deletions
|
@ -553,6 +553,26 @@ def fix_argument_def_classes(element):
|
||||||
element['class'].remove('o')
|
element['class'].remove('o')
|
||||||
element['class'].append('n')
|
element['class'].append('n')
|
||||||
|
|
||||||
|
def fix_decorator_classes(element):
|
||||||
|
'''
|
||||||
|
Given the first element of a decorator expression, this gives the decorator
|
||||||
|
class to all the siblings for the rest of the line, because pygments stops
|
||||||
|
coloring after it finds a dot i.e. [@decorators].my_decorator.
|
||||||
|
'''
|
||||||
|
while True:
|
||||||
|
if get_innertext(element).endswith('\n'):
|
||||||
|
break
|
||||||
|
|
||||||
|
if isinstance(element, bs4.NavigableString):
|
||||||
|
element = element.nextSibling
|
||||||
|
continue
|
||||||
|
|
||||||
|
# print(element, element['class'])
|
||||||
|
if element['class'] == ['n']:
|
||||||
|
element['class'] = ['nd']
|
||||||
|
|
||||||
|
element = element.nextSibling
|
||||||
|
|
||||||
def fix_repl_classes(element):
|
def fix_repl_classes(element):
|
||||||
'''
|
'''
|
||||||
Given a <pre> element, this function detects that this pre contains a REPL
|
Given a <pre> element, this function detects that this pre contains a REPL
|
||||||
|
@ -583,7 +603,6 @@ def fix_repl_classes(element):
|
||||||
|
|
||||||
if isinstance(child, bs4.NavigableString):
|
if isinstance(child, bs4.NavigableString):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if del_styles:
|
if del_styles:
|
||||||
del child['class']
|
del child['class']
|
||||||
|
|
||||||
|
@ -614,6 +633,9 @@ def fix_classes(soup):
|
||||||
if get_innertext(element.nextSibling) == '(':
|
if get_innertext(element.nextSibling) == '(':
|
||||||
fix_argument_call_classes(element)
|
fix_argument_call_classes(element)
|
||||||
|
|
||||||
|
for element in soup.find_all('span', {'class': 'nd'}):
|
||||||
|
fix_decorator_classes(element)
|
||||||
|
|
||||||
def fix_reddit_links(soup):
|
def fix_reddit_links(soup):
|
||||||
for a in soup.find_all('a'):
|
for a in soup.find_all('a'):
|
||||||
if not a.get('href'):
|
if not a.get('href'):
|
||||||
|
|
Loading…
Reference in a new issue