当前位置: 首页>>代码示例>>Python>>正文


Python mistune.Renderer方法代码示例

本文整理汇总了Python中mistune.Renderer方法的典型用法代码示例。如果您正苦于以下问题:Python mistune.Renderer方法的具体用法?Python mistune.Renderer怎么用?Python mistune.Renderer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mistune的用法示例。


在下文中一共展示了mistune.Renderer方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Renderer [as 别名]
def __init__(self, uuid, fileName):
        mistune.Renderer.__init__(self, inlinestyles=True, linenos=False)
        self.__uuid = uuid
        self.__fileName = fileName 
开发者ID:SergeySatskiy,项目名称:codimension,代码行数:6,代码来源:md.py

示例2: image

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Renderer [as 别名]
def image(self, src, title, text):
        """Custom image handler"""
        if src and self.__fileName:
            if not os.path.isabs(src):
                newSrcPath = ''.join([os.path.dirname(self.__fileName),
                                      os.path.sep, src])
                src = os.path.normpath(newSrcPath)
        return mistune.Renderer.image(self, src, title, text) 
开发者ID:SergeySatskiy,项目名称:codimension,代码行数:10,代码来源:md.py

示例3: codespan

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Renderer [as 别名]
def codespan(self, text):
        """Custom code span renderer"""
        return '<u>' + mistune.Renderer.codespan(self, text) + '</u>' 
开发者ID:SergeySatskiy,项目名称:codimension,代码行数:5,代码来源:md.py

示例4: table

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Renderer [as 别名]
def table(self, header, body):
        """Custom table tag renderer"""
        replacement = '<table cellspacing="0" cellpadding="4"' + \
                      CODE_BLOCK_STYLE + '>'
        return mistune.Renderer.table(self, header, body).replace('<table>',
                                                                  replacement) 
开发者ID:SergeySatskiy,项目名称:codimension,代码行数:8,代码来源:md.py

示例5: __init__

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Renderer [as 别名]
def __init__(self, app):
        app.jinja_env.filters.setdefault('markdown', self.__call__)
        renderer = Renderer(escape=False, hard_wrap=True)
        self.markdown = mistune.Markdown(renderer=renderer) 
开发者ID:opendatateam,项目名称:udata,代码行数:6,代码来源:markdown.py

示例6: __init__

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Renderer [as 别名]
def __init__(self, rules=None, **kwargs):
        super(RawInlineLexer, self).__init__(Renderer(), rules=rules, **kwargs) 
开发者ID:lepture,项目名称:mistune-contrib,代码行数:4,代码来源:passthrough.py

示例7: __init__

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Renderer [as 别名]
def __init__(self, colors):
        mistune.Renderer.__init__(self)
        self.colors = colors

    # Pagelayout 
开发者ID:noqqe,项目名称:cmddocs,代码行数:7,代码来源:rendering.py

示例8: main

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Renderer [as 别名]
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("input", help="source file")
    parser.add_argument("output", help="output directory")
    parser.add_argument("-p", "--params", help="additional flags for PcbDraw")
    parser.add_argument("-b", "--board", help=".kicad_pcb file with a board")
    parser.add_argument("-i", "--img_name", help="image name template, should contain exactly one {{}}")
    parser.add_argument("-t", "--template", help="handlebars template for HTML output")
    parser.add_argument("-f", "--type", help="output type: md or html")
    parser.add_argument("-l", "--libs", help="libraries for PcbDraw")

    args = parser.parse_args()

    try:
        header, content = load_content(args.input)
    except IOError:
        print("Cannot open source file " + args.input)
        sys.exit(1)
    header = relativize_header_paths(header, os.path.dirname(args.input))
    args = merge_args(args, header)

    try:
        validate_args(args)
    except RuntimeError as e:
        print(e.message)
        sys.exit(1)

    if args["type"] == "html":
        renderer = Renderer(mistune.Renderer)
        outputfile = "index.html"
        try:
            template = read_template(args["template"])
        except IOError:
            print("Cannot open template file " + args["template"])
            sys.exit(1)
    else:
        renderer = Renderer(pcbdraw.mdrenderer.MdRenderer)
        outputfile = "index.md"
    content = parse_content(renderer, content)
    content = generate_images(content, args["board"], args["libs"],
        args["params"], args["img_name"], args["output"])
    if args["type"] == "html":
        output = generate_html(template, content)
    else:
        output = generate_markdown(content)

    with open(os.path.join(args["output"], outputfile), "wb") as f:
        f.write(output) 
开发者ID:yaqwsx,项目名称:PcbDraw,代码行数:50,代码来源:populate.py

示例9: markdown_convert

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Renderer [as 别名]
def markdown_convert(markdown_string) -> str:
    def _get_contents(text):
        try:
            contents = json.loads(text).get('message', '')
        except json.decoder.JSONDecodeError:
            contents = text
        except AttributeError:
            contents = text

        return contents

    class ButtonRenderer(mistune.Renderer):
        '''
        Syntax for MD buttons
            %%%{JSON.message}%%%
        For example:
            %%%%{"message": "Something here"}%%%%
        Output:
            Something here
        '''

        def paragraph(self, text):
            text = _get_contents(text)
            return f'<p>{text}</p>'

    class ButtonInlineLexer(mistune.InlineLexer):
        def enable_md_button(self):
            self.rules.md_button = re.compile(r'%%%(.*?)%%%')
            self.default_rules.insert(3, 'md_button')

        def placeholder(self):
            pass

        def output_md_button(self, m):
            text = m.group(1)
            return self.renderer.paragraph(text)

    renderer = ButtonRenderer()
    inline_lexer = ButtonInlineLexer(renderer)
    inline_lexer.enable_md_button()

    md = mistune.Markdown(renderer, inline=inline_lexer)
    return md(markdown_string).strip() 
开发者ID:demisto,项目名称:dockerfiles,代码行数:45,代码来源:md_helpers.py


注:本文中的mistune.Renderer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。