-
Notifications
You must be signed in to change notification settings - Fork 876
Support fenced_code optional lang trailer: '::' up to } or newline #977
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
Support fenced_code optional lang trailer: '::' up to } or newline #977
Conversation
This is to allow sphinx_markdown_parser AutoStructify to work. It expects lang tags like this to work: ``` automodule:: bin.onusim ```
First of all, #816 is a mostly complete (only missing docs) refactor of fenced code attributes. I would think any change here needs to be on that, rather than what is in master now. Ignoring the concerns raised below, that refactor might be a good excuse to add support for a new feature like this. That said, I do have a concern. This change allows syntax that the extension does nothing with. In other words, if a user were to use Python-Markdown directly and use a ReST directive, the directive would be interpreted as the lang of a code block for syntax highlighting. I assume Pygments would just see it as a unrecognized lang and ignore it, but we need to be sure it won't break things. If we are officially supporting the syntax, then perhaps we should check for it an not pass the content to Pygments. More importantly, it could be confusing to users that the ReST directive is ignored if we 'support them.' Users would reasonably expect the directive to do something. However, that it outside the scope of this extension. I haven't looked at how sphinx-markdown-parser handles this, but my assumption would be that they provide a separate fenced code extension which handles the directives and replaces the built-in extension. Seems to me that that would be a more sensible approach than to simply allow the directives to be passed in with no action taken on them. Whether that extension forks or subclasses the builtin extension, or is built from scratch is simply an implementation detail. However, the extension would be maintained as a third-party extension outside of Python-Markdown. In that case, there would be no reason to make any changes for the built-in extension. |
Thanks @waylan. I wasn't aware of #816. I share the concern of your second paragraph, and I never expected this PR to be merged as is. I believe that sphinx-markdown-parser simply assumes that the node's With the #816 change, would the following be valid? If so, maybe it would be best just to do something like this:
Alternatively just stick to something that will be parsed as a language (so no change on the markdown parser side), and then transform it on the sphinx-markdown-parser side, e.g.,
BTW, I think that at present, non-matching "language" values can cause the fenced blocks to get out of sync (I could provide an example), so I think that invalid language/class/keyword text needs to match the RE. Is this addressed by #816? |
Yes, that should work fine.
That should work as well.
This has always been the case and is intentional. If you provide bad input, then you get bad output. That is the clue that you did something wrong. |
If I'm understanding what Autostructify is doing under the hood, I expect that something else that would work with no changes being required to any upstream libs would be this:
Of course, the problem with any of these solutions is that they require a different syntax than what recommonmark requires. I expect that sphinx-markdown-parser's goal is to provide a consistent syntax regardless of which tool is being used under-the-hood. While spelunking around in sphinx-markdown-parser's code, something else I noticed is that they are not using Python-Markdown's code highlighting, but leaving that for docutils/Sphinx to handle (which seems reasonable to me). Therefore, the I'm going to close this as something which should be implemented by a third-party extension. As an aside, I've given a lot of thought over the years to how one might support ReST directives in Markdown and I find the Autostructify library interesting. However, it is not what I would have done. It simply uses ReST syntax wrapped up in code blocks. Instead a Markdownesque syntax would be more preferable. I don't know what that would look like exactly, but it is not Autostructify IMO. |
Your I agree with your comments. Note that I only came across all this a couple of weeks ago (I'm a user here) and I have no axe to grind. There appears to be some history, with AutoStructify coming originally from recommonmark and having been reimplemented in python-markdown-parser. There other areas where it manages to be more directly "markdowny", e.g., it makes a valiant attempt at defining the toc tree in pure markdown. |
No, that should be a HTML class attribute. The dot syntax is simply shorthand. However you can define it explicitly, which allows you to use quotes and preserve whitespace. Although, now that I think about it, maybe that doesn't work. It probably should. |
In thought the refactor didn't allow setting arbitrary HTML attributes, or an I misunderstanding something? I though it wasn't allowed due to conflict with preexisting setting syntax. |
@waylan, isn't
|
Sorry I forgot that |
Ah, I didn't realise this. I guess
In fact (and this is probably the last thing you want to hear!) is there any way that the fenced code block extension could depend on the attr_list extension for processing its attribute lists? |
This is to allow sphinx_markdown_parser's AutoStructify Embed reStructuredText option to work. Its second style expects
lang
tags like this to work as ReST directives:sphinx-markdown-parser assumes that the entire
automodule:: module-name
is parsed as thelang
tag (and I can only assume that this used to work). However it no longer works because the lang tag needs to match this RE fragment (which doesn't allow spaces or colons):The fix in this PR retains the above fragment but adds this optional fragment:
I realise that the fix in this PR is probably not acceptable, because it doesn't sufficiently consider the impact on other valid syntaxes such as the
hl_lines
option, and indeed it may go against the spirit of thelang
tag (although where is the acceptable lang syntax defined?). However I wanted to test the temperature to see whether people think that a fix at the markdown parser level might be acceptable.