Source

moin-2.0 / MoinMoin / converter / text_in.py

# Copyright: 2008 MoinMoin:ThomasWaldmann
# Copyright: 2008 MoinMoin:BastianBlank
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
MoinMoin - Simple text input converter.

It just puts all text into a code block. It acts as a wildcard for text/* input.

We keep it at MIDDLE+2 prio in the registry, one after pygments converter, so
it is a fallback for the case we have no pygments or pygments has no support
for the input mimetype.
"""


from __future__ import absolute_import, division

from MoinMoin.util.tree import moin_page
from ._util import decode_data, normalize_split_text


class Converter(object):
    """
    Parse the raw text and create a document object
    that can be converted into output using Emitter.
    """
    @classmethod
    def _factory(cls, type_input, type_output, **kw):
        return cls()

    def __call__(self, data, contenttype=None, arguments=None):
        text = decode_data(data, contenttype)
        content = normalize_split_text(text)
        blockcode = moin_page.blockcode()
        for line in content:
            if len(blockcode):
                blockcode.append('\n')
            blockcode.append(line.expandtabs())
        body = moin_page.body(children=(blockcode, ))
        return moin_page.page(children=(body, ))


from . import default_registry
from MoinMoin.util.mime import Type, type_moin_document
# Assign a lower priority (= bigger number) so that it is tried after pygments_in
default_registry.register(Converter._factory, Type(type='text'), type_moin_document,
                          default_registry.PRIORITY_MIDDLE + 1)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.