Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: getnikola/plugins
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3fd11c053b29^
Choose a base ref
...
head repository: getnikola/plugins
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2beca1d45519
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Apr 22, 2015

  1. new mediawiki plugin

    ralsina committed Apr 22, 2015
    Copy the full SHA
    3fd11c0 View commit details
  2. blah

    ralsina committed Apr 22, 2015
    Copy the full SHA
    2beca1d View commit details
Showing with 112 additions and 0 deletions.
  1. +2 −0 v7/mediawiki/README.md
  2. +7 −0 v7/mediawiki/conf.py.sample
  3. +9 −0 v7/mediawiki/mediawiki.plugin
  4. +92 −0 v7/mediawiki/mediawiki.py
  5. +2 −0 v7/mediawiki/requirements.txt
2 changes: 2 additions & 0 deletions v7/mediawiki/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Compiler plugin to support Wikimedia markup using [smc.mw](https://github.com/lambdafu/smc.mw/).

7 changes: 7 additions & 0 deletions v7/mediawiki/conf.py.sample
Original file line number Diff line number Diff line change
@@ -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"),)
9 changes: 9 additions & 0 deletions v7/mediawiki/mediawiki.plugin
Original file line number Diff line number Diff line change
@@ -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
92 changes: 92 additions & 0 deletions v7/mediawiki/mediawiki.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# -*- coding: utf-8 -*-

# Copyright © 2012-2014 Roberto Alsina and others.

# 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)
2 changes: 2 additions & 0 deletions v7/mediawiki/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
https://github.com/lambdafu/smc.mw/archive/master.zip
grako