-
Notifications
You must be signed in to change notification settings - Fork 862
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
Refactor fenced code attributes #816
Conversation
I resolved conflicts and added back in support for |
Got as far as I can with this without also modifying the codehilite extension, but that will be addressed in #822. This still needs documented. |
I'm using this for both fenced_code changes and codehilite changes. In other words this replaces/overrides #822. In the latest commit, I've made the changes to codehilite and updated the existing tests. However, I need to add more tests for the new behavior and document everything. |
I need to confirm if |
Seems the answer is in your own comment:
|
@facelessuser you make a good point. I was thinking that this should reflect the behavior we find in attr_lists, but if |
Yes, but only for backward compatibility. Originally, only the language was supported. At some point we added support for
Actually the list parser in the attr_list extension is imported and used by fenced-code as of this PR. However, it is only used for anything defined within the brackets. But as only a single-word language and However, it does differ from an attr_list in at least one way. As the Now, that behavior is dependent on syntax highlighting being enabled (codehilite extension is enabled). Without syntax highlighting, then the ID gets set on the However, an argument could be made that including random attributes in the output would allow JavaScript highlighting libs to make use of them. And we have Pandoc as another implementation which already supports that. We also have received bug reports from time to time from users who expected any attribute to work if/when the attr_list is enabled. I suppose we could change behavior based on that by only assigning id and class by default, but assigning all defined attributes if attr_list is also enabled (and code highlighting is off). |
I should point out that I considered hard-coding the options that Pygments accepts and passing only those to Pygments, but setting everything else as attributes in the HTML. However, there are a few issues with that:
Given the above, it makes more sense to simply pass everything blindly to Pygments. That way we automatically support any new pygments feature and still don't loose any functionality. of course, all of that is dependent on code highlighting being turned on. When it's off, we are open to considering other options. |
bb85631
to
86d547c
Compare
I just added support for
|
Can you elaborate on this a bit more? |
@facelessuser, as I explained above:
Perhaps I should clarify by pointing out that if brackets are being used, then everything must be defined within them. When I say "outside of brackets" I mean no brackets are being used at all. In other words, at this time the following are both valid:
In the future the first of those may be deprecated for consistency. In fact, I expect to not document that Finally, when I say it may be deprecated in the future, I am using "may" because I haven't decided for sure (perhaps "might" would have been a better word choice). If it does happen, it would first be 'pending deprecation' to give users an opportunity to update their documents. I'm not sure how that would work though, as we don't generally raise warnings while parsing a document. Warnings are generally only raised when initializing the Regardless, at this time I only intend to exclude mentioning the option in the docs. Any additional steps towards deprecation would be in a future release if they happen at all. |
I have finished updating the docs for fenced code. However, I just realized that I never expanded the codehilite config options. I only expanded the internal API which fenced_code calls. We need to expand the global options as well. |
Sorry for the delayed response, but re 2 above:
I wondered whether in this case it would be possible for Pygments to consume ("eat") the options that it understands, leaving the remainder to be available on the node, e.g., to be included as HTML attributes. This would seem to be quite a Pythonic approach (ref. Python's super() considered super!, which is referenced from the Python |
I have no idea how this would work. Our code has no knowledge of the arguments which Pygments accepts. We simply blindly pass all arguments on to Pygments. It just so happens that Pygments was designed so that it ignores arguments it doesn't understand (rather than raising an error). Regardless, as I put it in the docs:
In other words, I am placing the blame squarely on Pygments. And I have no interest in modifying Pygments output. If someone wants to do that, they can create their own third-party extension. If anyone is going to argue that the current behavior is inconsistent, then the only change I would consider is to only accept Pygments arguments and never accept anything else. |
Thanks. Makes sense. Re this:
I have not looked at Pygments but at least in theory it could return the arguments that it hasn't consumed. |
It does not. Perhaps a subclass could address that, but I'm not interested in going down that road. |
I think this is done and ready to go. |
e30dbb5
to
a09c0cc
Compare
Addresses #775. A work in progress.
The behavior as of the first commit is that a single string (with an optional dot as first character), defines the language of the block:
With dot:
Without dot:
If more than one thing is to be defined, you must use an attribute list (wrapped in curly brackets (
{}
). The first class (startswith a dot) is the language. All other classes are simply set on the renderedcode
element. The hash tag is the id and allkey=value
pairs are codehilite config values. You cannot define HTML attributes withkey=value
pairs.You can even set other config values that normally are global (per document) on a per block basis:
Although, actually that might not work (untested at this point) as we don't (yet) convert the string to a Boolean.
However, we have a backward incompatibility in that the existing tests include the following 2 cases where a key=value pair is used, but not in an attribute list:
and
With these changes, those will no longer be valid. In fact, the two tests are failing. This better matches the behavior of the PHP implementation we claim to copy. But it could break existing documents. We can't even claim it worked by accident as we explicitly tested for it.