Skip to content

Commit

Permalink
fix BoboTiG#1478: Fix '!' template handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lasconic committed Jan 5, 2023
1 parent 3374d84 commit c58a643
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions wikidict/lang/fr/template_handlers.py
Expand Up @@ -14,6 +14,7 @@
term,
underline,
)
from ...utils import process_special_pipe_template
from .. import defaults
from .langs import langs

Expand Down Expand Up @@ -221,7 +222,7 @@ def render_cf(tpl: str, parts: List[str], data: Dict[str, str]) -> str:
'→ voir <i>triner</i>'
>>> render_cf("cf", ["in-", "extinguible"], defaultdict(str, {"lang": "fr"}))
'→ voir <i>in-</i> et <i>extinguible</i>'
>>> render_cf("cf", ["enfant", "de", "vierge!vierge Marie"], defaultdict(str, {"lang": "fr"}))
>>> render_cf("cf", ["enfant", "de", "vierge##pipe##!##pipe##vierge Marie"], defaultdict(str, {"lang": "fr"}))
'→ voir <i>enfant</i>, <i>de</i> et <i>vierge Marie</i>'
>>> render_cf("cf", [":Catégorie:Bruits en français"], defaultdict(str))
''
Expand All @@ -234,8 +235,7 @@ def render_cf(tpl: str, parts: List[str], data: Dict[str, str]) -> str:
s_array = []
for p in parts:
s_phrase = p
if "!" in s_phrase:
s_phrase = s_phrase.split("!")[1]
s_phrase = process_special_pipe_template(s_phrase)
s_array.append(italic(s_phrase))
phrase += f" {concat(s_array, ', ', ' et ')}"
return phrase
Expand Down
7 changes: 7 additions & 0 deletions wikidict/utils.py
Expand Up @@ -61,6 +61,13 @@
}


def process_special_pipe_template(text: str) -> str:
splitter = SPECIAL_TEMPLATES["{{!}}"].placeholder
if splitter in text:
text = text.split(splitter)[1]
return text


def convert_gender(genders: List[str]) -> str:
"""Return the HTML code to include for gender(s) of a word."""
if not genders:
Expand Down

0 comments on commit c58a643

Please sign in to comment.