Esempio n. 1
0
def render_content(input_content, pre_article_id, next_article_id):
    input_content = input_content.replace('\r\n', '    \r\n')
    config = load_config(
        config_file=settings.BASE_DIR + '/blog_django/utils/mkdocs.yml',
        docs_dir=settings.BASE_DIR + '/blog_django/utils/docs',
    )
    site_navigation = nav.SiteNavigation(config['pages'],
                                         config['use_directory_urls'])
    for page in site_navigation.walk_pages():
        pass
    # Process the markdown text
    html_content, table_of_contents, meta = convert_markdown(
        markdown_source=input_content,
        config=config,
        site_navigation=site_navigation)

    html_content = html_content.replace('src="./', 'src="/')
    # 添加视频

    html_content = re.sub("(?P<video><p>@video_start@.*?@video_end@</p>)",
                          sub_video, html_content)

    context = get_global_context(site_navigation, config)
    context['base_url'] = '/static/mk_docs'
    context.update(
        get_page_context(page, html_content, table_of_contents, meta, config))
    context['page'].next_article_id = next_article_id
    context['page'].pre_article_id = pre_article_id

    return context
Esempio n. 2
0
def build_autodoc(page, config, site_navigation, env, dump_json, dirty=False):
    """
    Build autodoc, just like mkdocs.commands.build._build_page
    """
    input_path, output_path = get_complete_paths(config, page)
    try:
        input_content = io.open(input_path, 'r', encoding='utf-8').read()
    except IOError:
        log.error('file not found: %s', input_path)
        raise
    # render autodoc contents
    tmplstr = io.open(TEMPLATE_PATH).read()
    template = env.from_string(tmplstr)
    contents, titles = parse_selected(input_content)
    table_of_contents = create_toc(titles)
    html_content = template.render(contents=contents)
    # render page
    meta = None
    context = get_global_context(site_navigation, config)
    context.update(get_page_context(
        page, html_content, table_of_contents, meta, config
    ))
    template = env.get_template('base.html')
    output_content = template.render(context)
    utils.write_file(output_content.encode('utf-8'), output_path)
    return html_content, table_of_contents, None
Esempio n. 3
0
    def test_extra_context(self):

        # Same as the default schema, but don't verify the docs_dir exists.
        cfg = load_config({'site_name': "Site", 'extra': {'a': 1}})

        context = build.get_global_context(mock.Mock(), cfg)

        self.assertEqual(context['config']['extra']['a'], 1)
Esempio n. 4
0
    def test_extra_context(self):

        # Same as the default schema, but don't verify the docs_dir exists.
        cfg = load_config({
            'site_name': "Site",
            'extra': {
                'a': 1
            }
        })

        context = build.get_global_context(mock.Mock(), cfg)

        self.assertEqual(context['config']['extra']['a'], 1)