diff --git a/src/mdformat/_util.py b/src/mdformat/_util.py index 24a3934..d95a2c0 100644 --- a/src/mdformat/_util.py +++ b/src/mdformat/_util.py @@ -66,9 +66,10 @@ def is_md_equal( html = mdit.render(text) # Remove codeblocks because code formatter plugins do arbitrary changes. - for codeclass in codeformatters: + if codeformatters: + langs_re = "|".join(re.escape(lang) for lang in codeformatters) html = re.sub( - f'.*', + rf'.*', "", html, flags=re.DOTALL, diff --git a/tests/test_util.py b/tests/test_util.py new file mode 100644 index 0000000..e3bc89f --- /dev/null +++ b/tests/test_util.py @@ -0,0 +1,23 @@ +from mdformat._util import is_md_equal + + +def test_is_md_equal(): + md1 = """ +paragraph + +```js +console.log() +``` + +paragr +""" + md2 = """ +paragraph + +```js +bonsole.l()g +``` + +paragr""" + assert not is_md_equal(md1, md2) + assert is_md_equal(md1, md2, codeformatters=("js", "go"))