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
Shortcodes #2193
Shortcodes #2193
Conversation
* Registered post-list as a shortcode * Added shortcode support to markdown compiler
[['foo', (['bar'], {'bat': 'baz', 'data': 'some data'}), 0, 43]] | ||
""" | ||
|
||
# FIXME: this is really space-intolerant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
y u no regex
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
|
||
class SCParser(HTMLParser): | ||
"""Parser for shortcode arguments.""" | ||
# Because shortcode attributes are HTML-like, we are abusing the HTML parser. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is overkill IMO. Mind me replacing with a really simple Python parser?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not mind, but after this branch is merged?
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
|
||
{{% foo %}} # No arguments | ||
{{% foo bar %}} # One argument, containing "bar" | ||
{{% foo bar baz=bat %}} # Two arguments, one containing "bar", one called "baz" containing "bat" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could use a note about "quotes" being accepted
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
What do you say @Kwpolska ? Merge? |
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
I would merge it, but I think that |
Why not? Done in the next revison. |
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
Merge if the newest commit passes tests. Also, here’s a reason to drop HTMLParser:
(I’ll send a PR for my parser after this gets merged) |
Well, AFAIK that's not valid "html-like", is it? But sure, looking forward to the parser :-) |
Out of curiosity: how is |
nikola.shortcodes.apply_shortcodes('hello {{% test "%}}" %}} world', {'test': lambda a, **kw: ':' + a + ':'}, None)
'hello ::" %}} world' |
Hmm, that's not what I would expect as an end-user (with programming experience). Is this really intended? If it is, shouldn't the parser complain about the not well-formed statement? |
Please write a better parser then. |
It has to be a combined parser for the regex part and the argument splitting, then. I'll work on that later. |
There are some more problems with the existing parsers:
Uncomment any of the lines to get an infinite loop. |
See #2200 for a new parser. |
Implement hugo-style shortcodes to help markups reach feature-parity with RST.