in src/processors/processors.py [0:0]
def process_code_blocks(tree):
if replace_simple_code:
# some spellcheckers may not know what to do with <code> elements,
# we replace in-line code blocks with span to improve spellcheckers
# TODO: avoid global variable hack here and pass the parameter explicitly
for element in tree.select("code"):
if len(element.attrs) == 0:
element.name = "span"
element['style'] = "font-style: italic; text-decoration: underline;"
for element in tree.select('pre > code'):
class_names = element.get("class")
lang = None
if class_names is not None:
for class_name in class_names:
if class_name.startswith("language-"):
lang = class_name[len("language-"):]
if lang is None:
continue
parent_div = find_closest_tag(element, 'div')
# Skip executable samples
if parent_div is not None and parent_div.has_attr('class') and "sample" in parent_div['class']:
continue
element['data-lang'] = languageMimeTypeMap[lang]
element['class'] = "code _highlighted"
return tree