Пример #1
0

def wiki_dir(config):
    return p.abspath(p.join(config['meta.root'], config.get('wiki-dir', 'wiki')))


def temp_dir(config):
    return p.abspath(p.join(config['meta.root'],
        config.get('temp-dir', config['hide-prefix'] + 'tmp')))


def template_dir(config):
    return p.abspath(p.join(config['meta.root'],
        config.get('template-dir', config['hide-prefix'] + 'templates')))


Config.register_default('hide-prefix', '.')
Config.register_default('use-default-static', True)
Config.register_default('cvs-exclude', True)
Config.register_func_default('html-dir', lambda cfg, key: html_dir(cfg))
Config.register_func_default('static-dir', lambda cfg, key: static_dir(cfg))
Config.register_func_default('wiki-dir', lambda cfg, key: wiki_dir(cfg))
Config.register_func_default('temp-dir', lambda cfg, key: temp_dir(cfg))
Config.register_func_default('template-dir', lambda cfg, key: template_dir(cfg))

Config.html_dir = property(html_dir)
Config.static_dir = property(static_dir)
Config.wiki_dir = property(wiki_dir)
Config.temp_dir = property(temp_dir)
Config.template_dir = property(template_dir)
Пример #2
0
# -*- coding: utf-8 -*-

import os.path as p

from phdoc.config import Config
import markdown
import phdoc.mdx_mathjax
import phdoc.mdx_fold

Config.register_default('markdown.extensions', ())
Config.register_func_default('markdown.extension-configs', lambda cfg, key: {})
Config.register_default('markdown.safe-mode', False)
Config.register_default('markdown.output-format', 'html5')
Config.register_default('document-extensions',
                        frozenset(['.md', '.mdown', '.markdown', '.wiki',
                                   '.text']))


class RelativeLinksTreeProcessor(markdown.treeprocessors.Treeprocessor):
    """A Markdown tree processor to relativize wiki links."""

    def __init__(self, curr_path='/'):
        self.curr_path = curr_path

    def make_relative(self, href):
        return make_relative(self.curr_path, href)

    def run(self, tree):
        links = tree.getiterator('a')
        for link in links:
            if link.attrib['href'].startswith('/'):