diff --git a/.gitignore b/.gitignore index 1ae6ed9..4e17e26 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ .DS_Store .idea -dist +/dist +/.eggs +/venv *.pyc +*.egg *.egg-info diff --git a/.travis.yml b/.travis.yml index d6c3478..89de62b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,9 @@ language: python python: - - "2.6" - - "2.7" -# command to run tests -script: python setup.py test \ No newline at end of file + - "2.7" + - "3.2" + - "3.3" + - "3.4" + - "3.5" +install: "pip install . nose mock" +script: nosetests diff --git a/README.markdown b/README.markdown index 3fcfb3d..b89e8ce 100644 --- a/README.markdown +++ b/README.markdown @@ -1,5 +1,7 @@ # Python Markdown oEmbed +[![Build Status](https://travis-ci.org/rennat/python-markdown-oembed.svg?branch=master)](https://travis-ci.org/rennat/python-markdown-oembed) + Markdown extension to allow media embedding using the oEmbed standard. ## Installation @@ -23,3 +25,13 @@ Markdown extension to allow media embedding using the oEmbed standard. ## License A Public Domain work. Do as you wish. + +## Changelog + +### 0.2.0 + +- backwards incompatible changes + - allows arbitrary endpoints ([commit](https://github.com/Wenzil/python-markdown-oembed/commit/1e89de9db5e63677e071c36503e2499bbe0792da)) + - works with modern Markdown (>=2.6) + - dropped support for python 2.6 +- added support python 3.x diff --git a/mdx_oembed/__init__.py b/mdx_oembed/__init__.py index 97960a4..9bac0d9 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.2.0' -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/endpoints.py b/mdx_oembed/endpoints.py index ce0a0d6..49901f2 100644 --- a/mdx_oembed/endpoints.py +++ b/mdx_oembed/endpoints.py @@ -1,16 +1,21 @@ # -*- coding: utf-8 -*- import oembed +YOUTUBE = oembed.OEmbedEndpoint('http://www.youtube.com/oembed', [ + 'https?://(*.)?youtube.com/*', + 'https?://youtu.be/*', +]) -ENDPOINTS = { - 'youtube': oembed.OEmbedEndpoint('http://www.youtube.com/oembed', [ - 'https?://(*.)?youtube.com/*', - 'https?://youtu.be/*', - ]), - 'flickr': oembed.OEmbedEndpoint('http://www.flickr.com/services/oembed/', [ - 'https?://*.flickr.com/*', - ]), - 'vimeo': oembed.OEmbedEndpoint('http://vimeo.com/api/oembed.json', [ - 'https?://vimeo.com/*', - ]), -} +FLICKR = oembed.OEmbedEndpoint('http://www.flickr.com/services/oembed/', [ + 'https?://*.flickr.com/*', +]) + +VIMEO = oembed.OEmbedEndpoint('http://vimeo.com/api/oembed.json', [ + 'https?://vimeo.com/*', +]) + +DEFAULT_ENDPOINTS = [ + YOUTUBE, + FLICKR, + VIMEO +] diff --git a/mdx_oembed/extension.py b/mdx_oembed/extension.py index 84e84a6..b3916fa 100644 --- a/mdx_oembed/extension.py +++ b/mdx_oembed/extension.py @@ -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 = { - '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': [ + 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, '%s" % html + placeholder = self.markdown.htmlStash.store(html, True) + return placeholder def get_oembed_html_for_match(self, match): url = match.group(3).strip() diff --git a/setup.py b/setup.py index 3e9ec51..d4dc324 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ except Exception: setup( name='python-markdown-oembed', - version='0.1.4', + version='0.2.0', description="Markdown extension to allow media embedding using the oEmbed " "standard.", long_description=LONG_DESCRIPTION, @@ -36,16 +36,12 @@ setup( ], install_requires=[ "python-oembed >= 0.2.1", - "Markdown >= 2.2.0", + "Markdown >= 2.6.1", ], test_suite='nose.collector', tests_require=[ 'nose', - 'mock', - 'WebTest >= 1.2', - 'BeautifulSoup', - 'pytidylib', - 'poster' + 'mock' ] ) diff --git a/tests.py b/tests.py index bbf9c41..b3e8662 100644 --- a/tests.py +++ b/tests.py @@ -3,7 +3,9 @@ import re import unittest import markdown from mock import patch +from nose.plugins.skip import SkipTest from mdx_oembed.extension import OEMBED_LINK_RE +from mdx_oembed import endpoints class OEmbedPatternRegexTestCase(unittest.TestCase): @@ -110,6 +112,7 @@ class ProtocolVarietyTestCase(OEmbedExtensionTestCase): self.assertIn('