Python mistune.Renderer() Examples
The following are 9
code examples of mistune.Renderer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
mistune
, or try the search function
.
Example #1
Source File: md.py From codimension with GNU General Public License v3.0 | 5 votes |
def __init__(self, uuid, fileName): mistune.Renderer.__init__(self, inlinestyles=True, linenos=False) self.__uuid = uuid self.__fileName = fileName
Example #2
Source File: md.py From codimension with GNU General Public License v3.0 | 5 votes |
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)
Example #3
Source File: md.py From codimension with GNU General Public License v3.0 | 5 votes |
def codespan(self, text): """Custom code span renderer""" return '<u>' + mistune.Renderer.codespan(self, text) + '</u>'
Example #4
Source File: md.py From codimension with GNU General Public License v3.0 | 5 votes |
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)
Example #5
Source File: markdown.py From udata with GNU Affero General Public License v3.0 | 5 votes |
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)
Example #6
Source File: passthrough.py From mistune-contrib with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, rules=None, **kwargs): super(RawInlineLexer, self).__init__(Renderer(), rules=rules, **kwargs)
Example #7
Source File: rendering.py From cmddocs with MIT License | 5 votes |
def __init__(self, colors): mistune.Renderer.__init__(self) self.colors = colors # Pagelayout
Example #8
Source File: populate.py From PcbDraw with MIT License | 4 votes |
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)
Example #9
Source File: md_helpers.py From dockerfiles with MIT License | 4 votes |
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()