Esempio n. 1
0
 def __init__(self, **kwargs):
     self.pot_blacklist = {}
     self.strings = {}
     self.pot = ''
     Renderer.__init__(self, **kwargs)
     self.cmd = ''
     if self.options.get('pot'):
         self.cmd = 'pot'
     elif self.options.get('lang_md'):
         self.cmd = 'lang-md'
Esempio n. 2
0
 def __init__(self, **kwargs):
   self.pot_blacklist = {}
   self.strings = {}
   self.pot = ''
   Renderer.__init__(self, **kwargs)
   self.cmd = ''
   if self.options.get('pot'):
     self.cmd = 'pot'
   elif self.options.get('lang_md'):
     self.cmd = 'lang-md'
Esempio n. 3
0
def parse(text, post=None):
    """
    Parses markdown into html.
    Expands certain patterns into HTML.
    """
    # Resolve the root if exists.
    root = post.parent.root if (post and post.parent) else None
    inline = BiostarInlineLexer(renderer=Renderer(), root=root)
    inline.enable_post_link()
    inline.enable_mention_link()
    inline.enable_anchor_link()
    inline.enable_anchor_link()
    inline.enable_user_link()

    inline.enable_youtube_link1()
    inline.enable_youtube_link2()
    inline.enable_youtube_link3()
    inline.enable_ftp_link()
    inline.enable_twitter_link()

    markdown = mistune.Markdown(escape=True, hard_wrap=True, inline=inline)

    html = markdown(text)

    return html
Esempio n. 4
0
DISCOURSE_API_KEY = os.getenv("DISCOURSE_API_KEY")
DISCOURSE_API_USERNAME = os.getenv("DISCOURSE_API_USERNAME")

session = requests.get_session()
discourse_api = DiscourseAPI(
    base_url="https://discourse.juju.is/",
    session=session,
    api_key=DISCOURSE_API_KEY,
    api_username=DISCOURSE_API_USERNAME,
)

_yaml = YAML(typ="rt")
_yaml_safe = YAML(typ="safe")

md_parser = Markdown(renderer=Renderer())


def get_yaml_loader(typ="safe"):
    if typ == "safe":
        return _yaml_safe
    return _yaml


def split_filters(filters):
    filter_params = {}

    for charm_filter in filters:
        if charm_filter not in filter_params:
            filter_params[charm_filter] = []
Esempio n. 5
0
        "strikethrough",
        "text",
    ]

    def output_url(self, m):
        output = []
        output.append(m.group(1) or "")

        # Allow symbols < and > inside the URL
        link = m.group(2).replace("&lt;", "<").replace("&gt;", ">")

        if self._in_link:
            output.append(self.renderer.text(link))
        else:
            output.append(self.renderer.autolink(link, False))

        output.append(m.group(3) or "")
        return "".join(output)


renderer = Renderer()
parser = Markdown(
    renderer=renderer,
    block=DescriptionBlock(),
    inline=DescriptionInline(renderer=renderer),
)


def parse_markdown_description(content):
    return parser(content)
Esempio n. 6
0
def marktohtml(marktext):
    renderer = Renderer(escape=False, parse_block_html=True)
    markdown = Markdown(renderer=renderer)
    return BeautifulSoup(markdown(marktext), "html.parser")
 def block_code(self, code, lang=None, tag=None):
     if lang == "yaml":
         yaml_code = yaml.load(code)
         self.yaml_content.append(yaml_code)
     return Renderer.block_code(self, code, lang)
 def __init__(self, *args, **kwargs):
     self.yaml_content = []
     Renderer.__init__(self, *args, **kwargs)
Esempio n. 9
0
 def __init__(self, rules=None, **kwargs):
     super(RawInlineLexer, self).__init__(Renderer(), rules=rules, **kwargs)
Esempio n. 10
0
 def image(self, src, title, text):
   src = WEBUI_Renderer.replace_start(src, 'icons/', 'static/icons/')
   src = WEBUI_Renderer.replace_start(src, '../icons/', 'static/icons/')
   return Renderer.image(self, src, title, text)
Esempio n. 11
0
# -*- coding: utf-8 -*-

import re

from mistune import Renderer, Markdown, InlineGrammar, InlineLexer


class TdwInlineLexer(InlineLexer):
    def __init__(self, renderer):
        super(TdwInlineLexer, self).__init__(renderer)

        # insert fragment searching: [Fragment text #id]
        self.rules.fragment = re.compile(r'\[(.+?)\s#([a-zA-Z0-9]+?)\]')
        self.default_rules.insert(0, 'fragment')

    def output_fragment(self, m):
        text = m.group(1)
        id = m.group(2)
        return '<span id="{}" class="fragment">{}</span>'.format(id, text)


renderer = Renderer(escape=True, use_xhtml=True)
inline = TdwInlineLexer(renderer)
markdown = Markdown(renderer=renderer, inline=inline)
Esempio n. 12
0
 def block_code(self, code, lang=None):
     if lang == "yaml":
         self.yaml_content.write(code + "\n")
     return Renderer.block_code(self, code, lang)
Esempio n. 13
0
 def __init__(self, *args, **kwargs):
     self.yaml_content = StringIO()
     Renderer.__init__(self, *args, **kwargs)
Esempio n. 14
0
 def image(self, src, title, text):
     src = WEBUI_Renderer.replace_start(src, 'icons/', 'static/icons/')
     src = WEBUI_Renderer.replace_start(src, '../icons/', 'static/icons/')
     return Renderer.image(self, src, title, text)