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

Shortcodes #2193

Merged
merged 20 commits into from Dec 23, 2015
Merged

Shortcodes #2193

merged 20 commits into from Dec 23, 2015

Conversation

@ralsina
Copy link
Member

@ralsina ralsina commented Dec 23, 2015

Implement hugo-style shortcodes to help markups reach feature-parity with RST.

ralsina added 3 commits Dec 23, 2015
* 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
Copy link
Member

@Kwpolska Kwpolska Dec 23, 2015

y u no regex

@gour gour mentioned this pull request Dec 23, 2015
11 tasks
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.
Copy link
Member

@Kwpolska Kwpolska Dec 23, 2015

This is overkill IMO. Mind me replacing with a really simple Python parser?

Copy link
Member Author

@ralsina ralsina Dec 23, 2015

I would not mind, but after this branch is merged?


{{% foo %}} # No arguments
{{% foo bar %}} # One argument, containing "bar"
{{% foo bar baz=bat %}} # Two arguments, one containing "bar", one called "baz" containing "bat"
Copy link
Member

@Kwpolska Kwpolska Dec 23, 2015

could use a note about "quotes" being accepted

@ralsina ralsina changed the title Shortcodes (WIP) Shortcodes Dec 23, 2015
@ralsina ralsina changed the title Shortcodes Shortcodes [WIP] Dec 23, 2015
ralsina and others added 4 commits Dec 23, 2015
@ralsina
Copy link
Member Author

@ralsina ralsina commented Dec 23, 2015

What do you say @Kwpolska ? Merge?

@ralsina ralsina changed the title Shortcodes [WIP] Shortcodes Dec 23, 2015
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
@Kwpolska
Copy link
Member

@Kwpolska Kwpolska commented Dec 23, 2015

I would merge it, but I think that data should be a guaranteed argument (to make things easier for devs) — am I thinking right?

@ralsina
Copy link
Member Author

@ralsina ralsina commented Dec 23, 2015

Why not? Done in the next revison.

Kwpolska added 2 commits Dec 23, 2015
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
@Kwpolska
Copy link
Member

@Kwpolska Kwpolska commented Dec 23, 2015

Merge if the newest commit passes tests.

Also, here’s a reason to drop HTMLParser:

{{% test "hello world" %}}
→ ('"hello', 'world"')

(I’ll send a PR for my parser after this gets merged)

@ralsina
Copy link
Member Author

@ralsina ralsina commented Dec 23, 2015

Well, AFAIK that's not valid "html-like", is it? But sure, looking forward to the parser :-)

ralsina added a commit that referenced this issue Dec 23, 2015
@ralsina ralsina merged commit 19cd8dd into master Dec 23, 2015
4 checks passed
@ralsina ralsina deleted the shortcodes branch Dec 23, 2015
@felixfontein
Copy link
Contributor

@felixfontein felixfontein commented Dec 24, 2015

Out of curiosity: how is {{% test "%}}" %}} handled?

@Kwpolska
Copy link
Member

@Kwpolska Kwpolska commented Dec 24, 2015

nikola.shortcodes.apply_shortcodes('hello {{% test "%}}" %}} world', {'test': lambda a, **kw: ':' + a + ':'}, None)
'hello ::" %}} world'

@felixfontein
Copy link
Contributor

@felixfontein felixfontein commented Dec 26, 2015

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?

@Kwpolska
Copy link
Member

@Kwpolska Kwpolska commented Dec 27, 2015

Please write a better parser then.

@felixfontein
Copy link
Contributor

@felixfontein felixfontein commented Dec 27, 2015

It has to be a combined parser for the regex part and the argument splitting, then. I'll work on that later.

@felixfontein
Copy link
Contributor

@felixfontein felixfontein commented Dec 27, 2015

There are some more problems with the existing parsers:

from nikola import shortcodes

#print(shortcodes.apply_shortcodes('==> {{% <==', {}))
#print(shortcodes.apply_shortcodes('==> {{% a %%} <==', {}))
#print(shortcodes.apply_shortcodes('==> {{% a %}} {{% /a %%} <==', {}))
#print(shortcodes.apply_shortcodes('==> {{% test %}} {{% bla %}} {{% /bla %}} {{% /test %%} <==', {}))
#print(shortcodes.apply_shortcodes('==> {{% test %}} {{% bla %}} {{% /bla %}} {{% /bla %%} <==', {}))

Uncomment any of the lines to get an infinite loop.

@felixfontein
Copy link
Contributor

@felixfontein felixfontein commented Dec 28, 2015

See #2200 for a new parser.

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

Successfully merging this pull request may close these issues.

None yet

3 participants