From 2f56c1c11aa1158b64dc1829b83b5e516d042666 Mon Sep 17 00:00:00 2001 From: "J. Tanner Netterville" Date: Tue, 13 Nov 2012 17:28:04 -0600 Subject: [PATCH] allow configuring which endpoints to allow --- mdx_oembed/__init__.py | 2 ++ mdx_oembed/extension.py | 18 ++++++++++++--- mdx_oembed/inlinepatterns.py | 6 ++++- tests.py | 45 +++++++++++++++++++++++++++++++----- 4 files changed, 61 insertions(+), 10 deletions(-) diff --git a/mdx_oembed/__init__.py b/mdx_oembed/__init__.py index 4395f4b..f1cd610 100644 --- a/mdx_oembed/__init__.py +++ b/mdx_oembed/__init__.py @@ -3,4 +3,6 @@ from mdx_oembed.extension import OEmbedExtension def makeExtension(configs=None): + if isinstance(configs, list): + configs = dict(configs) return OEmbedExtension(configs=configs) diff --git a/mdx_oembed/extension.py b/mdx_oembed/extension.py index 8c7a86d..84e84a6 100644 --- a/mdx_oembed/extension.py +++ b/mdx_oembed/extension.py @@ -5,16 +5,28 @@ from mdx_oembed.endpoints import 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 extendMarkdown(self, md, md_globals): self.oembed_consumer = self.prepare_oembed_consumer() - pattern = OEmbedLinkPattern(OEMBED_LINK_RE, md, self.oembed_consumer) - md.inlinePatterns.add('oembed_link', pattern, '