Skip to content
Permalink
Browse files

new mediawiki plugin

  • Loading branch information...
ralsina committed Apr 22, 2015
1 parent 9ad817f commit 34e88237ea4a619f2b0c2d5e0cc719d8c64dc06d
@@ -0,0 +1,2 @@
Compiler plugin to support Wikimedia markup using [smc.mw](https://github.com/lambdafu/smc.mw/).

@@ -0,0 +1,7 @@
# Add the mediawiki compiler to your COMPILERS dict.
# Make sure this doesn't conflict with the 'wiki' plugin
COMPILERS["mediawiki"] = ('.wiki',)

# Add mediawiki files to your POSTS, PAGES
POSTS = POSTS + (("posts/*.wiki", "posts", "post.tmpl"),)
PAGES = PAGES + (("stories/*.wiki", "posts", "post.tmpl"),)
@@ -0,0 +1,9 @@
[Core]
Name = mediawiki
Module = mediawiki

[Documentation]
Author = Roberto Alsina
Version = 0.2
Website = http://plugins.getnikola.com/#mediawiki
Description = Compile MediaWiki markup into HTML using smc.mw
@@ -0,0 +1,92 @@
# -*- coding: utf-8 -*-

# Copyright © 2012-2014 Roberto Alsina and others.

This comment has been minimized.

Copy link
@Kwpolska

Kwpolska Apr 22, 2015

Member

pretty sure it’s 2015 now

This comment has been minimized.

Copy link
@ralsina

ralsina Apr 22, 2015

Author Member

fixed, thx


# Permission is hereby granted, free of charge, to any
# person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the
# Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the
# Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice
# shall be included in all copies or substantial portions of
# the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

"""Implementation of compile_html based on asciidoc.
You will need, of course, to install asciidoc
"""

from __future__ import unicode_literals

import codecs
import io
import os
import re
import subprocess

from lxml import etree
try:
import smc.mw as mw
except:
mw = None

from nikola.plugin_categories import PageCompiler
from nikola.utils import makedirs, req_missing, write_metadata

try:
from collections import OrderedDict
except ImportError:
OrderedDict = dict # NOQA


class CompileMediaWiki(PageCompiler):
"""Compile mediawiki into HTML."""

name = "mediawiki"
demote_headers = True

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)
with io.open(dest, "w+", encoding="utf8") as out_file:
with io.open(source, "r", encoding="utf8") as in_file:
data = in_file.read()
if not is_two_file:
data = re.split('(\n\n|\r\n\r\n)', data, maxsplit=1)[-1]
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')
out_file.write(output)

def create_post(self, path, **kw):
content = kw.pop('content', None)
onefile = kw.pop('onefile', False)
# is_page is not used by create_post as of now.
kw.pop('is_page', False)

metadata = {}
metadata.update(self.default_metadata)
metadata.update(kw)
makedirs(os.path.dirname(path))
if not content.endswith('\n'):
content += '\n'
with io.open(path, "w+", encoding="utf8") as fd:
if onefile:
fd.write(write_metadata(metadata))
fd.write('\n\n')
fd.write(content)
@@ -0,0 +1,2 @@
https://github.com/lambdafu/smc.mw/archive/master.zip
grako

0 comments on commit 34e8823

Please sign in to comment.
You can’t perform that action at this time.