Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mdinclude accepts / as reference to doc root #8

Open
ITler opened this issue Aug 12, 2020 · 1 comment
Open

mdinclude accepts / as reference to doc root #8

ITler opened this issue Aug 12, 2020 · 1 comment

Comments

@ITler
Copy link

ITler commented Aug 12, 2020

Really thank you for providing this library.
I hope this will overcome my usage issues with recommonmark also in the long run.

It would be helpful, if .. mdinclude:: /_static/whatever.md would always starts looking on the doc root level (where sphinx-build command is executed) when reference starts with /.
This would match the behaviour of sphinx's ..include: directive.

@ravindk89
Copy link

Does anyone have a workaround for this? I can't really make good use of this plugin otherwise.

It seems like passing in something like .. mdinclude:: /source/imports/file.md results in the directive looking at the /source from the fs root instead of the project root.

I don't actually see anything different in how mdinclude handles finding the file compared to Include :

docutils/parsers/rst/directives/misc.py L56-66

if not self.state.document.settings.file_insertion_enabled:
   raise self.warning('"%s" directive disabled.' % self.name)

source = self.state_machine.input_lines.source(
   self.lineno - self.state_machine.input_offset - 1)

source_dir = os.path.dirname(os.path.abspath(source))

path = directives.path(self.arguments[0])

if path.startswith('<') and path.endswith('>'):
   path = os.path.join(self.standard_include_path, path[1:-1])

path = os.path.normpath(os.path.join(source_dir, path))

path = utils.relative_path(None, path)

path = nodes.reprunicode(path)

vs

if not self.state.document.settings.file_insertion_enabled:
   raise self.warning('"%s" directive disabled.' % self.name)

source = self.state_machine.input_lines.source(
   self.lineno - self.state_machine.input_offset - 1
)

source_dir = os.path.dirname(os.path.abspath(source))

path = rst.directives.path(self.arguments[0])

path = os.path.normpath(os.path.join(source_dir, path))

path = utils.relative_path(None, path)

path = nodes.reprunicode(path)

The code looks the same, but both directives behave completely differently. I don't know nearly enough about Sphinx API to dig much further than this :/ cc @CrossNox - I'd take a look at this but I'm not really sure what would be causing this behavior given how similar the code is between Include and MdInclude.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants