python-markdown-oembed/mdx_oembed/inlinepatterns.py

24 lines
661 B
Python
Raw Normal View History

2012-11-13 21:28:10 +00:00
# -*- 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