Skip to content

Commit

Permalink
freedict: minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Dec 15, 2024
1 parent 7026b11 commit 694999e
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pyglossary/plugins/freedict/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,20 +498,20 @@ def writeGramGroups(

hf.write(ET.Element("br"))

def writeSenseGrams(
def writeGramGroupChildren(
self,
hf: T_htmlfile,
sense: Element,
elem: Element,
) -> None:
self.writeGramGroups(hf, sense.findall("gramGrp", NAMESPACE))
self.writeGramGroups(hf, elem.findall("gramGrp", NAMESPACE))

def writeSense(
self,
hf: T_htmlfile,
sense: Element,
) -> None:
# this <sense> element is 1st-level (directly under <entry>)
self.writeSenseGrams(hf, sense)
self.writeGramGroupChildren(hf, sense)
self.makeList(
hf,
sense.findall("sense", NAMESPACE),
Expand Down Expand Up @@ -597,7 +597,7 @@ def getEntryByElem( # noqa: PLR0912

glos = self._glos
keywords = []
f = BytesIO()
buff = BytesIO()
pron_color = self._pron_color

if self._discover:
Expand Down Expand Up @@ -629,7 +629,7 @@ def br() -> Element:
]
senseList = entry.findall("sense", NAMESPACE)

with ET.htmlfile(f, encoding="utf-8") as hf:
with ET.htmlfile(buff, encoding="utf-8") as hf:
with hf.element("div"):
if self._word_title:
for keyword in keywords:
Expand All @@ -654,10 +654,10 @@ def br() -> Element:
hf.write("\n")

hf_ = cast("T_htmlfile", hf)
self.writeGramGroups(hf_, entry.findall("gramGrp", NAMESPACE))
self.writeGramGroupChildren(hf_, entry)
self.writeSenseList(hf_, senseList)

defi = f.getvalue().decode("utf-8")
defi = buff.getvalue().decode("utf-8")
# defi = defi.replace("\xa0", "&nbsp;") # do we need to do this?
file = self._file
return self._glos.newEntry(
Expand Down

0 comments on commit 694999e

Please sign in to comment.