Skip to content

Commit eb5e2db

Browse files
committed
supported for Django>=2.0
1 parent 369675d commit eb5e2db

File tree

20 files changed

+214
-88
lines changed

20 files changed

+214
-88
lines changed

README.rst

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ martor |pypi version|
1111
.. image:: https://img.shields.io/pypi/pyversions/martor.svg?style=flat-square
1212
:target: https://pypi.python.org/pypi/martor
1313

14-
.. image:: https://img.shields.io/badge/Django-1.8,%201.9,%201.10,%201.11-green.svg?style=flat-square
14+
.. image:: https://img.shields.io/badge/Django-1.8,%201.9,%201.10,%201.11,%202.0-green.svg?style=flat-square
1515
:target: https://www.djangoproject.com
1616

1717

@@ -27,6 +27,7 @@ Features
2727
* Support Multiple Fields (`fixed this issue`_)
2828
* Upload Image to imgur.com `(via API)` and `custom uploader`_.
2929
* Direct Mention users ``@[username]`` - `(require user to logged in)`
30+
* Support embed/iframe video from (Youtube, Vimeo, Dailymotion, Yahoo, Veoh, & Metacafe)
3031
* Emoji ``:emoji_name:`` + Cheat sheets
3132
* Martor Commands Refference
3233
* Support Django Admin
@@ -78,6 +79,13 @@ Martor is available directly from `PyPI`_:
7879
::
7980

8081
# urls.py
82+
# django >= 2.0
83+
urlpatterns = [
84+
...
85+
path('martor/', include('martor.urls')),
86+
]
87+
88+
# django <= 1.9
8189
urlpatterns = [
8290
...
8391
url(r'^martor/', include('martor.urls')),
@@ -130,9 +138,10 @@ to get ``IMGUR_CLIENT_ID`` and ``IMGUR_API_KEY``.
130138

131139
# Custom markdown extensions.
132140
'martor.extensions.urlize',
133-
'martor.extensions.del_ins', # ~~strikethrough~~ and ++underscores++
134-
'martor.extensions.mention', # require for mention
135-
'martor.extensions.emoji', # require for emoji
141+
'martor.extensions.del_ins', # ~~strikethrough~~ and ++underscores++
142+
'martor.extensions.mention', # to parse markdown mention
143+
'martor.extensions.emoji', # to parse markdown emoji
144+
'martor.extensions.mdx_video', # to parse embed/iframe video
136145
]
137146

138147
# Markdown Extensions Configs

martor/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
22

3-
__VERSION__ = '1.2.5'
3+
__VERSION__ = '1.2.7'
44
__AUTHOR__ = 'Agus Makmun (Summon Agus)'
55
__AUTHOR_EMAIL__ = 'agus@python.web.id'

martor/extensions/mdx_video.py

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/usr/bin/env python
2+
3+
import markdown
4+
from markdown.util import etree
5+
6+
7+
class VideoExtension(markdown.Extension):
8+
9+
def __init__(self, **kwargs):
10+
self.config = {
11+
'dailymotion_width': ['480', 'Width for Dailymotion videos'],
12+
'dailymotion_height': ['270', 'Height for Dailymotion videos'],
13+
'metacafe_width': ['440', 'Width for Metacafe videos'],
14+
'metacafe_height': ['248', 'Height for Metacafe videos'],
15+
'veoh_width': ['410', 'Width for Veoh videos'],
16+
'veoh_height': ['341', 'Height for Veoh videos'],
17+
'vimeo_width': ['500', 'Width for Vimeo videos'],
18+
'vimeo_height': ['281', 'Height for Vimeo videos'],
19+
'yahoo_width': ['624', 'Width for Yahoo! videos'],
20+
'yahoo_height': ['351', 'Height for Yahoo! videos'],
21+
'youtube_width': ['560', 'Width for Youtube videos'],
22+
'youtube_height': ['315', 'Height for Youtube videos'],
23+
}
24+
25+
# Override defaults with user settings
26+
for key, value in kwargs.items():
27+
self.setConfig(key, str(value))
28+
29+
def add_inline(self, md, name, klass, re):
30+
pattern = klass(re)
31+
pattern.md = md
32+
pattern.ext = self
33+
md.inlinePatterns.add(name, pattern, "<reference")
34+
35+
def extendMarkdown(self, md, md_globals):
36+
self.add_inline(md, 'dailymotion', Dailymotion,
37+
r'([^(]|^)https?://www\.dailymotion\.com/video/(?P<dailymotionid>[a-zA-Z0-9]+)(_[\w\-]*)?')
38+
self.add_inline(md, 'metacafe', Metacafe,
39+
r'([^(]|^)http://www\.metacafe\.com/watch/(?P<metacafeid>\d+)/?(:?.+/?)')
40+
self.add_inline(md, 'veoh', Veoh,
41+
r'([^(]|^)http://www\.veoh\.com/\S*(#watch%3D|watch/)(?P<veohid>\w+)')
42+
self.add_inline(md, 'vimeo', Vimeo,
43+
r'([^(]|^)http://(www.|)vimeo\.com/(?P<vimeoid>\d+)\S*')
44+
self.add_inline(md, 'yahoo', Yahoo,
45+
r'([^(]|^)http://screen\.yahoo\.com/.+/?')
46+
self.add_inline(md, 'youtube', Youtube,
47+
r'([^(]|^)https?://www\.youtube\.com/watch\?\S*v=(?P<youtubeid>\S[^&/]+)')
48+
self.add_inline(md, 'youtube_short', Youtube,
49+
r'([^(]|^)https?://youtu\.be/(?P<youtubeid>\S[^?&/]+)?')
50+
51+
52+
class Dailymotion(markdown.inlinepatterns.Pattern):
53+
54+
def handleMatch(self, m):
55+
url = '//www.dailymotion.com/embed/video/%s' % m.group('dailymotionid')
56+
width = self.ext.config['dailymotion_width'][0]
57+
height = self.ext.config['dailymotion_height'][0]
58+
return render_iframe(url, width, height)
59+
60+
61+
class Metacafe(markdown.inlinepatterns.Pattern):
62+
63+
def handleMatch(self, m):
64+
url = '//www.metacafe.com/embed/%s/' % m.group('metacafeid')
65+
width = self.ext.config['metacafe_width'][0]
66+
height = self.ext.config['metacafe_height'][0]
67+
return render_iframe(url, width, height)
68+
69+
70+
class Veoh(markdown.inlinepatterns.Pattern):
71+
72+
def handleMatch(self, m):
73+
url = '//www.veoh.com/videodetails2.swf?permalinkId=%s' % m.group('veohid')
74+
width = self.ext.config['veoh_width'][0]
75+
height = self.ext.config['veoh_height'][0]
76+
return flash_object(url, width, height)
77+
78+
79+
class Vimeo(markdown.inlinepatterns.Pattern):
80+
81+
def handleMatch(self, m):
82+
url = '//player.vimeo.com/video/%s' % m.group('vimeoid')
83+
width = self.ext.config['vimeo_width'][0]
84+
height = self.ext.config['vimeo_height'][0]
85+
return render_iframe(url, width, height)
86+
87+
88+
class Yahoo(markdown.inlinepatterns.Pattern):
89+
90+
def handleMatch(self, m):
91+
url = m.string + '?format=embed&player_autoplay=false'
92+
width = self.ext.config['yahoo_width'][0]
93+
height = self.ext.config['yahoo_height'][0]
94+
return render_iframe(url, width, height)
95+
96+
97+
class Youtube(markdown.inlinepatterns.Pattern):
98+
99+
def handleMatch(self, m):
100+
url = '//www.youtube.com/embed/%s' % m.group('youtubeid')
101+
width = self.ext.config['youtube_width'][0]
102+
height = self.ext.config['youtube_height'][0]
103+
return render_iframe(url, width, height)
104+
105+
106+
def render_iframe(url, width, height):
107+
iframe = etree.Element('iframe')
108+
iframe.set('width', width)
109+
iframe.set('height', height)
110+
iframe.set('src', url)
111+
iframe.set('allowfullscreen', 'true')
112+
iframe.set('frameborder', '0')
113+
return iframe
114+
115+
116+
def flash_object(url, width, height):
117+
obj = etree.Element('object')
118+
obj.set('type', 'application/x-shockwave-flash')
119+
obj.set('width', width)
120+
obj.set('height', height)
121+
obj.set('data', url)
122+
param = etree.Element('param')
123+
param.set('name', 'movie')
124+
param.set('value', url)
125+
obj.append(param)
126+
param = etree.Element('param')
127+
param.set('name', 'allowFullScreen')
128+
param.set('value', 'true')
129+
obj.append(param)
130+
return obj
131+
132+
133+
def makeExtension(**kwargs):
134+
return VideoExtension(**kwargs)
135+
136+
137+
if __name__ == "__main__":
138+
import doctest
139+
doctest.testmod()

martor/settings.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@
4646

4747
# Custom markdown extensions.
4848
'martor.extensions.urlize',
49-
'martor.extensions.del_ins', # ~~strikethrough~~ and ++underscores++
50-
'martor.extensions.mention', # to parse markdown mention
51-
'martor.extensions.emoji', # to parse markdown emoji
49+
'martor.extensions.del_ins', # ~~strikethrough~~ and ++underscores++
50+
'martor.extensions.mention', # to parse markdown mention
51+
'martor.extensions.emoji', # to parse markdown emoji
52+
'martor.extensions.mdx_video', # to parse embed/iframe video
5253
]
5354
)
5455

martor/static/martor/css/martor.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

martor/static/martor/js/martor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Name : Martor v1.2.5
2+
* Name : Martor v1.2.7
33
* Created by : Agus Makmun (Summon Agus)
44
* Release date : 02-Dec-2017
55
* License : GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007

martor/static/martor/js/martor.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

martor/static/plugins/fonts/icons.eot

100755100644
File mode changed.

martor/static/plugins/fonts/icons.otf

100755100644
File mode changed.

martor/static/plugins/fonts/icons.svg

100755100644
File mode changed.

0 commit comments

Comments
 (0)