Skip to content

Commit

Permalink
Shortcode support for mediawiki compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
ralsina committed Sep 24, 2016
1 parent 3067694 commit 651995c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion v7/mediawiki/mediawiki.plugin
Expand Up @@ -7,6 +7,6 @@ plugincategory = Compiler

[Documentation]
Author = Roberto Alsina
Version = 0.2
Version = 0.3
Website = http://plugins.getnikola.com/#mediawiki
Description = Compile MediaWiki markup into HTML using smc.mw
12 changes: 12 additions & 0 deletions v7/mediawiki/mediawiki.py
Expand Up @@ -61,6 +61,10 @@ def compile_html(self, source, dest, is_two_file=True):
makedirs(os.path.dirname(dest))
if mw is None:
req_missing(['smc.mw'], 'build this site (compile with MediaWiki)', python=True)
try:
post = self.site.post_per_input_file[source]
except KeyError:
post = None
with io.open(dest, "w+", encoding="utf8") as out_file:
with io.open(source, "r", encoding="utf8") as in_file:
data = in_file.read()
Expand All @@ -69,7 +73,15 @@ def compile_html(self, source, dest, is_two_file=True):
parser = mw.Parser(parseinfo=False, whitespace='', nameguard=False)
ast = parser.parse(data, 'document', semantics=mw.Semantics(parser))
output = etree.tostring(ast, encoding='utf8').decode('utf8')
output, shortcode_deps = self.site.apply_shortcodes(output, filename=source, with_dependencies=True, extra_context=dict(post=post))
out_file.write(output)
if post is None:
if shortcode_deps:
self.logger.error(
"Cannot save dependencies for post {0} due to unregistered source file name",
source)
else:
post._depfile[dest] += shortcode_deps

def create_post(self, path, **kw):
content = kw.pop('content', None)
Expand Down
2 changes: 1 addition & 1 deletion v7/mediawiki/requirements.txt
@@ -1,2 +1,2 @@
https://github.com/lambdafu/smc.mw/archive/master.zip
grako
grako==2.4.3

0 comments on commit 651995c

Please sign in to comment.