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

Commit a93e09a

Browse files
authored
Extends quote extension (#365)
* Extends quote extension (sphinx) * film, show * Adds parameter title1 to quote directive * Extends quote extension
1 parent a0b4b69 commit a93e09a

File tree

3 files changed

+184
-11
lines changed

3 files changed

+184
-11
lines changed

_unittests/ut_sphinxext/test_quote_extension.py

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,5 +273,134 @@ def test_quote_show(self):
273273
if ":author: auteur" not in rst:
274274
raise Exception(rst)
275275

276+
def test_quote_comic(self):
277+
from docutils import nodes as skip_
278+
279+
content = """
280+
.. quote::
281+
:author: auteur
282+
:comic: comic titre
283+
:lid: label1
284+
:pages: 234
285+
:year: 2018
286+
:title1: true
287+
288+
this code should appear___
289+
290+
next
291+
""".replace(" ", "")
292+
if sys.version_info[0] >= 3:
293+
content = content.replace('u"', '"')
294+
295+
tives = [("quote", QuoteNode, quote_node,
296+
visit_quote_node, depart_quote_node)]
297+
298+
html = rst2html(content, # fLOG=fLOG,
299+
writer="html", keep_warnings=True,
300+
directives=tives, extlinks={'issue': ('http://%s', '_issue_')})
301+
302+
temp = get_temp_folder(__file__, "temp_quote_comic", clean=False)
303+
with open(os.path.join(temp, "test_quote_comic.html"), "w", encoding="utf8") as f:
304+
f.write(html)
305+
306+
t1 = "this code should appear"
307+
if t1 not in html:
308+
raise Exception(html)
309+
if "auteur" not in html:
310+
raise Exception(html)
311+
if "comic titre" not in html:
312+
raise Exception(html)
313+
if "234" not in html:
314+
raise Exception(html)
315+
316+
tives = [("quote", QuoteNode, quote_node,
317+
visit_quote_node_rst, depart_quote_node_rst)]
318+
319+
rst = rst2html(content, # fLOG=fLOG,
320+
writer="rst", keep_warnings=True,
321+
directives=tives, extlinks={'issue': ('http://%s', '_issue_')})
322+
323+
with open(os.path.join(temp, "test_quote_comic.rst"), "w", encoding="utf8") as f:
324+
f.write(rst)
325+
326+
t1 = "this code should appear"
327+
if t1 not in rst:
328+
raise Exception(rst)
329+
if "auteur" not in rst:
330+
raise Exception(rst)
331+
if "comic titre" not in rst:
332+
raise Exception(rst)
333+
if "234" not in rst:
334+
raise Exception(rst)
335+
if ".. quote::" not in rst:
336+
raise Exception(rst)
337+
if ":author: auteur" not in rst:
338+
raise Exception(rst)
339+
340+
def test_quote_disc(self):
341+
from docutils import nodes as skip_
342+
343+
content = """
344+
.. quote::
345+
:author: auteur
346+
:disc: disc titre
347+
:lid: label1
348+
:pages: 234
349+
:year: 2018
350+
:title1: true
351+
352+
this code should appear___
353+
354+
next
355+
""".replace(" ", "")
356+
if sys.version_info[0] >= 3:
357+
content = content.replace('u"', '"')
358+
359+
tives = [("quote", QuoteNode, quote_node,
360+
visit_quote_node, depart_quote_node)]
361+
362+
html = rst2html(content, # fLOG=fLOG,
363+
writer="html", keep_warnings=True,
364+
directives=tives, extlinks={'issue': ('http://%s', '_issue_')})
365+
366+
temp = get_temp_folder(__file__, "temp_quote_disc", clean=False)
367+
with open(os.path.join(temp, "test_quote_disc.html"), "w", encoding="utf8") as f:
368+
f.write(html)
369+
370+
t1 = "this code should appear"
371+
if t1 not in html:
372+
raise Exception(html)
373+
if "auteur" not in html:
374+
raise Exception(html)
375+
if "disc titre" not in html:
376+
raise Exception(html)
377+
if "234" not in html:
378+
raise Exception(html)
379+
380+
tives = [("quote", QuoteNode, quote_node,
381+
visit_quote_node_rst, depart_quote_node_rst)]
382+
383+
rst = rst2html(content, # fLOG=fLOG,
384+
writer="rst", keep_warnings=True,
385+
directives=tives, extlinks={'issue': ('http://%s', '_issue_')})
386+
387+
with open(os.path.join(temp, "test_quote_disc.rst"), "w", encoding="utf8") as f:
388+
f.write(rst)
389+
390+
t1 = "this code should appear"
391+
if t1 not in rst:
392+
raise Exception(rst)
393+
if "auteur" not in rst:
394+
raise Exception(rst)
395+
if "disc titre" not in rst:
396+
raise Exception(rst)
397+
if "234" not in rst:
398+
raise Exception(rst)
399+
if ".. quote::" not in rst:
400+
raise Exception(rst)
401+
if ":author: auteur" not in rst:
402+
raise Exception(rst)
403+
404+
276405
if __name__ == "__main__":
277406
unittest.main()

src/pyquickhelper/sphinxext/sphinx_quote_extension.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from docutils.parsers.rst.directives.admonitions import BaseAdmonition
1212
from docutils.statemachine import StringList
1313
from sphinx.util.nodes import nested_parse_with_titles
14+
from ..texthelper.texts_language import TITLES
1415

1516

1617
class quote_node(nodes.admonition):
@@ -26,7 +27,7 @@ class QuoteNode(BaseAdmonition):
2627
It takes the following options:
2728
2829
* *author*
29-
* *book* or *manga* or *film* or *show*
30+
* *book* or *manga* or *film* or *show* or *disc* or *comic*
3031
* *year*
3132
* *pages*
3233
* *tag*
@@ -60,6 +61,8 @@ class QuoteNode(BaseAdmonition):
6061
'author': directives.unchanged,
6162
'book': directives.unchanged,
6263
'manga': directives.unchanged,
64+
'disc': directives.unchanged,
65+
'comic': directives.unchanged,
6366
'show': directives.unchanged,
6467
'film': directives.unchanged,
6568
'year': directives.unchanged,
@@ -83,6 +86,8 @@ def run(self):
8386
docname = None if env is None else env.docname
8487
if docname is not None:
8588
docname = docname.replace("\\", "/").split("/")[-1]
89+
language_code = self.state.document.settings.language_code if hasattr(
90+
self.state.document.settings, "language_code") else "en"
8691

8792
if not self.options.get('class'):
8893
self.options['class'] = ['admonition-quote']
@@ -106,6 +111,8 @@ def __(text):
106111
author = __(self.options.get('author', "").strip())
107112
book = __(self.options.get('book', "").strip())
108113
manga = __(self.options.get('manga', "").strip())
114+
comic = __(self.options.get('comic', "").strip())
115+
disc = __(self.options.get('disc', "").strip())
109116
film = __(self.options.get('film', "").strip())
110117
show = __(self.options.get('show', "").strip())
111118
pages = __(self.options.get('pages', "").strip())
@@ -127,37 +134,58 @@ def __(text):
127134
tnl = [] # pragma: no cover
128135

129136
if title1:
137+
if comic:
138+
tnl.append("**{0}**".format(comic))
139+
if disc:
140+
tnl.append("**{0}**".format(disc))
130141
if book:
131142
tnl.append("**{0}**".format(book))
132-
indexes.append(book)
133143
if manga:
134144
tnl.append("**{0}**".format(manga))
135-
indexes.append(manga)
136145
if show:
137146
tnl.append("**{0}**".format(show))
138-
indexes.append(show)
139147
if film:
140148
tnl.append("**{0}**".format(film))
141-
indexes.append(film)
142149
if author:
143150
tnl.append("*{0}*, ".format(author))
144-
indexes.append(author)
145151
else:
146152
if author:
147153
tnl.append("**{0}**, ".format(author))
148-
indexes.append(author)
154+
if comic:
155+
tnl.append("*{0}*".format(comic))
156+
if disc:
157+
tnl.append("*{0}*".format(disc))
149158
if book:
150159
tnl.append("*{0}*".format(book))
151-
indexes.append(book)
152160
if manga:
153161
tnl.append("*{0}*".format(manga))
154-
indexes.append(manga)
155162
if show:
156163
tnl.append("*{0}*".format(show))
157-
indexes.append(show)
158164
if film:
159165
tnl.append("*{0}*".format(film))
160-
indexes.append(film)
166+
167+
if author:
168+
indexes.append(author)
169+
indexes.append(TITLES[language_code]['author'] + "; " + author)
170+
if comic:
171+
indexes.append(comic)
172+
indexes.append(TITLES[language_code]['comic'] + "; " + comic)
173+
if disc:
174+
indexes.append(disc)
175+
indexes.append(TITLES[language_code]['disc'] + "; " + disc)
176+
if book:
177+
indexes.append(book)
178+
indexes.append(TITLES[language_code]['book'] + "; " + book)
179+
if manga:
180+
indexes.append(manga)
181+
indexes.append(TITLES[language_code]['manga'] + "; " + manga)
182+
if show:
183+
indexes.append(show)
184+
indexes.append(TITLES[language_code]['show'] + "; " + show)
185+
if film:
186+
indexes.append(film)
187+
indexes.append(TITLES[language_code]['film'] + "; " + film)
188+
161189
if pages:
162190
tnl.append(", {0}".format(pages))
163191
if date:
@@ -192,6 +220,8 @@ def __(text):
192220
node['source'] = source
193221
node['book'] = book
194222
node['manga'] = manga
223+
node['disc'] = disc
224+
node['comic'] = comic
195225
node['film'] = film
196226
node['show'] = show
197227
node['index'] = index

src/pyquickhelper/texthelper/texts_language.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
TITLES = {
88
'en': {
99
'allblogs': 'All blog posts',
10+
'author': 'author',
1011
'blocref_node': '',
1112
'blog_entry': 'The original entry is located in <<%s>>, line %d and can be found ',
1213
'blogpost': 'blogpost',
14+
'book': 'book',
1315
'brefmes': '(<<%s>> : %s, line %d)',
1416
'by category:': 'By category:',
1517
'by month:': 'By month:',
@@ -18,12 +20,15 @@
1820
'changes': 'Changes',
1921
'cmdmes': '(<<%s>> : %s, line %d)',
2022
'code': 'code',
23+
'comic': 'comic',
2124
'download': 'download',
25+
'disc': 'disc',
2226
'exmes': '(<<%s>> : %s, line %d)',
2327
'exref_node': 'Examples',
2428
'FAQ': 'FAQ',
2529
'faqmes': '(<<%s>> : %s, line %d)',
2630
'faqref_node': 'FAQ',
31+
'film': 'movie',
2732
'glossary': 'Glossary',
2833
'hide': 'hide',
2934
'In': '<<<',
@@ -32,6 +37,7 @@
3237
'main': 'blog list',
3338
'main2': 'blog main page',
3439
'main_title': 'blog page',
40+
'manga': 'manga',
3541
'mathdef_node': '',
3642
'mathmes': '(<<%s>> : %s, line %d)',
3743
'more': 'post',
@@ -42,6 +48,7 @@
4248
'Out2': 'Raw',
4349
'outl': 'output',
4450
'page1': 'first page',
51+
'show': 'show',
4552
'toc': 'Contents',
4653
'toc0': 'Links',
4754
'toc1': 'Information',
@@ -53,9 +60,11 @@
5360
},
5461
'fr': {
5562
'allblogs': 'Tous les articles de blog',
63+
'author': 'auteur',
5664
'blocref_node': '',
5765
'blog_entry': 'Source <<%s>>, line %d and can be found ',
5866
'blogpost': 'article',
67+
'book': 'livre',
5968
'brefmes': '(<<%s>> : %s, ligne %d)',
6069
'by category:': 'Par catégorie :',
6170
'by month:': 'Par mois :',
@@ -64,12 +73,15 @@
6473
'changes': 'Changements',
6574
'cmdmes': '(<<%s>> : %s, line %d)',
6675
'code': 'code',
76+
'comic': 'bande dessinée',
77+
'disc': 'disque',
6778
'download': 'télécharger',
6879
'exmes': '(<<%s>> : %s, ligne %d)',
6980
'exref_node': 'Exemples',
7081
'FAQ': 'FAQ',
7182
'faqmes': '(<<%s>> : %s, ligne %d)',
7283
'faqref_node': 'FAQ',
84+
'film': 'film',
7385
'glossary': 'Glossaire',
7486
'hide': 'cacher',
7587
'In': '<<<',
@@ -78,6 +90,7 @@
7890
'main': "liste d'articles du blog",
7991
'main2': 'page principale du blog',
8092
'main_title': 'page de blog',
93+
'manga': 'dessin animé',
8194
'mathdef_node': '',
8295
'mathmes': '(<<%s>> : %s, ligne %d)',
8396
'more': 'article',
@@ -88,6 +101,7 @@
88101
'Out2': 'Sortie brute',
89102
'outl': 'la sortie',
90103
'page1': 'première page',
104+
'show': 'série',
91105
'toc': 'Contenu',
92106
'toc0': 'Liens',
93107
'toc1': 'Information',

0 commit comments

Comments
 (0)