mirror of
https://github.com/Hopiu/python-markdown-oembed.git
synced 2026-03-16 22:10:24 +00:00
Merge remote-tracking branch 'wenzil/master' into 0.2.0
This commit is contained in:
commit
7d5a0ef503
5 changed files with 35 additions and 30 deletions
|
|
@ -2,10 +2,8 @@
|
|||
from mdx_oembed.extension import OEmbedExtension
|
||||
|
||||
|
||||
VERSION = '0.1.4'
|
||||
VERSION = '0.1.9'
|
||||
|
||||
|
||||
def makeExtension(configs=None):
|
||||
if isinstance(configs, list):
|
||||
configs = dict(configs)
|
||||
return OEmbedExtension(configs=configs)
|
||||
def makeExtension(**kwargs):
|
||||
return OEmbedExtension(**kwargs)
|
||||
|
|
|
|||
|
|
@ -2,15 +2,20 @@
|
|||
import oembed
|
||||
|
||||
|
||||
ENDPOINTS = {
|
||||
'youtube': oembed.OEmbedEndpoint('http://www.youtube.com/oembed', [
|
||||
DEFAULT_ENDPOINTS = [
|
||||
# Youtube
|
||||
oembed.OEmbedEndpoint('http://www.youtube.com/oembed', [
|
||||
'https?://(*.)?youtube.com/*',
|
||||
'https?://youtu.be/*',
|
||||
]),
|
||||
'flickr': oembed.OEmbedEndpoint('http://www.flickr.com/services/oembed/', [
|
||||
|
||||
# Flickr
|
||||
oembed.OEmbedEndpoint('http://www.flickr.com/services/oembed/', [
|
||||
'https?://*.flickr.com/*',
|
||||
]),
|
||||
'vimeo': oembed.OEmbedEndpoint('http://vimeo.com/api/oembed.json', [
|
||||
|
||||
# Vimeo
|
||||
oembed.OEmbedEndpoint('http://vimeo.com/api/oembed.json', [
|
||||
'https?://vimeo.com/*',
|
||||
]),
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,22 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from markdown import Extension
|
||||
import oembed
|
||||
from mdx_oembed.endpoints import ENDPOINTS
|
||||
from mdx_oembed.endpoints import DEFAULT_ENDPOINTS
|
||||
from mdx_oembed.inlinepatterns import OEmbedLinkPattern, OEMBED_LINK_RE
|
||||
|
||||
|
||||
AVAILABLE_ENDPOINTS = ENDPOINTS.keys()
|
||||
|
||||
|
||||
class OEmbedExtension(Extension):
|
||||
|
||||
config = {
|
||||
def __init__(self, **kwargs):
|
||||
self.config = {
|
||||
'allowed_endpoints': [
|
||||
AVAILABLE_ENDPOINTS,
|
||||
"A list of oEmbed endpoints to allow. Possible values are "
|
||||
"{}.".format(', '.join(AVAILABLE_ENDPOINTS)),
|
||||
DEFAULT_ENDPOINTS,
|
||||
"A list of oEmbed endpoints to allow. Defaults to "
|
||||
"endpoints.DEFAULT_ENDPOINTS"
|
||||
],
|
||||
}
|
||||
super(OEmbedExtension, self).__init__(**kwargs)
|
||||
|
||||
def extendMarkdown(self, md, md_globals):
|
||||
self.oembed_consumer = self.prepare_oembed_consumer()
|
||||
|
|
@ -25,10 +24,11 @@ class OEmbedExtension(Extension):
|
|||
md.inlinePatterns.add('oembed_link', link_pattern, '<image_link')
|
||||
|
||||
def prepare_oembed_consumer(self):
|
||||
allowed_endpoints = self.getConfig('allowed_endpoints',
|
||||
AVAILABLE_ENDPOINTS)
|
||||
allowed_endpoints = self.getConfig('allowed_endpoints', DEFAULT_ENDPOINTS)
|
||||
consumer = oembed.OEmbedConsumer()
|
||||
[consumer.addEndpoint(v)
|
||||
for k,v in ENDPOINTS.items()
|
||||
if k in allowed_endpoints]
|
||||
|
||||
if allowed_endpoints:
|
||||
for endpoint in allowed_endpoints:
|
||||
consumer.addEndpoint(endpoint)
|
||||
|
||||
return consumer
|
||||
|
|
|
|||
|
|
@ -21,7 +21,9 @@ class OEmbedLinkPattern(Pattern):
|
|||
html = self.get_oembed_html_for_match(match)
|
||||
if html is None:
|
||||
return None
|
||||
placeholder = self.markdown.htmlStash.store(html)
|
||||
else:
|
||||
html = "<figure class=\"oembed\">%s</figure>" % html
|
||||
placeholder = self.markdown.htmlStash.store(html, True)
|
||||
return placeholder
|
||||
|
||||
def get_oembed_html_for_match(self, match):
|
||||
|
|
|
|||
4
setup.py
4
setup.py
|
|
@ -15,7 +15,7 @@ except Exception:
|
|||
|
||||
setup(
|
||||
name='python-markdown-oembed',
|
||||
version='0.1.4',
|
||||
version='0.1.9',
|
||||
description="Markdown extension to allow media embedding using the oEmbed "
|
||||
"standard.",
|
||||
long_description=LONG_DESCRIPTION,
|
||||
|
|
@ -36,7 +36,7 @@ setup(
|
|||
],
|
||||
install_requires=[
|
||||
"python-oembed >= 0.2.1",
|
||||
"Markdown >= 2.2.0",
|
||||
"Markdown >= 2.6.1",
|
||||
],
|
||||
|
||||
test_suite='nose.collector',
|
||||
|
|
|
|||
Loading…
Reference in a new issue