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
WordPress compiler plugin. #91
Conversation
Improved some spacing.
__all__ = ['CompileWordpress', 'WordPressPlugin'] | ||
|
||
|
||
class WordPressPlugin(IPlugin): |
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.
Why not make this a PageCompiler? Look at https://github.com/getnikola/nikola/blob/master/nikola/plugins/compile/pandoc.py#L43 for an example.
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 a class which shortcode plugins for the WordPress compiler should derive from. This is not the class for the WordPress page compiler itself. The WordPress page compiler is CompileWordpress
and defined in wordpress.py
.
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.
In any case, inherit at least nikola.plugin_categories.BasePlugin or you will be missing stuff.
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.
Why? The plugin handling for .wpplugin
plugins (which inherit from WordPressPlugin
) is done completely by the WordPress page compiler plugin. Nikola won't see these plugins.
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.
Oh, it will. Nikola's plugin loader will find them, unless you put them in a different place? Then they will be loaded twice.
Also, there's no reason for the compiler to load plugins, just let Nikola load them and get them from self.site.plugin_manager. Saves you a chunk of code, too.
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.
How about a "plugin plugin" category? The base class for that category would have a field for the plugin name this plugin is for, and the Nikola main object would get a function which allows to retrieve all plugins for a given plugin.
I can add something like that to Nikola if you want. The problem is that this won't be part of Nikola anytime soon (7.6.0 was just released), and so the WordPress plugin won't be useable until a newer Nikola version is released -- and in particular, it won't be useable for almost all v7 versions.
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.
Re registering plugin categories from within plugins: that would be really cumbersome, since we have to specify the plugin categories before any plugin is loaded. Except of course if we load plugins twice, but I don't really like that idea.
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.
class CompilerExtension(BasePlugin):
compiler_name = ''
class RestExtension(CompilerExtension):
compiler_name = 'rest'
class MarkdownExtension(CompilerExtension)
compiler_name = 'markdown'
Your plugins would be CompilerExtensions with compiler_name = 'wordpress'
, and would filter for that.
We could make your plugin v8-only (and we really need to get our act together and land that release) to make compatibility easier.
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.
Yes, that's what I was thinking. Also very good idea to include RestExtension
and MarkdownExtension
into this scheme!
Apropos v8: is there a timeline when v8 should be done? For the earlytask branch, the main problem is that it is waiting for some features to appear in official doit before it an be merged.
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.
Well, it will take a while for v8 to become a thing, because there isn’t that much to change yet. However, I just implemented CompilerExtensions in getnikola/nikola@c65be6e. You could make your compiler v7.6.1+ and use them.
Review status: 0 of 10 files reviewed at latest revision, 5 unresolved discussions, all commit checks successful. v7/wordpress_compiler/README.md, line 12 [r1] (raw file):
v7/wordpress_compiler/wordpress/plugins/code.py, line 3 [r1] (raw file): v7/wordpress_compiler/wordpress/plugins/code.wpplugin, line 2 [r1] (raw file): Comments from the review on Reviewable.io |
Well, I patched it together, but I took some parts from other people -- like you ;-)
Isn't this always local to the |
I try to keep the names consistent, same name in the metadata plugin file, the plugin itself, task names, etc. You never know what someone is going to try in the future :-) |
Ok, let's merge this whenever you want, and let's revisit it in a few months. |
I'll add an remark for potential shortcode plugin authors that the plugin interface will be changed for v8, so they should be aware that their plugins have to be changed a bit. |
The new version now uses the |
I guess the tests will fail until Nikola 7.6.1 is released. |
from .wordpress import CompileWordpress | ||
|
||
|
||
__all__ = ['CompileWordpress', 'WordPressPlugin'] |
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.
- should be a tuple, not a list
- where is
WordPressPlugin
?
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.
Thanks! I moved WordPressPlugin
to plugin_interface
, otherwise yapsy would (at least for me) load that definition as the plugin and ignore the page compiler...
|
Ok, there's a big problem with the new |
import pygments.token | ||
|
||
|
||
class UnformattedLexer(pygments.lexer.RegexLexer): |
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.
Do you really need that? There is a text
lexer available.
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.
Must have missed that one.
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.
Done.
You could cheat and use |
Doesn't work for me, either, since I'm including the wordpress plugin via |
Hmm, that won't work either, since the first thing I need to do is |
Hack idea 2: use the plain CompilerExtension class and set |
And define |
You could write some functions (≠methods) and pass them to every extension in your compiler, when you register them. |
I'm now providing the modules. I'll do some more testing by porting my other plugins to this way... |
Seems to work this way. |
Please complete the checklist a few posts above. |
I now also adjusted the copyright lines (though I didn't do precisely the replacement you wanted to do). Is that ok? |
Yeah, just noticed that too :) |
Thanks! |
This plugin allows to compile WordPress posts (i.e. posts directly copied out of a WordPress blog, without any modifications).
It has support for shortcodes. By default, it only supports the [code] shortcode, but plugins for other shortcodes can be added via a plugin interface. See
wordpress/plugins/code.py
for an example.