Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit 703793b

Browse files
authored
Extends quote extension (sphinx) (#363)
* Extends quote extension (sphinx) * film, show
1 parent 5dc34a5 commit 703793b

File tree

2 files changed

+208
-2
lines changed

2 files changed

+208
-2
lines changed

_unittests/ut_sphinxext/test_quote_extension.py

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,194 @@ def test_quote(self):
8383
if ":author: auteur" not in rst:
8484
raise Exception(rst)
8585

86+
def test_quote_manga(self):
87+
from docutils import nodes as skip_
88+
89+
content = """
90+
.. quote::
91+
:author: auteur
92+
:manga: manga titre
93+
:lid: label1
94+
:pages: 234
95+
:year: 2018
96+
97+
this code should appear___
98+
99+
next
100+
""".replace(" ", "")
101+
if sys.version_info[0] >= 3:
102+
content = content.replace('u"', '"')
103+
104+
tives = [("quote", QuoteNode, quote_node,
105+
visit_quote_node, depart_quote_node)]
106+
107+
html = rst2html(content, # fLOG=fLOG,
108+
writer="html", keep_warnings=True,
109+
directives=tives, extlinks={'issue': ('http://%s', '_issue_')})
110+
111+
temp = get_temp_folder(__file__, "temp_quote_manga", clean=False)
112+
with open(os.path.join(temp, "test_quote_manga.html"), "w", encoding="utf8") as f:
113+
f.write(html)
114+
115+
t1 = "this code should appear"
116+
if t1 not in html:
117+
raise Exception(html)
118+
if "auteur" not in html:
119+
raise Exception(html)
120+
if "manga titre" not in html:
121+
raise Exception(html)
122+
if "234" not in html:
123+
raise Exception(html)
124+
125+
tives = [("quote", QuoteNode, quote_node,
126+
visit_quote_node_rst, depart_quote_node_rst)]
127+
128+
rst = rst2html(content, # fLOG=fLOG,
129+
writer="rst", keep_warnings=True,
130+
directives=tives, extlinks={'issue': ('http://%s', '_issue_')})
131+
132+
with open(os.path.join(temp, "test_quote_manga.rst"), "w", encoding="utf8") as f:
133+
f.write(rst)
134+
135+
t1 = "this code should appear"
136+
if t1 not in rst:
137+
raise Exception(rst)
138+
if "auteur" not in rst:
139+
raise Exception(rst)
140+
if "manga titre" not in rst:
141+
raise Exception(rst)
142+
if "234" not in rst:
143+
raise Exception(rst)
144+
if ".. quote::" not in rst:
145+
raise Exception(rst)
146+
if ":author: auteur" not in rst:
147+
raise Exception(rst)
148+
149+
def test_quote_film(self):
150+
from docutils import nodes as skip_
151+
152+
content = """
153+
.. quote::
154+
:author: auteur
155+
:film: film titre
156+
:lid: label1
157+
:pages: 234
158+
:year: 2018
159+
160+
this code should appear___
161+
162+
next
163+
""".replace(" ", "")
164+
if sys.version_info[0] >= 3:
165+
content = content.replace('u"', '"')
166+
167+
tives = [("quote", QuoteNode, quote_node,
168+
visit_quote_node, depart_quote_node)]
169+
170+
html = rst2html(content, # fLOG=fLOG,
171+
writer="html", keep_warnings=True,
172+
directives=tives, extlinks={'issue': ('http://%s', '_issue_')})
173+
174+
temp = get_temp_folder(__file__, "temp_quote_film", clean=False)
175+
with open(os.path.join(temp, "test_quote_film.html"), "w", encoding="utf8") as f:
176+
f.write(html)
177+
178+
t1 = "this code should appear"
179+
if t1 not in html:
180+
raise Exception(html)
181+
if "auteur" not in html:
182+
raise Exception(html)
183+
if "film titre" not in html:
184+
raise Exception(html)
185+
if "234" not in html:
186+
raise Exception(html)
187+
188+
tives = [("quote", QuoteNode, quote_node,
189+
visit_quote_node_rst, depart_quote_node_rst)]
190+
191+
rst = rst2html(content, # fLOG=fLOG,
192+
writer="rst", keep_warnings=True,
193+
directives=tives, extlinks={'issue': ('http://%s', '_issue_')})
194+
195+
with open(os.path.join(temp, "test_quote_film.rst"), "w", encoding="utf8") as f:
196+
f.write(rst)
197+
198+
t1 = "this code should appear"
199+
if t1 not in rst:
200+
raise Exception(rst)
201+
if "auteur" not in rst:
202+
raise Exception(rst)
203+
if "film titre" not in rst:
204+
raise Exception(rst)
205+
if "234" not in rst:
206+
raise Exception(rst)
207+
if ".. quote::" not in rst:
208+
raise Exception(rst)
209+
if ":author: auteur" not in rst:
210+
raise Exception(rst)
211+
212+
def test_quote_show(self):
213+
from docutils import nodes as skip_
214+
215+
content = """
216+
.. quote::
217+
:author: auteur
218+
:show: show titre
219+
:lid: label1
220+
:pages: 234
221+
:year: 2018
222+
223+
this code should appear___
224+
225+
next
226+
""".replace(" ", "")
227+
if sys.version_info[0] >= 3:
228+
content = content.replace('u"', '"')
229+
230+
tives = [("quote", QuoteNode, quote_node,
231+
visit_quote_node, depart_quote_node)]
232+
233+
html = rst2html(content, # fLOG=fLOG,
234+
writer="html", keep_warnings=True,
235+
directives=tives, extlinks={'issue': ('http://%s', '_issue_')})
236+
237+
temp = get_temp_folder(__file__, "temp_quote_show", clean=False)
238+
with open(os.path.join(temp, "test_quote_show.html"), "w", encoding="utf8") as f:
239+
f.write(html)
240+
241+
t1 = "this code should appear"
242+
if t1 not in html:
243+
raise Exception(html)
244+
if "auteur" not in html:
245+
raise Exception(html)
246+
if "show titre" not in html:
247+
raise Exception(html)
248+
if "234" not in html:
249+
raise Exception(html)
250+
251+
tives = [("quote", QuoteNode, quote_node,
252+
visit_quote_node_rst, depart_quote_node_rst)]
253+
254+
rst = rst2html(content, # fLOG=fLOG,
255+
writer="rst", keep_warnings=True,
256+
directives=tives, extlinks={'issue': ('http://%s', '_issue_')})
257+
258+
with open(os.path.join(temp, "test_quote_show.rst"), "w", encoding="utf8") as f:
259+
f.write(rst)
260+
261+
t1 = "this code should appear"
262+
if t1 not in rst:
263+
raise Exception(rst)
264+
if "auteur" not in rst:
265+
raise Exception(rst)
266+
if "show titre" not in rst:
267+
raise Exception(rst)
268+
if "234" not in rst:
269+
raise Exception(rst)
270+
if ".. quote::" not in rst:
271+
raise Exception(rst)
272+
if ":author: auteur" not in rst:
273+
raise Exception(rst)
86274

87275
if __name__ == "__main__":
88276
unittest.main()

src/pyquickhelper/sphinxext/sphinx_quote_extension.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class QuoteNode(BaseAdmonition):
2626
It takes the following options:
2727
2828
* *author*
29-
* *book*
29+
* *book* or *manga* or *film* or *show*
3030
* *year*
3131
* *pages*
3232
* *tag*
@@ -58,6 +58,9 @@ class QuoteNode(BaseAdmonition):
5858
option_spec = {
5959
'author': directives.unchanged,
6060
'book': directives.unchanged,
61+
'manga': directives.unchanged,
62+
'show': directives.unchanged,
63+
'film': directives.unchanged,
6164
'year': directives.unchanged,
6265
'pages': directives.unchanged,
6366
'tag': directives.unchanged,
@@ -100,6 +103,9 @@ def __(text):
100103
# book
101104
author = __(self.options.get('author', "").strip())
102105
book = __(self.options.get('book', "").strip())
106+
manga = __(self.options.get('manga', "").strip())
107+
film = __(self.options.get('film', "").strip())
108+
show = __(self.options.get('show', "").strip())
103109
pages = __(self.options.get('pages', "").strip())
104110
year = __(self.options.get('year', "").strip())
105111
source = __(self.options.get('source', "").strip())
@@ -123,6 +129,15 @@ def __(text):
123129
if book:
124130
tnl.append("*{0}*".format(book))
125131
indexes.append(book)
132+
if manga:
133+
tnl.append("*{0}*".format(manga))
134+
indexes.append(manga)
135+
if show:
136+
tnl.append("*{0}*".format(show))
137+
indexes.append(show)
138+
if film:
139+
tnl.append("*{0}*".format(film))
140+
indexes.append(film)
126141
if pages:
127142
tnl.append(", {0}".format(pages))
128143
if date:
@@ -146,7 +161,7 @@ def __(text):
146161
from sphinx.util import logging
147162
logger = logging.getLogger("blogpost")
148163
logger.warning(
149-
"[blogpost] unable to parse '{0}' - '{1}' - {2}".format(author, book, e))
164+
"[blogpost] unable to parse '{0}' - '{1}' - {2}".format(author, book or manga, e))
150165
raise e
151166

152167
node['tag'] = tag
@@ -156,6 +171,9 @@ def __(text):
156171
node['label'] = lid
157172
node['source'] = source
158173
node['book'] = book
174+
node['manga'] = manga
175+
node['film'] = film
176+
node['show'] = show
159177
node['index'] = index
160178
node['content'] = '\n'.join(self.content)
161179
node['classes'] += ["quote"]

0 commit comments

Comments
 (0)