當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。