"""Test cases for Blocks (HTML)."""
from ... import util
class TestBlocksHTML(util.MdCase):
"""Test Blocks HTML cases."""
extension = ['pymdownx.blocks.html', 'md_in_html']
extension_configs = {
'pymdownx.blocks.html': {
'custom': [
{'tag': 'custom', 'mode': 'block'}
]
}
}
def test_raw_empty_block(self):
"""Test that raw empty blocks are handled properly."""
self.check_markdown(
R'''
/// html | pre
///
''',
R'''
''',
True
)
def test_bad_tag(self):
"""Test bad HTML tag."""
self.check_markdown(
R'''
/// html | 3tag
Some *content*
///
''',
R'''
/// html | 3tag
Some content
///
''',
True
)
def test_required_tag(self):
"""Test that tab is not processed if tag is omitted."""
self.check_markdown(
R'''
/// html
Some *content*
///
''',
r'''
/// html
Some content
///
''',
True
)
def test_html_block(self):
"""Test HTML block element."""
self.check_markdown(
R'''
/// html | div
Some *content*
And more `content`.
///
''',
r'''
Some content
And more content.
''',
True
)
def test_html_span(self):
"""Test HTML with span element."""
self.check_markdown(
R'''
/// html | span
Will be parsed as inline *content*
And more `content`.
///
''',
r'''
Will be parsed as inline content
And more content.
''',
True
)
def test_html_raw_element(self):
"""Test HTML raw element."""
self.check_markdown(
R'''
/// html | pre
Some *content*
And more `content`.
///
''',
r'''
Some *content*
And more `content`.
''',
True
)
def test_html_forced_raw_element(self):
"""Test HTML force raw element."""
self.check_markdown(
R'''
/// html | div
markdown: raw
Some *content*
And more `content`.
///
''',
r'''
Some *content*
And more `content`.
''',
True
)
def test_html_force_span(self):
"""Test HTML with force span element."""
self.check_markdown(
R'''
/// html | div
markdown: inline
Will be parsed as inline *content*
And more `content`.
///
''',
r'''
Will be parsed as inline content
And more content.
''',
True
)
def test_html_force_block(self):
"""Test HTML force block element."""
self.check_markdown(
R'''
/// html | span
markdown: block
Some *content*
And more `content`.
///
''',
r'''
Some content
And more content.
''',
True
)
def test_attributes(self):
"""Test attributes."""
self.check_markdown(
R'''
/// html | div.some.classes#an-id[name1 name2=value name3="string value"]
Some *content*
And more `content`.
///
''',
r'''
Some content
And more content.
''',
True
)
def test_bad_attributes(self):
"""Test no attributes."""
self.check_markdown(
R'''
/// html | div.+
content
///
''',
'''
/// html | div.+
content
///
''',
True
)
def test_multi_class(self):
"""Test multiple classes."""
self.check_markdown(
R'''
/// html | div.a.b[class=c]
content
///
''',
'''
''',
True
)
def test_multi_class2(self):
"""Test multiple classes."""
self.check_markdown(
R'''
/// html | div[class="a b"].c
content
///
''',
'''
''',
True
)
def test_inline_and_md_in_html(self):
"""Test inline format and HTML content."""
self.check_markdown(
R'''
/// html | div
markdown: inline
**content**
**content**
///
''',
'''
''',
True
)
def test_raw_and_md_in_html(self):
"""Test raw format and HTML content."""
self.check_markdown(
R'''
/// html | div
markdown: raw
**content**
this is raw **content**
///
''',
'''
<div>
**content**
</div>
this is <span>raw</span> **content**
''',
True
)
def test_html_and_html(self):
"""Test HTML mode format with HTML code."""
self.check_markdown(
R'''
/// html | div
markdown: html
**content**
this is raw **content**
///
''',
'''
**content**
this is
raw **content**
''',
True
)
def test_html_and_script(self):
"""Test inline format with script."""
self.check_markdown(
R'''
/// html | script
const el = document.querySelector('div');
el.innerHTML = 'test
///
''',
'''
''',
True
)
def test_custom(self):
"""Test custom block handling."""
self.check_markdown(
R'''
/// html | custom
- a
- b
///
''',
'''
''',
True
)
def test_custom_override(self):
"""Test custom block handling but mode is overridden."""
self.check_markdown(
R'''
/// html | custom
markdown: inline
- a
- b
///
''',
'''
- a
- b
''',
True
)