-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrst_html5_audiovideo.py
131 lines (104 loc) · 3.21 KB
/
rst_html5_audiovideo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from docutils import nodes
from docutils.parsers.rst import directives
"""
HTML5 audio and video directive for reStructuredText
====================================================
Directive
---------
.. video:: <url>
width= int
height= int
autoplay= bool
preload= bool
controls= bool
.. audio:: <url>
autoplay= bool
preload= bool
controls= bool
License
-------
The Python source code is under the terms of the MIT License <http://www.opensource.org/licenses/mit-license.php>.
From original source code: <https://github.com/nduhamel/Pelican-plugins/blob/master/rst_youtube.py>
"""
VIDEO = """
<video
src="{src}"
width="{width}"
height="{height}"
{autoplay}
{controls}
{preload}>
<p>
If you can't see this video, try with Frefox:<br />
<a
href="http://www.mozilla-europe.org/"><img
border="0" alt="Get Firefox" title="Get Firefox"
src="http://sfx-images.mozilla.org/affiliates/Buttons/180x60/trust.gif" /></a>
</p>
</video>
"""
AUDIO = """
<audio
src="{src}"
{autoplay}
{controls}
{preload}>
<p>
If you can't heard this sound, try with Firefox:<br />
<a
href="http://www.mozilla-europe.org/"><img
border="0" alt="Get Firefox" title="Get Firefox"
src="http://sfx-images.mozilla.org/affiliates/Buttons/180x60/trust.gif" /></a>
</p>
</audio>
"""
def video(name, args, options, content, lineno,
contentOffset, blockText, state, stateMachine):
""" Restructured text extension for inserting html5 videos """
opts = {
'src': content[0],
'width': 400,
'height': 300,
'controls': 'controls',
'preload': 'preload'
}
opts.update(
dict(
[
(
i.split('=')[0].lower(),
i.split('=')[-1].lower()
) for i in content[1:]
]
)
)
opts['autoplay'] = 'autoplay="autoplay"' if opts.get('autoplay') else ''
opts['controls'] = 'controls="controls"' if opts.get('controls') else ''
opts['preload'] = 'preload="preload"' if opts.get('preload') else ''
return [nodes.raw('', VIDEO.format(**opts), format='html')]
video.content = True
directives.register_directive('video', video)
def audio(name, args, options, content, lineno,
contentOffset, blockText, state, stateMachine):
""" Restructured text extension for inserting html5 audio """
opts = {
'src': content[0],
'controls': 'controls',
'preload': 'preload'
}
opts.update(
dict(
[
(
i.split('=')[0].lower(),
i.split('=')[-1].lower()
) for i in content[1:]
]
)
)
opts['autoplay'] = 'autoplay="autoplay"' if opts.get('autoplay') else ''
opts['controls'] = 'controls="controls"' if opts.get('controls') else ''
opts['preload'] = 'preload="preload"' if opts.get('preload') else ''
return [nodes.raw('', AUDIO.format(**opts), format='html')]
audio.content = True
directives.register_directive('audio', audio)