python-markdown-oembed/mdx_oembed/inlinepatterns.py
J. Tanner Netterville e4ec8a72fb initial commit
Functional beta
2012-11-13 15:28:10 -06:00

23 lines
661 B
Python

# -*- coding: utf-8 -*-
import logging
from markdown.inlinepatterns import Pattern
LOG = logging.getLogger(__name__)
OEMBED_LINK_RE = r'\!\[([^\]]*)\]\((https?://[^\)]*)' \
r'(?<!png)(?<!jpg)(?<!jpeg)(?<!gif)\)'
class OEmbedLinkPattern(Pattern):
def __init__(self, pattern, markdown_instance=None, oembed_consumer=None):
Pattern.__init__(self, pattern, markdown_instance)
self.consumer = oembed_consumer
def handleMatch(self, match):
url = match.group(3).strip()
response = self.consumer.embed(url)
placeholder = self.markdown.htmlStash.store(response['html'])
return placeholder