Skip to content

Commit 82e03af

Browse files
committedAug 2, 2016
Add ShortcodePlugin class
1 parent 141ea96 commit 82e03af

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed
 

‎docs/extending.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ So, if you are creating a plugin that generates markup, it may be a good idea
577577
to register it as a shortcode in addition of to restructured text directive or
578578
markdown extension, thus making it available to all markup formats.
579579

580-
To implement your own shortcodes from a plugin, you can call
580+
To implement your own shortcodes from a plugin, you can create a plugin inheriting ``ShortcodePlugin`` and call
581581
``Nikola.register_shortcode(name, func)`` with the following arguments:
582582

583583
``name``:

‎nikola/nikola.py

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
CompilerExtension,
6767
MarkdownExtension,
6868
RestExtension,
69+
ShortcodePlugin,
6970
Task,
7071
TaskMultiplier,
7172
TemplateSystem,
@@ -892,6 +893,7 @@ def init_plugins(self, commands_only=False, load_all=False):
892893
"CompilerExtension": CompilerExtension,
893894
"MarkdownExtension": MarkdownExtension,
894895
"RestExtension": RestExtension,
896+
"ShortcodePlugin": ShortcodePlugin,
895897
"SignalHandler": SignalHandler,
896898
"ConfigPlugin": ConfigPlugin,
897899
"PostScanner": PostScanner,
@@ -990,6 +992,9 @@ def plugin_position_in_places(plugin):
990992
self.plugin_manager.activatePluginByName(plugin_info.name)
991993
plugin_info.plugin_object.set_site(self)
992994

995+
# Activate shortcode plugins
996+
self._activate_plugins_of_category("ShortcodePlugin")
997+
993998
# Load compiler plugins
994999
self.compilers = {}
9951000
self.inverse_compilers = {}

‎nikola/plugin_categories.py

+6
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,12 @@ class ConfigPlugin(BasePlugin):
344344
name = "dummy_config_plugin"
345345

346346

347+
class ShortcodePlugin(BasePlugin):
348+
"""A plugin that adds a shortcode."""
349+
350+
name = "dummy_shortcode_plugin"
351+
352+
347353
class Importer(Command):
348354
"""Basic structure for importing data into Nikola.
349355

0 commit comments

Comments
 (0)
Please sign in to comment.