diff --git a/.gitignore b/.gitignore index 4e17e26..6b21a0f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,10 @@ .idea /dist /.eggs -/venv +venv *.pyc *.egg *.egg-info +*.coverage +*.swp +*.swo diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..9b0eab5 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1698611440, + "narHash": "sha256-jPjHjrerhYDy3q9+s5EAsuhyhuknNfowY6yt6pjn9pc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0cbe9f69c234a7700596e943bfae7ef27a31b735", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ffb8b7d --- /dev/null +++ b/flake.nix @@ -0,0 +1,29 @@ +{ + description = "Oembed plugin flake"; + inputs = { + nixpkgs.url = github:NixOS/nixpkgs/nixos-unstable; + }; + outputs = { self, nixpkgs }: + let + pkgs = import nixpkgs { + inherit system; + overlays = []; + }; + pythonPackages = pkgs.python3Packages; + system = "x86_64-linux"; + in rec { + devShell.x86_64-linux = pkgs.mkShell { + buildInputs = [ + pkgs.python3 + pkgs.python3Packages.pip + ]; + shellHook = '' + export PS1='\u@md-oembed \$ ' + export PIP_PREFIX=$(pwd)/venv/pip_packages + export PYTHONPATH="$PIP_PREFIX/${pkgs.python3.sitePackages}:$PYTHONPATH" + export PATH="$PIP_PREFIX/bin:$PATH" + unset SOURCE_DATE_EPOCH + ''; + }; + }; +} diff --git a/src/python_markdown_oembed_extension/__init__.py b/src/python_markdown_oembed_extension/__init__.py new file mode 100644 index 0000000..b733a04 --- /dev/null +++ b/src/python_markdown_oembed_extension/__init__.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +from python_markdown_oembed_extension.oembedextension import OEmbedExtension + + +VERSION = '0.2.2' + + +def makeExtension(**kwargs): + return OEmbedExtension(**kwargs) diff --git a/mdx_oembed/endpoints.py b/src/python_markdown_oembed_extension/endpoints.py similarity index 100% rename from mdx_oembed/endpoints.py rename to src/python_markdown_oembed_extension/endpoints.py diff --git a/mdx_oembed/inlinepatterns.py b/src/python_markdown_oembed_extension/inlinepatterns.py similarity index 100% rename from mdx_oembed/inlinepatterns.py rename to src/python_markdown_oembed_extension/inlinepatterns.py diff --git a/mdx_oembed/extension.py b/src/python_markdown_oembed_extension/oembedextension.py similarity index 88% rename from mdx_oembed/extension.py rename to src/python_markdown_oembed_extension/oembedextension.py index 14607dd..bfe3cc7 100644 --- a/mdx_oembed/extension.py +++ b/src/python_markdown_oembed_extension/oembedextension.py @@ -1,7 +1,7 @@ from markdown import Extension import oembed -from mdx_oembed.endpoints import DEFAULT_ENDPOINTS -from mdx_oembed.inlinepatterns import OEmbedLinkPattern, OEMBED_LINK_RE +from python_markdown_oembed_extension.endpoints import DEFAULT_ENDPOINTS +from python_markdown_oembed_extension.inlinepatterns import OEmbedLinkPattern, OEMBED_LINK_RE class OEmbedExtension(Extension): @@ -36,3 +36,4 @@ class OEmbedExtension(Extension): for endpoint in (allowed_endpoints or []): consumer.addEndpoint(endpoint) return consumer + diff --git a/src/python_markdown_oembed_extension/tests/test_expectedHtml.html b/src/python_markdown_oembed_extension/tests/test_expectedHtml.html new file mode 100644 index 0000000..0740525 --- /dev/null +++ b/src/python_markdown_oembed_extension/tests/test_expectedHtml.html @@ -0,0 +1,9 @@ +

In this video Jakob Zinsstag introduces the topic of the course. You will +discover that the relationship between humans and animals is manifold. +{.lead}

+

+

Have a look at the farm of Jakob Zinsstag’s cousin in the Canton of Jura, +Switzerland. Different animals create different feelings: there are those we +love, some provoke fears and others will be eaten. Jakob Zinsstag shares the +personal experiences he has had with animals.

+

How do you categorise your own experience with animals?

diff --git a/src/python_markdown_oembed_extension/tests/test_markdown.md b/src/python_markdown_oembed_extension/tests/test_markdown.md new file mode 100644 index 0000000..107b350 --- /dev/null +++ b/src/python_markdown_oembed_extension/tests/test_markdown.md @@ -0,0 +1,12 @@ +In this video Jakob Zinsstag introduces the topic of the course. You will +discover that the relationship between humans and animals is manifold. +{.lead} + +![embed](https://vimeo.com/734276368/f29c542352) + +Have a look at the farm of Jakob Zinsstag’s cousin in the Canton of Jura, +Switzerland. Different animals create different feelings: there are those we +love, some provoke fears and others will be eaten. Jakob Zinsstag shares the +personal experiences he has had with animals. + +**How do you categorise your own experience with animals?** diff --git a/src/python_markdown_oembed_extension/tests/test_markdown.py b/src/python_markdown_oembed_extension/tests/test_markdown.py new file mode 100644 index 0000000..4391235 --- /dev/null +++ b/src/python_markdown_oembed_extension/tests/test_markdown.py @@ -0,0 +1,21 @@ +import markdown, yaml, requests_mock +from python_markdown_oembed_extension.oembedextension import OEmbedExtension +from python_markdown_oembed_extension.endpoints import VIMEO + + +def test_full(): + with ( requests_mock.Mocker() as m + , open('./src/python_markdown_oembed_extension/tests/vimeoMock.yaml', 'r') as vm + , open('./src/python_markdown_oembed_extension/tests/test_markdown.md', 'r') as md + , open('./src/python_markdown_oembed_extension/tests/test_expectedHtml.html', 'r') as expectedHtml + ): + + yml = yaml.safe_load(vm) + m.get(yml['request'], json=yml['response']) + + mdString = md.read() + htmlString = markdown.markdown(mdString, extensions=[OEmbedExtension()]) + print(htmlString) + + assert htmlString == expectedHtml.read().rstrip() + diff --git a/src/python_markdown_oembed_extension/tests/vimeoMock.yaml b/src/python_markdown_oembed_extension/tests/vimeoMock.yaml new file mode 100644 index 0000000..4559214 --- /dev/null +++ b/src/python_markdown_oembed_extension/tests/vimeoMock.yaml @@ -0,0 +1,30 @@ +--- +request: 'https://vimeo.com/734276368/f29c542352' +response: + account_type: 'live_premium' + author_name: 'NMC Universität Basel' + author_url: 'https://vimeo.com/newmediacenterunibasel' + description: '' + duration: 282 + height: 240 + html: >- + + is_plus: '0' + provider_name: 'Vimeo' + provider_url: 'https://vimeo.com/' + thumbnail_height: 166 + thumbnail_url: 'https://i.vimeocdn.com/video/1480489232-5ca2d723cadc09ae077c8b437581e84bd0485049780c60e218986fda60881110-d_295x166' + thumbnail_url_with_play_button: 'https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F1480489232-5ca2d723cadc09ae077c8b437581e84bd0485049780c60e218986fda60881110-d_295x166&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png' + thumbnail_width: 295 + title: 'One-Health_Tales_EN_1-02' + type: 'video' + upload_date: '2022-07-28 04:16:03' + uri: '/videos/734276368:f29c542352' + version: '1.0' + video_id: 734276368 + width: 426