"""Test cases for Highlight."""
from .. import util
import pymdownx.arithmatex as arithmatex
from pymdownx.inlinehilite import InlineHiliteException
import warnings
def _format(src, language, class_name, md):
"""Inline math formatter."""
return '{}'.format(language, class_name, src)
def _default_format(src, language, class_name, md):
"""Inline math formatter."""
return '
'
R'import module'
R'.
import module.
#!python import module.
import module.
Code
`Not code`
' ) self.check_markdown( r'\\`Code`', r'\Code
\`Not code`
' ) self.check_markdown( r'\\\\`Code`', r'\\Code
'
'import module'
'
Lets test inline highlight no guessing and no text styling import module.
Lets test inline highlight no guessing and no text styling import module.
Lets test inline highlight no guessing and no text styling import module.
import module.
import module.
import module.
Thou shalt be re-educated through labour should this test ever fails.
``` ''', r'''<!DOCTYPE html>
<html>
<body>
<h1>My great test</h1>
<p>Thou shalt be re-educated through labour should this test ever fails.</p>
</body>
</html>
import module.
import module.
#!python import module.
import module.
''', True ) class TestLegacyInlineHiliteCustom1(util.MdCase): """Test custom InlineHilite cases.""" extension = [ 'pymdownx.highlight', 'pymdownx.inlinehilite', ] extension_configs = { 'pymdownx.inlinehilite': { 'css_class': 'inlinehilite', 'custom_inline': [ { 'name': 'math', 'class': 'arithmatex', 'format': arithmatex.inline_mathjax_format } ] } } def test_legacy_arithmatex(self): """Test Arithmatex.""" with warnings.catch_warnings(record=True) as w: self.check_markdown( r'`#!math 3 + 3`', r'''
''', True ) self.assertTrue(len(w) == 1) self.assertTrue(issubclass(w[-1].category, DeprecationWarning)) class TestInlineHiliteCustom2(util.MdCase): """Test custom InlineHilite cases.""" extension = [ 'pymdownx.highlight', 'pymdownx.inlinehilite', ] extension_configs = { 'pymdownx.inlinehilite': { 'css_class': 'inlinehilite', 'custom_inline': [ { 'name': 'math', 'class': 'arithmatex', 'format': arithmatex.arithmatex_inline_format(mode="mathjax", preview=True) } ] } } def test_preview_arithmatex(self): """Test preview Arithmatex.""" self.check_markdown( r'`#!math 3 + 3`', r'
3 + 3' r'
' ) class TestLegacyInlineHiliteCustom2(util.MdCase): """Test custom InlineHilite cases.""" extension = [ 'pymdownx.highlight', 'pymdownx.inlinehilite', ] extension_configs = { 'pymdownx.inlinehilite': { 'css_class': 'inlinehilite', 'custom_inline': [ { 'name': 'math', 'class': 'arithmatex', 'format': arithmatex.inline_mathjax_preview_format } ] } } def test_legacy_preview_arithmatex(self): """Test preview Arithmatex.""" with warnings.catch_warnings(record=True) as w: self.check_markdown( r'`#!math 3 + 3`', r'3 + 3' r'
' ) self.assertTrue(len(w) == 1) self.assertTrue(issubclass(w[-1].category, DeprecationWarning)) class TestInlineHiliteCustom3(util.MdCase): """Test custom InlineHilite cases.""" extension = [ 'pymdownx.highlight', 'pymdownx.inlinehilite', ] extension_configs = { 'pymdownx.inlinehilite': { 'css_class': 'inlinehilite', 'custom_inline': [ { 'name': 'math', 'class': 'arithmatex', 'format': arithmatex.arithmatex_inline_format(mode="generic") } ] } } def test_arithmatex_generic(self): """Test generic Arithmatex.""" self.check_markdown( r'`#!math 3 + 3`', r'\(3 + 3\)
' ) class TestLegacyInlineHiliteCustom3(util.MdCase): """Test custom InlineHilite cases.""" extension = [ 'pymdownx.highlight', 'pymdownx.inlinehilite', ] extension_configs = { 'pymdownx.inlinehilite': { 'css_class': 'inlinehilite', 'custom_inline': [ { 'name': 'math', 'class': 'arithmatex', 'format': arithmatex.inline_generic_format } ] } } def test_legacy_arithmatex_generic(self): """Test generic Arithmatex.""" with warnings.catch_warnings(record=True) as w: self.check_markdown( r'`#!math 3 + 3`', r'\(3 + 3\)
' ) self.assertTrue(len(w) == 1) self.assertTrue(issubclass(w[-1].category, DeprecationWarning)) class TestInlineHiliteCustom4(util.MdCase): """Test custom InlineHilite cases.""" extension = [ 'pymdownx.highlight', 'pymdownx.inlinehilite', ] extension_configs = { 'pymdownx.inlinehilite': { 'css_class': 'inlinehilite', 'custom_inline': [ { 'name': 'test', 'class': 'class-test', 'format': _format } ] } } def test_custom(self): """Test custom formatter.""" self.check_markdown( r'`#!test src test`', r'src test
' ) class TestInlineHiliteCustom5(util.MdCase): """Test custom InlineHilite cases.""" extension = [ 'pymdownx.highlight', 'pymdownx.inlinehilite', ] extension_configs = { 'pymdownx.inlinehilite': { 'css_class': 'inlinehilite', 'custom_inline': [ { 'name': '*', 'class': 'overwrite', 'format': _default_format }, { 'name': 'test', 'class': 'class-test', 'format': _format } ] } } def test_custom(self): """Test custom formatter.""" self.check_markdown( r'`#!test src test` `#!python src test`', r'src test
`#!test boom`
' ) class TestInlineHiliteCustomBrokenFormatterFail(util.MdCase): """Test custom broken InlineHilite cases fails.""" extension = [ 'pymdownx.highlight', 'pymdownx.inlinehilite', ] extension_configs = { 'pymdownx.inlinehilite': { 'custom_inline': [ { 'name': 'test', 'class': 'test', 'format': _format_exploder_fail } ] } } def test_broken(self): """Test custom broken formatter.""" with self.assertRaises(InlineHiliteException): self.check_markdown( r'`#!test boom`', r'' )