Coverage for src/ptf/cmds/xml/jats/builder/issue.py: 37%
37 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-05 09:56 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-05 09:56 +0000
1"""
2Creates Jats xmls.
3Used by `crawler` and `ptf.cmds.xml.jats.jats_parser`
4"""
6from ptf.cmds.xml.xml_utils import escape
9def get_single_title_xml(title: str):
10 has_italic = title.find("<i>") > -1 and title.find("</i>") > -1
11 has_superscript = title.find("<sup>") > -1 and title.find("</sup>") > -1
12 has_subscript = title.find("<sub>") > -1 and title.find("</sub>") > -1
14 if has_italic: 14 ↛ 15line 14 didn't jump to line 15 because the condition on line 14 was never true
15 title = title.replace("<i>", "|||i|||").replace("</i>", "|||/i|||")
16 if has_superscript: 16 ↛ 17line 16 didn't jump to line 17 because the condition on line 16 was never true
17 title = title.replace("<sup>", "|||sup|||").replace("</sup>", "|||/sup|||")
18 if has_subscript: 18 ↛ 19line 18 didn't jump to line 19 because the condition on line 18 was never true
19 title = title.replace("<sub>", "|||sub|||").replace("</sub>", "|||/sub|||")
21 title = escape(title)
23 if has_italic: 23 ↛ 24line 23 didn't jump to line 24 because the condition on line 23 was never true
24 title = title.replace("|||i|||", "<italic>").replace("|||/i|||", "</italic>")
26 if has_superscript: 26 ↛ 27line 26 didn't jump to line 27 because the condition on line 26 was never true
27 title = title.replace("|||sup|||", "<sup>").replace("|||/sup|||", "</sup>")
29 if has_subscript: 29 ↛ 30line 29 didn't jump to line 30 because the condition on line 29 was never true
30 title = title.replace("|||sub|||", "<sub>").replace("|||/sub|||", "</sub>")
32 return title
35def get_title_xml(title: str, trans_title=None, trans_lang=None, with_tex_values=True):
36 """
37 Get the title_xml given a simple title
38 If the title has formulas, use CKeditorParser first, then call this function with the value_xml returned by the parser
39 and set with_tex_values to False
40 TODO: enhance CkeditorParser to accept both title and trans_title to build the xml in 1 shot.
41 """
42 if with_tex_values:
43 title = get_single_title_xml(title)
45 xml = '<title-group xmlns:xlink="http://www.w3.org/1999/xlink">'
46 xml += f'<article-title xml:space="preserve">{title}</article-title>'
48 if trans_title and trans_lang:
49 if with_tex_values:
50 trans_title = get_single_title_xml(trans_title)
51 xml += f'<trans-title-group xml:lang="{trans_lang}"><trans-title>{trans_title}</trans-title></trans-title-group>'
53 xml += "</title-group>"
55 return xml
58def get_issue_title_xml(title: str, lang: str, trans_title=None, trans_lang=None):
59 """
60 Get the title_xml given a simple title
61 """
62 title = get_single_title_xml(title)
63 xml = f'<issue-title xml:lang="{lang}" xml:space="preserve">{title}</issue-title>'
65 if trans_title and trans_lang:
66 trans_title = get_single_title_xml(trans_title)
67 xml += f'<issue-title xml:lang="{trans_lang}" xml:space="preserve">{trans_title}</issue-title>'
69 return xml
72# def get_name_params(first_name, last_name, prefix, suffix, orcid):
73# params = {
74# "first_name": first_name,
75# "last_name": last_name,
76# "prefix": prefix,
77# "suffix": suffix,
78# "orcid": orcid,
79# }
80# helper_update_name_params(params)
81# return params