CrossNox / m2r2

Markdown to reStructuredText converter
https://crossnox.github.io/m2r2
MIT License
107 stars 26 forks source link

Unknown directive type "mdinclude" #15

Open cglacet opened 3 years ago

cglacet commented 3 years ago

Version 0.2.5

I'm not too sure what I've done, this package used to work but now I get this error:

WARNING: Unknown directive type "mdinclude".

I can still convert files without any problem, but when I run sphinx (3.3.1) I get this error when using the mdinclude directive.

Details about my install

$ poetry show m2r2
name         : m2r2
version      : 0.2.5
description  : Markdown and reStructuredText in a single file.

dependencies
 - docutils *
 - mistune *

I tried removing and adding m2r2 back but nothing seems to work.

How does m2r2 normally registers this new directive?

cglacet commented 3 years ago

I managed to solve the issue by downgrading sphinx to 3.2.1:

[tool.poetry.dev-dependencies]
-sphinx = "^3.3.1"
+sphinx = "3.2.1"

The error also appears on sphinx 3.3.0.

NumesSanguis commented 3 years ago

Related to?: https://github.com/CrossNox/m2r2/issues/13

cglacet commented 3 years ago

No, it's a different problem, I had #13 too but I solved it by adding this to my conf.py:


"""Patching m2r2"""
import m2r2

current_m2r2_setup = m2r2.setup

def patched_m2r2_setup(app):
    try:
        return current_m2r2_setup(app)
    except (AttributeError):
        app.add_source_suffix(".md", "markdown")
        app.add_source_parser(m2r2.M2RParser)
    return dict(
        version=m2r2.__version__,
        parallel_read_safe=True,
        parallel_write_safe=True,
    )

m2r2.setup = patched_m2r2_setup

Also note that #13 has been patched, but the PR hasn't been merged yet. This mimics the patch that will (hopefully) been soon merged.

chrizzFTD commented 3 years ago

Hi @cglacet!

I was having similar errors from https://github.com/CrossNox/m2r2/issues/13, then I saw this issue and I took your patch from conf.py and added it to my project here: https://github.com/thegrill/grill/pull/7/commits/2fc61deae156351f0444af3fc1747be0e63ee153.

I noticed the missing mdinclude directive was fixed by adding the app.add_directive("mdinclude", m2r2.MdInclude) call after catching the AttributeError: https://github.com/thegrill/grill/pull/7/commits/79cbb7b9331796d30a9a56b7fe859e2438f1c2ff, like so:

    ...
    except (AttributeError):
        app.add_source_suffix(".md", "markdown")
        app.add_source_parser(m2r2.M2RParser)
+       app.add_directive("mdinclude", m2r2.MdInclude)
    return dict(
    ...

With that, my docs built properly again.

Since it was fixed directly on the patch, I feel this is related to https://github.com/CrossNox/m2r2/issues/13

I hope this helps!

CrossNox commented 3 years ago

IIUC, this can be closed, since the fix for #13 has already been merged, right?