def __init__ (self, md, config): """Initialize the Markdwon inline pattern processor""" ## Store the configuration dict self.config = config ## Initialize the parent class LinkPattern.__init__ (self, LINK_RE, md)
def __init__(self, md, config): """Initialize the Markdwon inline pattern processor""" ## Store the configuration dict self.config = config ## Initialize the parent class LinkPattern.__init__(self, LINK_RE, md)
def parse_link(matchobj): link = LinkPattern(MAGICLINKS_RE, self.markdown) href = link.sanitize_url(link.unescape(matchobj.group(0).strip())) if href: href = self.escape(href) return self.markdown.htmlStash.store('<a href="%(href)s">%(href)s</a>' % {'href': href}, safe=True) else: return matchobj.group(0)
def parse_link(matchobj): link = LinkPattern(MAGICLINKS_RE, self.markdown) href = link.sanitize_url(link.unescape(matchobj.group(0).strip())) if href: if is_inner(href): clean = clean_inner(href) return self.markdown.htmlStash.store('<a href="%s">%s</a>' % (clean, clean[1:]), safe=True) else: return self.markdown.htmlStash.store('<a href="%(href)s" rel="nofollow">%(href)s</a>' % {'href': href}, safe=True) else: return matchobj.group(0)
def parse_link(matchobj): link = LinkPattern(MAGICLINKS_RE, self.markdown) href = link.sanitize_url(link.unescape(matchobj.group(0).strip())) if href: if is_inner(href): clean = clean_inner(href) return self.markdown.htmlStash.store( '<a href="%s">%s</a>' % (clean, clean[1:]), safe=True) else: return self.markdown.htmlStash.store( '<a href="%(href)s" rel="nofollow">%(href)s</a>' % {'href': href}, safe=True) else: return matchobj.group(0)
def handleMatch (self, m): """Add the class attribute to the generated <a> element""" ## Build the <a> element using the parent class elm = LinkPattern.handleMatch (self, m) ## Return the <a> element return add_class (elm, self.config)
def extendMarkdown(self, md, md_globals): md.inlinePatterns["link"] = LinkPattern(SPACED_LINK_RE, md) md.inlinePatterns["reference"] = ReferencePattern( SPACED_REFERENCE_RE, md) md.inlinePatterns["image_link"] = ImagePattern(SPACED_IMAGE_LINK_RE, md) md.inlinePatterns["image_reference"] = ImageReferencePattern( SPACED_IMAGE_REFERENCE_RE, md)
def parse_link(matchobj): matched_link = matchobj.group(0).strip() if matched_link[0] == '<': matched_link = matched_link[1:] if matched_link[-1] == '>': matched_link = matched_link[:-1] link = LinkPattern(MAGICLINKS_RE, self.markdown) href = link.sanitize_url(link.unescape(matched_link)) if href: if is_inner(href): clean = clean_inner(href) return self.markdown.htmlStash.store('<a href="%s">%s</a>' % (clean, clean[1:]), safe=True) else: clean = clean_outer(href) return self.markdown.htmlStash.store('<a href="%s" rel="nofollow">%s</a>' % (clean, href), safe=True) else: return matchobj.group(0)
def handleMatch(self, m): # get node node = LinkPattern.handleMatch(self, m) # get link href src = node.attrib.get('href') # if link is in assets process and update node with new url output_asset = self.asset_processor.asset_urlparse(src) if output_asset: node.attrib['href'] = output_asset return node
def handleMatch(self, m): """Add the class attribute to the generated <a> element""" ## Build the <a> element using the parent class elm = LinkPattern.handleMatch(self, m) ## Add the appropriate class attribute m = re.match('^https?://', elm.get('href')) elm.set( 'class', m and self.config['external-class'] or self.config['internal-class']) ## Return the <a> element return elm
def handleMatch (self, m): """Add the class attribute to the generated <a> element""" ## Build the <a> element using the parent class elm = LinkPattern.handleMatch (self, m) ## Add the appropriate class attribute m = re.match ('^https?://', elm.get ('href')) elm.set ('class', m and self.config ['external-class'] or self.config ['internal-class']) ## Return the <a> element return elm
def handleMatch(self, m): node = LinkPattern.handleMatch(self, m) # check 'src' to ensure it is local src = node.attrib.get('href') scheme, netloc, path, params, query, fragment = urlparse(src) if scheme or netloc: return node if path.endswith('.md'): path = path[:-3] path_parts = path.split('/') if path_parts[-1] == 'index': path_parts = path_parts[:-1] current_path = self.requested_path[:] for path_part in path_parts: if path_part == '.' or path_part == '..': path_parts = path_parts[1:] current_path = current_path[:-1] url = url_for('blog_index', path='/'.join(current_path + path_parts), _external=True, _anchor=fragment) node.set('href', url) return node
def __init__(self, asset_processor, pattern, markdown_instance=None): LinkPattern.__init__(self, pattern, markdown_instance) self.asset_processor = asset_processor
def handleMatch(self, m): node = LinkPattern.handleMatch(self, m) node.set('target', '_blank') return node
def __init__(self, pattern, md, target, item): LinkPattern.__init__(self, pattern, md) self.target = target self.item = item
def __init__(self, pattern, md, item, srcfile, faults): LinkPattern.__init__(self, pattern, md) self.item = item self.srcfile = srcfile self.faults = faults
def __init__(self, pattern, config): LinkPattern.__init__(self, pattern) self.config = config