Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions _unittests/ut_sphinxext/test_quote_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,134 @@ def test_quote_show(self):
if ":author: auteur" not in rst:
raise Exception(rst)

def test_quote_comic(self):
from docutils import nodes as skip_

content = """
.. quote::
:author: auteur
:comic: comic titre
:lid: label1
:pages: 234
:year: 2018
:title1: true

this code should appear___

next
""".replace(" ", "")
if sys.version_info[0] >= 3:
content = content.replace('u"', '"')

tives = [("quote", QuoteNode, quote_node,
visit_quote_node, depart_quote_node)]

html = rst2html(content, # fLOG=fLOG,
writer="html", keep_warnings=True,
directives=tives, extlinks={'issue': ('http://%s', '_issue_')})

temp = get_temp_folder(__file__, "temp_quote_comic", clean=False)
with open(os.path.join(temp, "test_quote_comic.html"), "w", encoding="utf8") as f:
f.write(html)

t1 = "this code should appear"
if t1 not in html:
raise Exception(html)
if "auteur" not in html:
raise Exception(html)
if "comic titre" not in html:
raise Exception(html)
if "234" not in html:
raise Exception(html)

tives = [("quote", QuoteNode, quote_node,
visit_quote_node_rst, depart_quote_node_rst)]

rst = rst2html(content, # fLOG=fLOG,
writer="rst", keep_warnings=True,
directives=tives, extlinks={'issue': ('http://%s', '_issue_')})

with open(os.path.join(temp, "test_quote_comic.rst"), "w", encoding="utf8") as f:
f.write(rst)

t1 = "this code should appear"
if t1 not in rst:
raise Exception(rst)
if "auteur" not in rst:
raise Exception(rst)
if "comic titre" not in rst:
raise Exception(rst)
if "234" not in rst:
raise Exception(rst)
if ".. quote::" not in rst:
raise Exception(rst)
if ":author: auteur" not in rst:
raise Exception(rst)

def test_quote_disc(self):
from docutils import nodes as skip_

content = """
.. quote::
:author: auteur
:disc: disc titre
:lid: label1
:pages: 234
:year: 2018
:title1: true

this code should appear___

next
""".replace(" ", "")
if sys.version_info[0] >= 3:
content = content.replace('u"', '"')

tives = [("quote", QuoteNode, quote_node,
visit_quote_node, depart_quote_node)]

html = rst2html(content, # fLOG=fLOG,
writer="html", keep_warnings=True,
directives=tives, extlinks={'issue': ('http://%s', '_issue_')})

temp = get_temp_folder(__file__, "temp_quote_disc", clean=False)
with open(os.path.join(temp, "test_quote_disc.html"), "w", encoding="utf8") as f:
f.write(html)

t1 = "this code should appear"
if t1 not in html:
raise Exception(html)
if "auteur" not in html:
raise Exception(html)
if "disc titre" not in html:
raise Exception(html)
if "234" not in html:
raise Exception(html)

tives = [("quote", QuoteNode, quote_node,
visit_quote_node_rst, depart_quote_node_rst)]

rst = rst2html(content, # fLOG=fLOG,
writer="rst", keep_warnings=True,
directives=tives, extlinks={'issue': ('http://%s', '_issue_')})

with open(os.path.join(temp, "test_quote_disc.rst"), "w", encoding="utf8") as f:
f.write(rst)

t1 = "this code should appear"
if t1 not in rst:
raise Exception(rst)
if "auteur" not in rst:
raise Exception(rst)
if "disc titre" not in rst:
raise Exception(rst)
if "234" not in rst:
raise Exception(rst)
if ".. quote::" not in rst:
raise Exception(rst)
if ":author: auteur" not in rst:
raise Exception(rst)


if __name__ == "__main__":
unittest.main()
52 changes: 41 additions & 11 deletions src/pyquickhelper/sphinxext/sphinx_quote_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from docutils.parsers.rst.directives.admonitions import BaseAdmonition
from docutils.statemachine import StringList
from sphinx.util.nodes import nested_parse_with_titles
from ..texthelper.texts_language import TITLES


class quote_node(nodes.admonition):
Expand All @@ -26,7 +27,7 @@ class QuoteNode(BaseAdmonition):
It takes the following options:

* *author*
* *book* or *manga* or *film* or *show*
* *book* or *manga* or *film* or *show* or *disc* or *comic*
* *year*
* *pages*
* *tag*
Expand Down Expand Up @@ -60,6 +61,8 @@ class QuoteNode(BaseAdmonition):
'author': directives.unchanged,
'book': directives.unchanged,
'manga': directives.unchanged,
'disc': directives.unchanged,
'comic': directives.unchanged,
'show': directives.unchanged,
'film': directives.unchanged,
'year': directives.unchanged,
Expand All @@ -83,6 +86,8 @@ def run(self):
docname = None if env is None else env.docname
if docname is not None:
docname = docname.replace("\\", "/").split("/")[-1]
language_code = self.state.document.settings.language_code if hasattr(
self.state.document.settings, "language_code") else "en"

if not self.options.get('class'):
self.options['class'] = ['admonition-quote']
Expand All @@ -106,6 +111,8 @@ def __(text):
author = __(self.options.get('author', "").strip())
book = __(self.options.get('book', "").strip())
manga = __(self.options.get('manga', "").strip())
comic = __(self.options.get('comic', "").strip())
disc = __(self.options.get('disc', "").strip())
film = __(self.options.get('film', "").strip())
show = __(self.options.get('show', "").strip())
pages = __(self.options.get('pages', "").strip())
Expand All @@ -127,37 +134,58 @@ def __(text):
tnl = [] # pragma: no cover

if title1:
if comic:
tnl.append("**{0}**".format(comic))
if disc:
tnl.append("**{0}**".format(disc))
if book:
tnl.append("**{0}**".format(book))
indexes.append(book)
if manga:
tnl.append("**{0}**".format(manga))
indexes.append(manga)
if show:
tnl.append("**{0}**".format(show))
indexes.append(show)
if film:
tnl.append("**{0}**".format(film))
indexes.append(film)
if author:
tnl.append("*{0}*, ".format(author))
indexes.append(author)
else:
if author:
tnl.append("**{0}**, ".format(author))
indexes.append(author)
if comic:
tnl.append("*{0}*".format(comic))
if disc:
tnl.append("*{0}*".format(disc))
if book:
tnl.append("*{0}*".format(book))
indexes.append(book)
if manga:
tnl.append("*{0}*".format(manga))
indexes.append(manga)
if show:
tnl.append("*{0}*".format(show))
indexes.append(show)
if film:
tnl.append("*{0}*".format(film))
indexes.append(film)

if author:
indexes.append(author)
indexes.append(TITLES[language_code]['author'] + "; " + author)
if comic:
indexes.append(comic)
indexes.append(TITLES[language_code]['comic'] + "; " + comic)
if disc:
indexes.append(disc)
indexes.append(TITLES[language_code]['disc'] + "; " + disc)
if book:
indexes.append(book)
indexes.append(TITLES[language_code]['book'] + "; " + book)
if manga:
indexes.append(manga)
indexes.append(TITLES[language_code]['manga'] + "; " + manga)
if show:
indexes.append(show)
indexes.append(TITLES[language_code]['show'] + "; " + show)
if film:
indexes.append(film)
indexes.append(TITLES[language_code]['film'] + "; " + film)

if pages:
tnl.append(", {0}".format(pages))
if date:
Expand Down Expand Up @@ -192,6 +220,8 @@ def __(text):
node['source'] = source
node['book'] = book
node['manga'] = manga
node['disc'] = disc
node['comic'] = comic
node['film'] = film
node['show'] = show
node['index'] = index
Expand Down
14 changes: 14 additions & 0 deletions src/pyquickhelper/texthelper/texts_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
TITLES = {
'en': {
'allblogs': 'All blog posts',
'author': 'author',
'blocref_node': '',
'blog_entry': 'The original entry is located in <<%s>>, line %d and can be found ',
'blogpost': 'blogpost',
'book': 'book',
'brefmes': '(<<%s>> : %s, line %d)',
'by category:': 'By category:',
'by month:': 'By month:',
Expand All @@ -18,12 +20,15 @@
'changes': 'Changes',
'cmdmes': '(<<%s>> : %s, line %d)',
'code': 'code',
'comic': 'comic',
'download': 'download',
'disc': 'disc',
'exmes': '(<<%s>> : %s, line %d)',
'exref_node': 'Examples',
'FAQ': 'FAQ',
'faqmes': '(<<%s>> : %s, line %d)',
'faqref_node': 'FAQ',
'film': 'movie',
'glossary': 'Glossary',
'hide': 'hide',
'In': '<<<',
Expand All @@ -32,6 +37,7 @@
'main': 'blog list',
'main2': 'blog main page',
'main_title': 'blog page',
'manga': 'manga',
'mathdef_node': '',
'mathmes': '(<<%s>> : %s, line %d)',
'more': 'post',
Expand All @@ -42,6 +48,7 @@
'Out2': 'Raw',
'outl': 'output',
'page1': 'first page',
'show': 'show',
'toc': 'Contents',
'toc0': 'Links',
'toc1': 'Information',
Expand All @@ -53,9 +60,11 @@
},
'fr': {
'allblogs': 'Tous les articles de blog',
'author': 'auteur',
'blocref_node': '',
'blog_entry': 'Source <<%s>>, line %d and can be found ',
'blogpost': 'article',
'book': 'livre',
'brefmes': '(<<%s>> : %s, ligne %d)',
'by category:': 'Par catégorie :',
'by month:': 'Par mois :',
Expand All @@ -64,12 +73,15 @@
'changes': 'Changements',
'cmdmes': '(<<%s>> : %s, line %d)',
'code': 'code',
'comic': 'bande dessinée',
'disc': 'disque',
'download': 'télécharger',
'exmes': '(<<%s>> : %s, ligne %d)',
'exref_node': 'Exemples',
'FAQ': 'FAQ',
'faqmes': '(<<%s>> : %s, ligne %d)',
'faqref_node': 'FAQ',
'film': 'film',
'glossary': 'Glossaire',
'hide': 'cacher',
'In': '<<<',
Expand All @@ -78,6 +90,7 @@
'main': "liste d'articles du blog",
'main2': 'page principale du blog',
'main_title': 'page de blog',
'manga': 'dessin animé',
'mathdef_node': '',
'mathmes': '(<<%s>> : %s, ligne %d)',
'more': 'article',
Expand All @@ -88,6 +101,7 @@
'Out2': 'Sortie brute',
'outl': 'la sortie',
'page1': 'première page',
'show': 'série',
'toc': 'Contenu',
'toc0': 'Liens',
'toc1': 'Information',
Expand Down