How to use the markdown.util function in Markdown

To help you get started, we’ve selected a few Markdown examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zestedesavoir / zds-site / zds / utils / templatetags / mkd_ext / urlize.py View on Github external
def handleMatch(self, m):
        url = m.group(2)
        
        if url.startswith('<'):
            url = url[1:-1]
            
        text = url
        
        if not url.split('://')[0] in ('http','https','ftp'):
            if '@' in url and not '/' in url:
                url = 'mailto:' + url
            else:
                url = 'http://' + url
    
        el = markdown.util.etree.Element("a")
        el.set('href', url)
        el.text = markdown.util.AtomicString(text)
        return el
github zestedesavoir / zds-site / zds / utils / templatetags / mkd_ext / smartImg.py View on Github external
while len(elemsToInspect) > 0:
            elem = elemsToInspect.pop()
            for nelem in elem:
                if nelem.tag in self.configs["PARENTS"]:
                    elemsToInspect.append(nelem)
                elif nelem.tag == "p" and len(list(nelem.itertext())) == 0 :
                    lelems = list(nelem.iter())

                    if     (len(lelems) == 1 or (len(lelems)==2 and lelems[0] is nelem)) \
                            and lelems[-1].tag == "img" \
                            and lelems[-1].attrib["alt"] != "" \
                            and not (lelems[-1].attrib["src"] in self.configs["IGNORING_IMG"]):
                        oldImg = lelems[-1]
                        nelem.remove(oldImg)
                        nFig = util.etree.Element("figure")
                        nFigCaption = util.etree.Element("figurecaption")
                        nFigCaption.text = oldImg.attrib["alt"]
                        oldImg.attrib["alt"]=""
                        nFig.append(oldImg)
                        nFig.append(nFigCaption)
                        nelem.append(nFig)

        return root
github bollwyvl / TangleDown / tangledown / apps / tangle / markdown / mdx_tangle.py View on Github external
def tk_span(cls_or_class, text=None, ignore=[], children=[], **kwargs):
    """
    Helper function. Creates the "normal" TangleKit spans.
    """
    kwargs = dict([('data-'+k, v) for k, v in kwargs.items() if v not in [None,""] and k not in ignore])
    obj = markdown.util.etree.Element('span')
    [obj.append(c) for c in children]
    if text:
        obj.text = text
    if isinstance(cls_or_class, str):
        obj.set('class', cls_or_class)
    else:
        obj.set('class', cls_or_class.__class__.__name__)
    [obj.set(k, v) for k, v in kwargs.items()]
    return obj
github zulip / zulip / zerver / lib / bugdown / __init__.py View on Github external
def handleMatch(self, m):
        ret = LinkPattern.handleMatch(self, m)
        if not isinstance(ret, basestring):
            ret.text = markdown.util.AtomicString(ret.text)
        return ret
github dragondjf / QMarkdowner / markdown / inlinepatterns.py View on Github external
def itertext(el):
            ' Reimplement Element.itertext for older python versions '
            tag = el.tag
            if not isinstance(tag, util.string_type) and tag is not None:
                return
            if el.text:
                yield el.text
            for e in el:
                for s in itertext(e):
                    yield s
                if e.tail:
                    yield e.tail
        def get_stash(m):
github dellsystem / wikinotes / mdx / mdx_subscript.py View on Github external
def handleMatch(self, m):
        subsc = m.group(3)

        text = subsc

        el = markdown.util.etree.Element("sub")
        el.text = markdown.util.AtomicString(text)
        return el
github facelessuser / pymdown-extensions / pymdownx / superfences.py View on Github external
)
RE_TABS = re.compile(r'((?:<p>.*?</p>\s*)+)', re.DOTALL)

TAB = (
    ''
    '<input id="__tabbed_%%(index)s_%%(tab_index)s" type="radio" name="__tabbed_%%(index)s">'
    '<label for="__tabbed_%%(index)s_%%(tab_index)s">%(title)s</label>'
    '<div class="%(content)s">%(code)s</div>'
    ''
)

NESTED_FENCE_END = r'%s[ \t]*$'

FENCED_BLOCK_RE = re.compile(
    r'^([\&gt; ]*)%s(%s)%s$' % (
        md_util.HTML_PLACEHOLDER[0],
        md_util.HTML_PLACEHOLDER[1:-1] % r'([0-9]+)',
        md_util.HTML_PLACEHOLDER[-1]
    )
)

MSG_TAB_DEPRECATION = """
The tab option in SuperFences has been deprecated in favor of the general purpose 'pymdownx.tabbed' extension.
While you can continue to use this feature for now, it will be removed in the future.
Also be mindful of the class changes, if you require old style classes, please enable the 'legacy_tab_classes' option.
"""


def _escape(txt):
    """Basic html escaping."""

    txt = txt.replace('&amp;', '&amp;')
github Python-Markdown / markdown / markdown / core.py View on Github external
'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3',
            'h4', 'h5', 'h6', 'header', 'hr', 'main', 'menu', 'nav', 'ol', 'p', 'pre',
            'section', 'table', 'ul',
            # Other elements which Markdown should not be mucking up the contents of.
            'canvas', 'dd', 'dt', 'group', 'iframe', 'li', 'math', 'noscript', 'output',
            'progress', 'script', 'style', 'tbody', 'td', 'th', 'thead', 'tr', 'video'
        ]

        self.registeredExtensions = []
        self.docType = ""
        self.stripTopLevelTags = True

        self.build_parser()

        self.references = {}
        self.htmlStash = util.HtmlStash()
        self.registerExtensions(extensions=kwargs.get('extensions', []),
                                configs=kwargs.get('extension_configs', {}))
        self.set_output_format(kwargs.get('output_format', 'xhtml'))
        self.reset()
github szaghi / MaTiSSe / src / main / python / matisse / mdx_mathjax.py View on Github external
def handleMatch(self, m):
    node = markdown.util.etree.Element('mathjax')
    node.text = markdown.util.AtomicString(m.group(2) + m.group(3) + m.group(2))
    return node
github dragondjf / QMarkdowner / markdown / treeprocessors.py View on Github external
stack = [tree]

        while stack:
            currElement = stack.pop()
            insertQueue = []
            for child in currElement.getchildren():
                if child.text and not isinstance(child.text, util.AtomicString):
                    text = child.text
                    child.text = None
                    lst = self.__processPlaceholders(self.__handleInline(
                                                    text), child)
                    stack += lst
                    insertQueue.append((child, lst))
                if child.tail:
                    tail = self.__handleInline(child.tail)
                    dumby = util.etree.Element('d')
                    tailResult = self.__processPlaceholders(tail, dumby)
                    if dumby.text:
                        child.tail = dumby.text
                    else:
                        child.tail = None
                    pos = currElement.getchildren().index(child) + 1
                    tailResult.reverse()
                    for newChild in tailResult:
                        currElement.insert(pos, newChild)
                if child.getchildren():
                    stack.append(child)

            for element, lst in insertQueue:
                if self.markdown.enable_attributes:
                    if element.text and isString(element.text):
                        element.text = \