|
| 1 | +"""Test basic plugin creation functionality: |
| 2 | +that they can be added and are called correctly |
| 3 | +""" |
| 4 | +from markdown_it import MarkdownIt |
| 5 | + |
| 6 | + |
| 7 | +def inline_rule(state, silent): |
| 8 | + print("plugin called") |
| 9 | + |
| 10 | + |
| 11 | +def test_inline_after(capsys): |
| 12 | + def _plugin(_md): |
| 13 | + _md.inline.ruler.after("text", "new_rule", inline_rule) |
| 14 | + |
| 15 | + MarkdownIt().use(_plugin).parse("[") |
| 16 | + assert "plugin called" in capsys.readouterr().out |
| 17 | + |
| 18 | + |
| 19 | +def test_inline_before(capsys): |
| 20 | + def _plugin(_md): |
| 21 | + _md.inline.ruler.before("text", "new_rule", inline_rule) |
| 22 | + |
| 23 | + MarkdownIt().use(_plugin).parse("a") |
| 24 | + assert "plugin called" in capsys.readouterr().out |
| 25 | + |
| 26 | + |
| 27 | +def test_inline_at(capsys): |
| 28 | + def _plugin(_md): |
| 29 | + _md.inline.ruler.at("text", inline_rule) |
| 30 | + |
| 31 | + MarkdownIt().use(_plugin).parse("a") |
| 32 | + assert "plugin called" in capsys.readouterr().out |
| 33 | + |
| 34 | + |
| 35 | +def block_rule(state, startLine, endLine, silent): |
| 36 | + print("plugin called") |
| 37 | + |
| 38 | + |
| 39 | +def test_block_after(capsys): |
| 40 | + def _plugin(_md): |
| 41 | + _md.block.ruler.after("hr", "new_rule", block_rule) |
| 42 | + |
| 43 | + MarkdownIt().use(_plugin).parse("a") |
| 44 | + assert "plugin called" in capsys.readouterr().out |
| 45 | + |
| 46 | + |
| 47 | +def test_block_before(capsys): |
| 48 | + def _plugin(_md): |
| 49 | + _md.block.ruler.before("hr", "new_rule", block_rule) |
| 50 | + |
| 51 | + MarkdownIt().use(_plugin).parse("a") |
| 52 | + assert "plugin called" in capsys.readouterr().out |
| 53 | + |
| 54 | + |
| 55 | +def test_block_at(capsys): |
| 56 | + def _plugin(_md): |
| 57 | + _md.block.ruler.at("hr", block_rule) |
| 58 | + |
| 59 | + MarkdownIt().use(_plugin).parse("a") |
| 60 | + assert "plugin called" in capsys.readouterr().out |
| 61 | + |
| 62 | + |
| 63 | +def core_rule(state): |
| 64 | + print("plugin called") |
| 65 | + |
| 66 | + |
| 67 | +def test_core_after(capsys): |
| 68 | + def _plugin(_md): |
| 69 | + _md.core.ruler.after("normalize", "new_rule", core_rule) |
| 70 | + |
| 71 | + MarkdownIt().use(_plugin).parse("a") |
| 72 | + assert "plugin called" in capsys.readouterr().out |
| 73 | + |
| 74 | + |
| 75 | +def test_core_before(capsys): |
| 76 | + def _plugin(_md): |
| 77 | + _md.core.ruler.before("normalize", "new_rule", core_rule) |
| 78 | + |
| 79 | + MarkdownIt().use(_plugin).parse("a") |
| 80 | + assert "plugin called" in capsys.readouterr().out |
| 81 | + |
| 82 | + |
| 83 | +def test_core_at(capsys): |
| 84 | + def _plugin(_md): |
| 85 | + _md.core.ruler.at("normalize", core_rule) |
| 86 | + |
| 87 | + MarkdownIt().use(_plugin).parse("a") |
| 88 | + assert "plugin called" in capsys.readouterr().out |
0 commit comments