1616else :
1717 from sphinx .util .osutil import _chdir as chdir
1818
19- _MSGID_PATTERN = re .compile (r'msgid "(.*)"' )
19+ _MSGID_PATTERN = re .compile (r'msgid "((?:\n|.)*?)"\nmsgstr' , re . MULTILINE )
2020
2121
22- def msgid_getter (msgid ):
23- if m := _MSGID_PATTERN .search (msgid ):
24- return m [1 ]
25- return None
22+ def get_msgids (pot ):
23+ matches = _MSGID_PATTERN .findall (pot )
24+ return [m .replace ('"\n "' , '' ) for m in matches [1 :]]
2625
2726
2827def test_Catalog_duplicated_message ():
@@ -105,7 +104,7 @@ def test_gettext_index_entries(app):
105104 app .build (filenames = [app .srcdir / 'index_entries.txt' ])
106105
107106 pot = (app .outdir / 'index_entries.pot' ).read_text (encoding = 'utf8' )
108- msg_ids = list ( filter ( None , map ( msgid_getter , pot . splitlines ())) )
107+ msg_ids = get_msgids ( pot )
109108
110109 assert msg_ids == [
111110 "i18n with index entries" ,
@@ -134,7 +133,7 @@ def test_gettext_disable_index_entries(app):
134133 app .build (filenames = [app .srcdir / 'index_entries.txt' ])
135134
136135 pot = (app .outdir / 'index_entries.pot' ).read_text (encoding = 'utf8' )
137- msg_ids = list ( filter ( None , map ( msgid_getter , pot . splitlines ())) )
136+ msg_ids = get_msgids ( pot )
138137
139138 assert msg_ids == [
140139 "i18n with index entries" ,
@@ -200,7 +199,7 @@ def test_gettext_prolog_epilog_substitution(app):
200199
201200 assert (app .outdir / 'prolog_epilog_substitution.pot' ).is_file ()
202201 pot = (app .outdir / 'prolog_epilog_substitution.pot' ).read_text (encoding = 'utf8' )
203- msg_ids = list ( filter ( None , map ( msgid_getter , pot . splitlines ())) )
202+ msg_ids = get_msgids ( pot )
204203
205204 assert msg_ids == [
206205 "i18n with prologue and epilogue substitutions" ,
@@ -227,9 +226,43 @@ def test_gettext_prolog_epilog_substitution_excluded(app):
227226
228227 assert (app .outdir / 'prolog_epilog_substitution_excluded.pot' ).is_file ()
229228 pot = (app .outdir / 'prolog_epilog_substitution_excluded.pot' ).read_text (encoding = 'utf8' )
230- msg_ids = list ( filter ( None , map ( msgid_getter , pot . splitlines ())) )
229+ msg_ids = get_msgids ( pot )
231230
232231 assert msg_ids == [
233232 "i18n without prologue and epilogue substitutions" ,
234233 "This is content that does not include prologue and epilogue substitutions." ,
235234 ]
235+
236+
237+ @pytest .mark .sphinx (
238+ 'gettext' , srcdir = 'gettext' ,
239+ confoverrides = {'gettext_compact' : False ,
240+ 'gettext_additional_targets' : ['literal-block' , 'doctest-block' ]})
241+ def test_gettext_literalblock_additional (app ):
242+ app .build (force_all = True )
243+
244+ assert (app .outdir / 'literalblock.pot' ).is_file ()
245+ pot = (app .outdir / 'literalblock.pot' ).read_text (encoding = 'utf8' )
246+ msg_ids = get_msgids (pot )
247+
248+ assert msg_ids == [
249+ 'i18n with literal block' ,
250+ 'Correct literal block::' ,
251+ 'this is\\ nliteral block' ,
252+ 'Missing literal block::' ,
253+ "That's all." ,
254+ 'included raw.txt' ,
255+ '===\\ nRaw\\ n===\\ n\\ n.. raw:: html\\ n\\ n <iframe src=\\ "https://sphinx-doc.org\\ "></iframe>\\ n\\ n' ,
256+ 'code blocks' ,
257+ "def main\\ n 'result'\\ nend" ,
258+ '#include <stdlib.h>\\ nint main(int argc, char** argv)\\ n{\\ n return 0;\\ n}' ,
259+ 'example of C language' ,
260+ '#include <stdio.h>\\ nint main(int argc, char** argv)\\ n{\\ n return 0;\\ n}' ,
261+ 'literal-block\\ nin list' ,
262+ 'test_code_for_noqa()\\ ncontinued()' ,
263+ 'doctest blocks' ,
264+ '>>> import sys # sys importing\\ n>>> def main(): # define main '
265+ "function\\ n... sys.stdout.write('hello') # call write method of "
266+ "stdout object\\ n>>>\\ n>>> if __name__ == '__main__': # if run this py "
267+ 'file as python script\\ n... main() # call main' ,
268+ ]
0 commit comments