本文整理汇总了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
示例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)
示例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>'
示例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)
示例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)
示例6: __init__
# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Renderer [as 别名]
def __init__(self, rules=None, **kwargs):
super(RawInlineLexer, self).__init__(Renderer(), rules=rules, **kwargs)
示例7: __init__
# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Renderer [as 别名]
def __init__(self, colors):
mistune.Renderer.__init__(self)
self.colors = colors
# Pagelayout
示例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)
示例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()