import importlib.util from pathlib import Path import sys spec = importlib.util.spec_from_file_location( "documentation_highlighting", Path(__file__).parents[1] / "netbox_documentation" / "highlighting.py", ) highlighting = importlib.util.module_from_spec(spec) sys.modules[spec.name] = highlighting spec.loader.exec_module(highlighting) def test_highlights_markdown_fence_with_language(): result = highlighting.highlight_code_blocks('
def f():\n    return 1\n
') assert 'class="doc-hl" data-lang="Python"' in result assert 'def' in result def test_highlights_tinymce_code_sample_and_keeps_escaping(): result = highlighting.highlight_code_blocks('
<b onclick="x">hi</b>
') assert 'data-lang="HTML"' in result assert "interface Gi0/1', '
x
'): assert highlighting.highlight_code_blocks(block) == block