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

This comment has been minimized.

@Kwpolska

Kwpolska Dec 23, 2015
Member

y u no regex

@gour gour mentioned this pull request Dec 23, 2015
8 of 11 tasks complete
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.

This comment has been minimized.

@Kwpolska

Kwpolska Dec 23, 2015
Member

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

This comment has been minimized.

@ralsina

ralsina Dec 23, 2015
Author Member

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"

This comment has been minimized.

@Kwpolska

Kwpolska Dec 23, 2015
Member

could use a note about "quotes" being accepted

{{% foo %}}Some text{{% /foo %}} # one argument called "data" containing "Some text"

So, if you are creating a plugin that generates markup, it may be a good idea to register it as a shortcode
in adition of a restructured text directive or markdown extension, thus making it available to all markups.

This comment has been minimized.

@Kwpolska

Kwpolska Dec 23, 2015
Member

in addition to a reStructuredText directive or Markdown extension, thus making it available to all input formats.

Shortcodes
==========

Some (hopefully all) markup compilers support shortcodes in these forms::

This comment has been minimized.

@Kwpolska

Kwpolska Dec 23, 2015
Member

Do we support it in HTML and ipynb? (ipynb might need some extra help, I’d rather not run this over Python cells/a JSON file)

This comment has been minimized.

@ralsina

ralsina Dec 23, 2015
Author Member

So far, only markdown.

This comment has been minimized.

@ralsina

ralsina Dec 23, 2015
Author Member

About ipynb ... this runs over everything pretty dumbly. In fact, now that you mention it, adding it to the rest compiler would break the docs, now that they mention shortcodes ;-)

This comment has been minimized.

@Kwpolska

Kwpolska Dec 23, 2015
Member

Create a _raw shortcode.

Input:

{{% _raw foo bar baz=bat %}}

Output:

{{% foo bar baz=bat %}}

This comment has been minimized.

@ralsina

ralsina Dec 23, 2015
Author Member

And I can add that one when I add a bunch of builtin template-based shortcodes in the next branch. GOOD.

@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
[ci skip]
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
@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 pull request Dec 23, 2015
Shortcodes
@ralsina ralsina merged commit 19cd8dd into master Dec 23, 2015
4 checks passed
4 checks passed
continuous-integration/appveyor/branch AppVeyor build succeeded
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.