From c3a4466ecabcf1b2185fb9444dc59710fcb369c8 Mon Sep 17 00:00:00 2001 From: Sami Turcotte Date: Thu, 2 Apr 2015 03:47:33 -0400 Subject: [PATCH 01/11] Reconcile with Markdown 2.6 Updated the initialization of OEmbedExtension to be compatible with Markdown 2.6. See https://pythonhosted.org/Markdown/release-2.6.html --- mdx_oembed/__init__.py | 8 +++----- mdx_oembed/extension.py | 16 +++++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/mdx_oembed/__init__.py b/mdx_oembed/__init__.py index 97960a4..5b2871e 100644 --- a/mdx_oembed/__init__.py +++ b/mdx_oembed/__init__.py @@ -2,10 +2,8 @@ from mdx_oembed.extension import OEmbedExtension -VERSION = '0.1.4' +VERSION = '0.1.5' -def makeExtension(configs=None): - if isinstance(configs, list): - configs = dict(configs) - return OEmbedExtension(configs=configs) +def makeExtension(**kwargs): + return OEmbedExtension(**kwargs) diff --git a/mdx_oembed/extension.py b/mdx_oembed/extension.py index 84e84a6..9ad8ee1 100644 --- a/mdx_oembed/extension.py +++ b/mdx_oembed/extension.py @@ -10,13 +10,15 @@ AVAILABLE_ENDPOINTS = ENDPOINTS.keys() class OEmbedExtension(Extension): - config = { - 'allowed_endpoints': [ - AVAILABLE_ENDPOINTS, - "A list of oEmbed endpoints to allow. Possible values are " - "{}.".format(', '.join(AVAILABLE_ENDPOINTS)), - ], - } + def __init__(self, **kwargs): + self.config = { + 'allowed_endpoints': [ + AVAILABLE_ENDPOINTS, + "A list of oEmbed endpoints to allow. Possible values are " + "{}.".format(', '.join(AVAILABLE_ENDPOINTS)), + ], + } + super(OEmbedExtension, self).__init__(**kwargs) def extendMarkdown(self, md, md_globals): self.oembed_consumer = self.prepare_oembed_consumer() From 4a7f2a4d4664a0d06f0df3ab488abcddb2abfdec Mon Sep 17 00:00:00 2001 From: Sami Turcotte Date: Thu, 2 Apr 2015 03:48:18 -0400 Subject: [PATCH 02/11] Version bump --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 6c19af5..92a474b 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ except Exception: setup( name='python-markdown-oembed', - version='0.1.4', + version='0.1.5', 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.0", ], test_suite='nose.collector', From 3adab335ec503cb14bad71ac8e1c0ff68499bddf Mon Sep 17 00:00:00 2001 From: Sami Turcotte Date: Fri, 3 Apr 2015 01:22:11 -0400 Subject: [PATCH 03/11] Add support for python-markdown safe mode Mark the resulting OEmbed html tags as safe so they don't get stripped away in safe mode. --- mdx_oembed/inlinepatterns.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mdx_oembed/inlinepatterns.py b/mdx_oembed/inlinepatterns.py index b147d96..9f71fd3 100644 --- a/mdx_oembed/inlinepatterns.py +++ b/mdx_oembed/inlinepatterns.py @@ -21,7 +21,7 @@ class OEmbedLinkPattern(Pattern): html = self.get_oembed_html_for_match(match) if html is None: return None - placeholder = self.markdown.htmlStash.store(html) + placeholder = self.markdown.htmlStash.store(html, True) return placeholder def get_oembed_html_for_match(self, match): From 7f12354970bb939ee938be1ae76674736690f2bc Mon Sep 17 00:00:00 2001 From: Sami Turcotte Date: Fri, 3 Apr 2015 01:51:34 -0400 Subject: [PATCH 04/11] Version bump --- mdx_oembed/__init__.py | 2 +- setup.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mdx_oembed/__init__.py b/mdx_oembed/__init__.py index 5b2871e..33ae4dc 100644 --- a/mdx_oembed/__init__.py +++ b/mdx_oembed/__init__.py @@ -2,7 +2,7 @@ from mdx_oembed.extension import OEmbedExtension -VERSION = '0.1.5' +VERSION = '0.1.6' def makeExtension(**kwargs): diff --git a/setup.py b/setup.py index 92a474b..875f102 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ except Exception: setup( name='python-markdown-oembed', - version='0.1.5', + version='0.1.6', 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.6.0", + "Markdown >= 2.6.1", ], test_suite='nose.collector', From f3f09aae985ec2007940698607b1341c5dec40d5 Mon Sep 17 00:00:00 2001 From: Sami Turcotte Date: Sat, 4 Apr 2015 03:33:33 -0400 Subject: [PATCH 05/11] Wrap oEmbed html output in a div To keep a constant aspect ratio for the resulting iframe of an oEmbed request in a responsive website, the iframe needs a div wrapper. With this change, html results are wrapped in a "oembed" class div. --- mdx_oembed/inlinepatterns.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mdx_oembed/inlinepatterns.py b/mdx_oembed/inlinepatterns.py index 9f71fd3..1fbb09d 100644 --- a/mdx_oembed/inlinepatterns.py +++ b/mdx_oembed/inlinepatterns.py @@ -21,8 +21,10 @@ class OEmbedLinkPattern(Pattern): html = self.get_oembed_html_for_match(match) if html is None: return None - placeholder = self.markdown.htmlStash.store(html, True) - return placeholder + else: + html = "
%s
" % html + placeholder = self.markdown.htmlStash.store(html, True) + return placeholder def get_oembed_html_for_match(self, match): url = match.group(3).strip() From 0e3aaac58c550a7e3397592f820a374272f3b9e6 Mon Sep 17 00:00:00 2001 From: Sami Turcotte Date: Sat, 4 Apr 2015 03:34:33 -0400 Subject: [PATCH 06/11] version bump --- mdx_oembed/__init__.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mdx_oembed/__init__.py b/mdx_oembed/__init__.py index 33ae4dc..b7494c5 100644 --- a/mdx_oembed/__init__.py +++ b/mdx_oembed/__init__.py @@ -2,7 +2,7 @@ from mdx_oembed.extension import OEmbedExtension -VERSION = '0.1.6' +VERSION = '0.1.7' def makeExtension(**kwargs): diff --git a/setup.py b/setup.py index 875f102..062969b 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ except Exception: setup( name='python-markdown-oembed', - version='0.1.6', + version='0.1.7', description="Markdown extension to allow media embedding using the oEmbed " "standard.", long_description=LONG_DESCRIPTION, From 639d4a6dec412c7313067950aca6c860d917f30b Mon Sep 17 00:00:00 2001 From: Sami Turcotte Date: Mon, 20 Apr 2015 00:42:50 -0400 Subject: [PATCH 07/11] Change div wrapper to a figure wrapper The reasoning is that the translation of Markdown into HTML should be as concise as possible. The semantics of the figure element seem to fit the embedded nature of OEmbed content moreso than the div element which is quite generic. --- mdx_oembed/inlinepatterns.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mdx_oembed/inlinepatterns.py b/mdx_oembed/inlinepatterns.py index 1fbb09d..8c59ea1 100644 --- a/mdx_oembed/inlinepatterns.py +++ b/mdx_oembed/inlinepatterns.py @@ -22,7 +22,7 @@ class OEmbedLinkPattern(Pattern): if html is None: return None else: - html = "
%s
" % html + html = "
%s
" % html placeholder = self.markdown.htmlStash.store(html, True) return placeholder From 350d90b6b9503204b33a2cd8306b385e97a02f98 Mon Sep 17 00:00:00 2001 From: Sami Turcotte Date: Mon, 20 Apr 2015 00:44:21 -0400 Subject: [PATCH 08/11] Version bump --- mdx_oembed/__init__.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mdx_oembed/__init__.py b/mdx_oembed/__init__.py index b7494c5..7172523 100644 --- a/mdx_oembed/__init__.py +++ b/mdx_oembed/__init__.py @@ -2,7 +2,7 @@ from mdx_oembed.extension import OEmbedExtension -VERSION = '0.1.7' +VERSION = '0.1.8' def makeExtension(**kwargs): diff --git a/setup.py b/setup.py index 062969b..228e029 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ except Exception: setup( name='python-markdown-oembed', - version='0.1.7', + version='0.1.8', description="Markdown extension to allow media embedding using the oEmbed " "standard.", long_description=LONG_DESCRIPTION, From e2e29489d7bed1085c788fbec7b1e475b45113d4 Mon Sep 17 00:00:00 2001 From: Sami Turcotte Date: Tue, 21 Apr 2015 05:18:42 -0400 Subject: [PATCH 09/11] Allow arbitrary oEmbed endpoints Before this change, only three hardcoded oEmbed endpoints were available for users of the extension; youtube, flickr and vimeo. In the configuration, it was only possible to pass a subset of those 3 oEmbed endpoints. It was done by passing the names of the allowed endpoints. With this change, the API has changed. The allowed_endpoints kwarg now expects to be passed a list of OEmbedEndpoint objects (as opposed to names). This means the responsibility of creating OEmbedEndpoint objects has been shifted to the user of the extension. If the allowed_endpoints kwarg is omitted, the default oEmbed endpoints used will be the same as before; youtube, flickr and vimeo. The motivation is to allow arbitrary oEmbed endpoints, without necessitating anyone to maintain the list of all possible oEmbed endpoints out there. --- mdx_oembed/endpoints.py | 13 +++++++++---- mdx_oembed/extension.py | 22 ++++++++++------------ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/mdx_oembed/endpoints.py b/mdx_oembed/endpoints.py index ce0a0d6..0fd23ba 100644 --- a/mdx_oembed/endpoints.py +++ b/mdx_oembed/endpoints.py @@ -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/*', ]), } diff --git a/mdx_oembed/extension.py b/mdx_oembed/extension.py index 9ad8ee1..b3916fa 100644 --- a/mdx_oembed/extension.py +++ b/mdx_oembed/extension.py @@ -1,21 +1,18 @@ # -*- 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): 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) @@ -27,10 +24,11 @@ class OEmbedExtension(Extension): md.inlinePatterns.add('oembed_link', link_pattern, ' Date: Tue, 21 Apr 2015 05:19:19 -0400 Subject: [PATCH 10/11] Version bump --- mdx_oembed/__init__.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mdx_oembed/__init__.py b/mdx_oembed/__init__.py index 7172523..32a9d2a 100644 --- a/mdx_oembed/__init__.py +++ b/mdx_oembed/__init__.py @@ -2,7 +2,7 @@ from mdx_oembed.extension import OEmbedExtension -VERSION = '0.1.8' +VERSION = '0.1.9' def makeExtension(**kwargs): diff --git a/setup.py b/setup.py index 228e029..67d31e4 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ except Exception: setup( name='python-markdown-oembed', - version='0.1.8', + version='0.1.9', description="Markdown extension to allow media embedding using the oEmbed " "standard.", long_description=LONG_DESCRIPTION, From 95d2797cfaf7a5485bd0099911ebd1de8b67acdc Mon Sep 17 00:00:00 2001 From: Sami Turcotte Date: Tue, 21 Apr 2015 05:23:39 -0400 Subject: [PATCH 11/11] Fix syntax error --- mdx_oembed/endpoints.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mdx_oembed/endpoints.py b/mdx_oembed/endpoints.py index 0fd23ba..370bfaa 100644 --- a/mdx_oembed/endpoints.py +++ b/mdx_oembed/endpoints.py @@ -18,4 +18,4 @@ DEFAULT_ENDPOINTS = [ oembed.OEmbedEndpoint('http://vimeo.com/api/oembed.json', [ 'https?://vimeo.com/*', ]), -} +]