"""Test cases for SuperFences."""
from .. import util
import pymdownx.arithmatex as arithmatex
import pymdownx.superfences as superfences
from pymdownx.superfences import SuperFencesException
import warnings
def custom_format(source, language, class_name, options, md, **kwargs):
"""Custom format."""
return '
{}
'.format(language, class_name,
options['opt'], source)
def default_format(source, language, class_name, options, md, **kwargs):
"""Default format."""
return '{}'.format(language, class_name, source)
def custom_exploder(source, language, class_name, options, md, **kwargs):
"""Broken format."""
raise Exception('Boom!')
def custom_exploder_fail(source, language, class_name, options, md, **kwargs):
"""Broken format."""
raise SuperFencesException('Boom!')
def custom_validator_exploder(language, inputs, options, attrs, md):
"""Broken validator."""
raise Exception('Boom!')
def custom_validator(language, inputs, options, attrs, md):
"""Custom validator."""
okay = True
for k in inputs.keys():
if k != 'opt':
okay = False
break
if okay:
if inputs['opt'] != "A":
okay = False
else:
options['opt'] = inputs['opt']
return okay
def custom_validator_except(language, inputs, options, attrs, md):
"""Custom validator."""
okay = True
try:
for k in inputs.keys():
if k != 'opt':
okay = False
break
if okay:
if inputs['opt'] != "A":
okay = False
else:
options['opt'] = inputs['opt']
except KeyError as e:
raise SuperFencesException from e
return okay
class TestHighlightTitle(util.MdCase):
"""Test title cases."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
def test_title(self):
"""Test auto title."""
self.check_markdown(
r'''
```pycon title="My title"
>>> import test
```
''',
r'''
''', # noqa: E501
True
)
def test_title_table(self):
"""Test auto title."""
self.check_markdown(
r'''
```pycon title="My title" linenums="1"
>>> import test
```
''',
r'''
''', # noqa: E501
True
)
class TestHighlightStrip(util.MdCase):
"""Test Highlight's stripping of new lines."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {'pymdownx.highlight': {'stripnl': False}}
def test_no_stripnl(self):
"""Test no stripping of leading and trailing new lines."""
self.check_markdown(
r'''
```py
import foo
import bar
```
''',
r'''
''',
True
)
class TestHighlightAutoTitleOverride(util.MdCase):
"""Test title cases."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'auto_title': True,
"auto_title_map": {
"Python Console Session": "Python"
}
}
}
def test_auto_tile(self):
"""Test auto title."""
self.check_markdown(
r'''
```{.python title="My Title"}
import test
```
''',
r'''
''', # noqa: E501
True
)
def test_auto_tile_map(self):
"""Test auto title."""
self.check_markdown(
r'''
```{.pycon title="My Title"}
>>> import test
```
''',
r'''
''', # noqa: E501
True
)
class TestHighlightLineWrapsInline(util.MdCase):
"""Test highlight line wraps."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'line_spans': '__my_span',
'linenums_style': 'inline'
}
}
def test_linespans(self):
"""Test wrapping a line in line spans."""
self.check_markdown(
r'''
```python linenums="2"
import test
```
''',
r'''
''', # noqa: E501
True
)
class TestHighlightLineWrapsPymdownxInline(util.MdCase):
"""Test highlight line wraps."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'line_spans': '__my_span',
'linenums_style': 'pymdownx-inline'
}
}
def test_linespans(self):
"""Test wrapping a line in line spans."""
self.check_markdown(
r'''
```python linenums="2"
import test
```
''',
r'''
''', # noqa: E501
True
)
class TestHighlightLineWrapsPymdownsTable(util.MdCase):
"""Test highlight line wraps."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'line_spans': '__my_span',
'linenums_style': 'table'
}
}
def test_linespans(self):
"""Test wrapping a line in line spans."""
self.check_markdown(
r'''
```python linenums="2"
import test
```
''',
r'''
''', # noqa: E501
True
)
class TestHighlightLineAnchorsInline(util.MdCase):
"""Test highlight line wraps."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'line_anchors': '__my_span',
'linenums_style': 'inline'
}
}
def test_linespans(self):
"""Test wrapping a line in line spans."""
self.check_markdown(
r'''
```python linenums="2"
import test
```
''',
r'''
''', # noqa: E501
True
)
class TestHighlightLineAnchorsPymdownxInline(util.MdCase):
"""Test highlight line wraps."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'line_anchors': '__my_span',
'linenums_style': 'pymdownx-inline'
}
}
def test_linespans(self):
"""Test wrapping a line in line spans."""
self.check_markdown(
r'''
```python linenums="2"
import test
```
''',
r'''
''', # noqa: E501
True
)
class TestHighlightLineAnchorsPymdownsTable(util.MdCase):
"""Test highlight line wraps."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'line_anchors': '__my_span',
'linenums_style': 'table'
}
}
def test_linespans(self):
"""Test wrapping a line in line spans."""
self.check_markdown(
r'''
```python linenums="2"
import test
```
''',
r'''
''', # noqa: E501
True
)
class TestHighlightAnchorLinenumInline(util.MdCase):
"""Test highlight line wraps."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'anchor_linenums': True,
'linenums_style': 'inline'
}
}
def test_linespans(self):
"""Test wrapping a line in line spans."""
self.check_markdown(
r'''
```python linenums="2"
import test
```
''',
r'''
''', # noqa: E501
True
)
def test_linespans_id(self):
"""Test wrapping a line in line spans with an ID."""
self.check_markdown(
r'''
```{.python #id linenums="2"}
import test
```
''',
r'''
''', # noqa: E501
True
)
class TestHighlightAnchorLinenumsPymdownxInline(util.MdCase):
"""Test highlight line wraps."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'anchor_linenums': True,
'linenums_style': 'pymdownx-inline'
}
}
def test_linespans(self):
"""Test wrapping a line in line spans."""
self.check_markdown(
r'''
```python linenums="2"
import test
```
''',
r'''
''', # noqa: E501
True
)
def test_linespans_id(self):
"""Test wrapping a line in line spans."""
self.check_markdown(
r'''
```{.python #id linenums="2"}
import test
```
''',
r'''
''', # noqa: E501
True
)
class TestHighlightAnchorLinenumsPymdownsTable(util.MdCase):
"""Test highlight line wraps."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'anchor_linenums': True,
'linenums_style': 'table'
}
}
def test_linespans(self):
"""Test wrapping a line in line spans."""
self.check_markdown(
r'''
```python linenums="2"
import test
```
''',
r'''
''', # noqa: E501
True
)
class TestHighlightAnchorLinenumNameInline(util.MdCase):
"""Test highlight line wraps."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'anchor_linenums': True,
'line_anchors': '__my_span',
'linenums_style': 'inline'
}
}
def test_linespans(self):
"""Test wrapping a line in line spans."""
self.check_markdown(
r'''
```python linenums="2"
import test
```
''',
r'''
''', # noqa: E501
True
)
class TestHighlightLines(util.MdCase):
"""Test line highlighting."""
extension = ['pymdownx.superfences']
extension_configs = {}
def test_highlight_range(self):
"""Test highlight ranges."""
self.check_markdown(
r'''
```py3 hl_lines="1-2 5 7-8"
import foo
import boo.baz
import foo.bar.baz
class Foo:
def __init__(self):
self.foo = None
self.bar = None
self.baz = None
```
''',
'''
import foo
import boo.baz
import foo.bar.baz
class Foo:
def __init__(self):
self.foo = None
self.bar = None
self.baz = None
''', # noqa: E501
True
)
def test_highlight_out_of_range(self):
"""Test highlight ranges."""
self.check_markdown(
r'''
```py3 hl_lines="0 10"
import foo
import boo.baz
import foo.bar.baz
class Foo:
def __init__(self):
self.foo = None
self.bar = None
self.baz = None
```
''',
'''
import foo
import boo.baz
import foo.bar.baz
class Foo:
def __init__(self):
self.foo = None
self.bar = None
self.baz = None
''', # noqa: E501
True
)
def test_highlight_in_range_only(self):
"""Test highlight ranges."""
self.check_markdown(
r'''
```py3 hl_lines="0-10"
import foo
import boo.baz
import foo.bar.baz
class Foo:
def __init__(self):
self.foo = None
self.bar = None
self.baz = None
```
''',
'''
import foo
import boo.baz
import foo.bar.baz
class Foo:
def __init__(self):
self.foo = None
self.bar = None
self.baz = None
''', # noqa: E501
True
)
def test_nonword_boundary_language(self):
"""Test language with non-word boundary."""
self.check_markdown(
"""
```c++ hl_lines="1"
#include
```
""",
"""
""", # noqa: E501
True
)
def test_omitted_language(self):
"""Test when language is omitted."""
self.check_markdown(
"""
```hl_lines="1"
some
code
```
""",
"""
""",
True
)
class TestSuperFencesClassesIds(util.MdCase):
"""Test classes and ids without attribute lists."""
extension = ['pymdownx.superfences']
extension_configs = {}
def test_classes(self):
"""Test extra classes."""
self.check_markdown(
r'''
```{.python .more}
import test
```
''',
r'''
''', # noqa: E501
True
)
def test_id(self):
"""Test extra id."""
self.check_markdown(
r'''
```{.python #id}
import test
```
''',
r'''
''', # noqa: E501
True
)
def test_attr(self):
"""Test extra attributes."""
self.check_markdown(
r'''
```{.python #id attr="test"}
import test
```
''',
r'''
''', # noqa: E501
True
)
def test_attrs_alternate_form(self):
"""Test attributes with new alternate form."""
self.check_markdown(
r'''
```python {.test .class #class}
import test
```
''',
r'''
''', # noqa: E501
True
)
def test_issue_2479(self):
"""Test issue #2479."""
self.check_markdown(
"""```test_test_test_test_test_test_test_test``` test test.""",
"""
test_test_test_test_test_test_test_test test test.
""",
True
)
class TestSuperFencesClassesIdsAttrList(util.MdCase):
"""Test fence ids and classes with attribute lists."""
extension = ['pymdownx.superfences', 'markdown.extensions.attr_list']
extension_configs = {}
def test_attribute_lists_with_braces(self):
"""Test attribute lists with braces."""
self.check_markdown(
R'''
``` { .c data-copy="int main() { return 0; }" }
Try copying me for some C code
```
''',
R'''
Try copying me for some C code
''', # noqa: E501
True
)
def test_classes(self):
"""Test extra classes."""
self.check_markdown(
r'''
```{.python .more}
import test
```
''',
r'''
''', # noqa: E501
True
)
def test_id(self):
"""Test extra id."""
self.check_markdown(
r'''
```{.python #id}
import test
```
''',
r'''
''', # noqa: E501
True
)
def test_bad_attr(self):
"""Test bad attribute."""
self.check_markdown(
r'''
```{.python #id attr="test"}
import test
```
''',
r'''
''', # noqa: E501
True
)
def test_data_attr(self):
"""Test data attributes."""
self.check_markdown(
r'''
```{.python #id data-attr="test"}
import test
```
''',
r'''
''', # noqa: E501
True
)
def test_data_attr_linenums(self):
"""Test data attributes with line numbers enabled."""
self.check_markdown(
r'''
```{.python #id data-attr="test" linenums="1"}
import test
```
''',
r'''
''', # noqa: E501
True
)
def test_attrs_alternate_form(self):
"""Test attributes with new alternate form."""
self.check_markdown(
r'''
```python {.test .class #id data-attr="test" linenums="1"}
import test
```
''',
r'''
''', # noqa: E501
True
)
class TestSuperFencesClassesIdsAttrListNoPygments(util.MdCase):
"""Test fence ids and classes with attribute lists and with no Pygments."""
extension = ['pymdownx.highlight', 'pymdownx.superfences', 'markdown.extensions.attr_list']
extension_configs = {
"pymdownx.highlight": {
"use_pygments": False
}
}
def test_classes(self):
"""Test extra classes."""
self.check_markdown(
r'''
```{.python .more}
import test
```
''',
r'''
import test
''',
True
)
def test_id(self):
"""Test extra id."""
self.check_markdown(
r'''
```{.python #id}
import test
```
''',
r'''
import test
''',
True
)
def test_attr(self):
"""Test extra attributes."""
self.check_markdown(
r'''
```{.python #id attr="test"}
import test
```
''',
r'''
import test
''',
True
)
class TestSuperFencesClassesIdsAttrListNoPygmentsOnPre(util.MdCase):
"""Test fence ids and classes with attribute lists and with no Pygments and classes and ids on pre."""
extension = ['pymdownx.highlight', 'pymdownx.superfences', 'markdown.extensions.attr_list']
extension_configs = {
"pymdownx.highlight": {
"use_pygments": False,
"code_attr_on_pre": True
}
}
def test_classes(self):
"""Test extra classes."""
self.check_markdown(
r'''
```{.python .more}
import test
```
''',
r'''
import test
''',
True
)
def test_id(self):
"""Test extra id."""
self.check_markdown(
r'''
```{.python #id}
import test
```
''',
r'''
import test
''',
True
)
def test_attr(self):
"""Test extra attributes."""
self.check_markdown(
r'''
```{.python #id attr="test"}
import test
```
''',
r'''
import test
''',
True
)
class TestSuperFencesBad(util.MdCase):
"""Test bad options."""
extension = ['pymdownx.superfences']
extension_configs = {}
def test_bad_options(self):
"""Test bad options."""
self.check_markdown(
r'''
```python option="bad"
import test
```
''',
r'''
python option="bad"
import test
''',
True
)
def test_bad_option_value(self):
"""Test bad option values."""
self.check_markdown(
r'''
```python hl_lines="unexpected 3" linenums="1"
"""Some file."""
import foo.bar
import boo.baz
import foo.bar.baz
```
''',
r'''
python hl_lines="unexpected 3" linenums="1"
"""Some file."""
import foo.bar
import boo.baz
import foo.bar.baz
''',
True
)
class TestSuperFencesCustom(util.MdCase):
"""Test custom validator and format."""
extension = ['pymdownx.superfences', 'attr_list']
extension_configs = {
'pymdownx.superfences': {
'custom_fences': [
{
'name': 'test',
'class': 'test',
'format': custom_format,
'validator': custom_validator
}
]
}
}
def test_failure(self):
"""
Test failure of custom fence.
Fence failed, gracefully continue with any other fences that can capture this.
"""
self.check_markdown(
r'''
```test
test
```
''',
r'''
''',
True
)
def test_bad_options(self):
"""Test bad option."""
self.check_markdown(
r'''
```test bad="bad"
test
```
''',
r'''
test bad="bad"
test
''',
True
)
def test_bad_option_value(self):
"""Test option with bad value."""
self.check_markdown(
r'''
```test opt="B"
test
```
''',
r'''
test opt="B"
test
''',
True
)
def test_bad_option_no_value(self):
"""Test option with no value."""
self.check_markdown(
r'''
```test opt
test
```
''',
r'''
test opt
test
''',
True
)
def test_custom_options(self):
"""Test option with correct value."""
self.check_markdown(
r'''
```test opt="A"
test
```
''',
r'''
test
''',
True
)
def test_custom_options_attr_list(self):
"""Test option with correct value."""
self.check_markdown(
r'''
```test {opt="A"}
test
```
''',
r'''
test
''',
True
)
class TestSuperFencesCustomException(util.MdCase):
"""Test custom validator and format."""
extension = ['pymdownx.superfences']
extension_configs = {
'pymdownx.superfences': {
'custom_fences': [
{
'name': 'test',
'class': 'test',
'format': custom_format,
'validator': custom_validator_except
}
]
}
}
def test_custom_fail_exception(self):
"""Test custom fences forced exception."""
with self.assertRaises(SuperFencesException):
self.check_markdown(
r'''
```test
test
```
''',
'',
True
)
class TestSuperFencesCustomExceptionAttrList(util.MdCase):
"""Test custom validator and format with attribute lists."""
extension = ['pymdownx.superfences', 'attr_list']
extension_configs = {
'pymdownx.superfences': {
'custom_fences': [
{
'name': 'test',
'class': 'test',
'format': custom_format,
'validator': custom_validator_except
}
]
}
}
def test_custom_fail_exception(self):
"""Test custom fences forced exception with attribute lists."""
with self.assertRaises(SuperFencesException):
self.check_markdown(
r'''
```{.test}
test
```
''',
'',
True
)
class TestSuperFencesCustomDefaultValidator(util.MdCase):
"""Test custom format with default validator."""
extension = ['pymdownx.superfences', 'markdown.extensions.attr_list']
extension_configs = {
'pymdownx.superfences': {
'custom_fences': [
{
'name': 'test',
'class': 'test',
'format': superfences.fence_div_format,
'validator': superfences.default_validator
}
]
}
}
def test_default_validator(self):
"""Test default validator."""
self.check_markdown(
r'''
```{.test opt="A"}
test
```
''',
r'''
test
''',
True
)
class TestSuperFencesCustomArithmatex(util.MdCase):
"""Test custom Arithmatex format."""
extension = ['pymdownx.superfences']
extension_configs = {
'pymdownx.superfences': {
'custom_fences': [
{
'name': 'math',
'class': 'arithmatex',
'format': arithmatex.arithmatex_fenced_format(mode="mathjax")
}
]
}
}
def test_arithmatex(self):
"""Test Arithmatex formatter without preview."""
self.check_markdown(
r'''
```math
E(\mathbf{v}, \mathbf{h}) = -\sum_{i,j}w_{ij}v_i h_j - \sum_i b_i v_i - \sum_j c_j h_j
```
''',
r'''
''',
True
)
class TestSuperFencesCustomLegacyArithmatex(util.MdCase):
"""Test custom Arithmatex format."""
extension = ['pymdownx.superfences']
extension_configs = {
'pymdownx.superfences': {
'custom_fences': [
{
'name': 'math',
'class': 'arithmatex',
'format': arithmatex.fence_mathjax_format
}
]
}
}
def test_legacy_arithmatex(self):
"""Test Arithmatex formatter without preview."""
with warnings.catch_warnings(record=True) as w:
self.check_markdown(
r'''
```math
E(\mathbf{v}, \mathbf{h}) = -\sum_{i,j}w_{ij}v_i h_j - \sum_i b_i v_i - \sum_j c_j h_j
```
''',
r'''
''',
True
)
self.assertTrue(len(w) == 1)
self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
class TestSuperFencesCustomArithmatexPreview(util.MdCase):
"""Test custom Arithmatex preview format."""
extension = ['pymdownx.superfences']
extension_configs = {
'pymdownx.superfences': {
'custom_fences': [
{
'name': 'math',
'class': 'arithmatex',
'format': arithmatex.arithmatex_fenced_format(mode='mathjax', preview=True)
}
]
}
}
def test_arithmatex_preview(self):
"""Test Arithmatex formatter with preview."""
self.check_markdown(
r'''
```math
E(\mathbf{v}, \mathbf{h}) = -\sum_{i,j}w_{ij}v_i h_j - \sum_i b_i v_i - \sum_j c_j h_j
```
''',
r'''
E(\mathbf{v}, \mathbf{h}) = -\sum_{i,j}w_{ij}v_i h_j - \sum_i b_i v_i - \sum_j c_j h_j
''',
True
)
class TestSuperFencesCustomLegacyArithmatexPreview(util.MdCase):
"""Test custom Arithmatex preview format."""
extension = ['pymdownx.superfences']
extension_configs = {
'pymdownx.superfences': {
'custom_fences': [
{
'name': 'math',
'class': 'arithmatex',
'format': arithmatex.fence_mathjax_preview_format
}
]
}
}
def test_legacy_arithmatex_preview(self):
"""Test Arithmatex formatter with preview."""
with warnings.catch_warnings(record=True) as w:
self.check_markdown(
r'''
```math
E(\mathbf{v}, \mathbf{h}) = -\sum_{i,j}w_{ij}v_i h_j - \sum_i b_i v_i - \sum_j c_j h_j
```
''',
r'''
E(\mathbf{v}, \mathbf{h}) = -\sum_{i,j}w_{ij}v_i h_j - \sum_i b_i v_i - \sum_j c_j h_j
''',
True
)
self.assertTrue(len(w) == 1)
self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
class TestSuperFencesCustomArithmatexGeneric(util.MdCase):
"""Test custom Arithmatex generic format."""
extension = ['pymdownx.superfences']
extension_configs = {
'pymdownx.superfences': {
'custom_fences': [
{
'name': 'math',
'class': 'arithmatex',
'format': arithmatex.arithmatex_fenced_format(mode="generic")
}
]
}
}
def test_arithmatex_generic(self):
"""Test Arithmatex generic formatter."""
self.check_markdown(
r'''
```math
E(\mathbf{v}, \mathbf{h}) = -\sum_{i,j}w_{ij}v_i h_j - \sum_i b_i v_i - \sum_j c_j h_j
```
''',
r'''
\[
E(\mathbf{v}, \mathbf{h}) = -\sum_{i,j}w_{ij}v_i h_j - \sum_i b_i v_i - \sum_j c_j h_j
\]
''',
True
)
class TestSuperFencesCustomLegacyArithmatexGeneric(util.MdCase):
"""Test custom Arithmatex generic format."""
extension = ['pymdownx.superfences']
extension_configs = {
'pymdownx.superfences': {
'custom_fences': [
{
'name': 'math',
'class': 'arithmatex',
'format': arithmatex.fence_generic_format
}
]
}
}
def test_legacy_arithmatex_generic(self):
"""Test Arithmatex generic formatter."""
with warnings.catch_warnings(record=True) as w:
self.check_markdown(
r'''
```math
E(\mathbf{v}, \mathbf{h}) = -\sum_{i,j}w_{ij}v_i h_j - \sum_i b_i v_i - \sum_j c_j h_j
```
''',
r'''
\[
E(\mathbf{v}, \mathbf{h}) = -\sum_{i,j}w_{ij}v_i h_j - \sum_i b_i v_i - \sum_j c_j h_j
\]
''',
True
)
self.assertTrue(len(w) == 1)
self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
class TestSuperFencesCustomDefault(util.MdCase):
"""Test overriding the default format."""
extension = ['pymdownx.superfences']
extension_configs = {
'pymdownx.superfences': {
'custom_fences': [
{
'name': '*',
'class': '',
'format': default_format
},
{
'name': 'math',
'class': 'arithmatex',
'format': arithmatex.arithmatex_fenced_format(mode="generic")
}
]
}
}
def test_default_override(self):
"""Test default override."""
self.check_markdown(
r'''
```math
E(\mathbf{v}, \mathbf{h}) = -\sum_{i,j}w_{ij}v_i h_j - \sum_i b_i v_i - \sum_j c_j h_j
```
```python
test
```
''',
r'''
\[
E(\mathbf{v}, \mathbf{h}) = -\sum_{i,j}w_{ij}v_i h_j - \sum_i b_i v_i - \sum_j c_j h_j
\]
test
''',
True
)
class TestSuperFencesCustomBroken(util.MdCase):
"""Test custom formatter that is broken."""
extension = ['pymdownx.superfences']
extension_configs = {
'pymdownx.superfences': {
'custom_fences': [
{
'name': 'test',
'class': 'test',
'format': custom_exploder,
}
]
}
}
def test_broken(self):
"""Test broken fence."""
self.check_markdown(
'''
```test
doesn't matter
```
''',
'''
test
doesn't matter
''',
True
)
def test_broken_blockquote(self):
"""Test broken fence in a blockquote."""
self.check_markdown(
'''
> ```test
> doesn't matter
> ```
''',
'''
test
doesn't matter
''',
True
)
class TestSuperFencesCustomBrokenFail(util.MdCase):
"""Test custom formatter that is broken and causes a failure."""
extension = ['pymdownx.superfences']
extension_configs = {
'pymdownx.superfences': {
'custom_fences': [
{
'name': 'test',
'class': 'test',
'format': custom_exploder_fail,
}
]
}
}
def test_custom_fail_exception(self):
"""Test custom fences forced exception."""
with self.assertRaises(SuperFencesException):
self.check_markdown(
r'''
```test
test
```
''',
'',
True
)
def test_custom_fail_exception_blockquote(self):
"""Test custom fences forced exception in a block quote."""
with self.assertRaises(SuperFencesException):
self.check_markdown(
r'''
> ```test
> test
> ```
''',
'',
True
)
class TestSuperFencesCustomValidatorBroken(util.MdCase):
"""Test custom legacy validator that is broken."""
extension = ['pymdownx.superfences']
extension_configs = {
'pymdownx.superfences': {
'custom_fences': [
{
'name': 'test',
'class': 'test',
'format': custom_format,
'validator': custom_validator_exploder
}
]
}
}
def test_broken(self):
"""Test broken fence."""
self.check_markdown(
'''
```test
doesn't matter
```
''',
'''
''',
True
)
def test_broken_brace(self):
"""Test broken fence."""
self.check_markdown(
'''
```{.test}
doesn't matter
```
''',
'''
''',
True
)
class TestHighlightRelaxedHeaders(util.MdCase):
"""Test relaxed header cases."""
extension = ['pymdownx.highlight', 'pymdownx.superfences', 'attr_list']
extension_configs = {
'pymdownx.superfences': {
'relaxed_headers': True,
'custom_fences': [
{
'name': 'test',
'class': 'test',
'format': custom_format,
'validator': custom_validator_except
},
{
'name': 'test2',
'class': 'test',
'format': custom_format,
'validator': custom_validator_exploder
}
]
}
}
def test_custom_fail_exception(self):
"""Test custom fences forced exception."""
with self.assertRaises(SuperFencesException):
self.check_markdown(
r'''
```test [1]
test
```
''',
'',
True
)
def test_custom_fail_exception_relaxed(self):
"""Test custom fences relaxed forced exception."""
self.check_markdown(
r'''
```test2 [1]
test
```
''',
'''
''',
True
)
def test_bad_lang(self):
"""Test bad language."""
self.check_markdown(
r'''
```bad
test
```
''',
'''
''',
True
)
def test_bad_option(self):
"""Test bad options."""
self.check_markdown(
r'''
```pycon bad="My title"
>>> import test
```
''',
r'''
''', # noqa: E501
True
)
def test_bad_attribute(self):
"""Test bad attribute."""
self.check_markdown(
r'''
```pycon {.class !!!}
>>> import test
```
''',
r'''
''', # noqa: E501
True
)
def test_bad_attribute_full(self):
"""Test bad attribute full."""
self.check_markdown(
r'''
```{.pycon .class !!!}
>>> import test
```
''',
r'''
''', # noqa: E501
True
)
def test_bad_header(self):
"""Test bad header."""
self.check_markdown(
r'''
```pycon [nonsense]
>>> import test
```
''',
r'''
''', # noqa: E501
True
)
def test_nonsense(self):
"""Test only nonsense."""
self.check_markdown(
r'''
```[nonsense]
>>> import test
```
''',
r'''
''',
True
)