From 23b9dbd75bcfd976f2912cf074719ca7a1a4a717 Mon Sep 17 00:00:00 2001 From: schneefux Date: Sat, 3 Oct 2015 16:43:44 +0200 Subject: always show examples and synonyms --- ankivoc.py | 47 ++++------------------------------------------- 1 file changed, 4 insertions(+), 43 deletions(-) (limited to 'ankivoc.py') diff --git a/ankivoc.py b/ankivoc.py index da8adb2..00ea9b9 100644 --- a/ankivoc.py +++ b/ankivoc.py @@ -20,52 +20,14 @@ def lookup(word): el.extract() # remove annyoing link - for el in res.find_all("a", class_="moreInformationSynonyms"): + for el in res.find_all("a", class_="moreInformationSynonyms") + \ + res.find_all("a", class_="moreInformationExemples"): el.extract() for sense in res.find_all("div", class_="msDict"): - # prepare example sentences for "more" tag - # The class typo is real. - for el in sense.find_all("a", class_="moreInformationExemples"): - #el.name = "button" # a - el["href"] = "#" - el["onclick"] = \ - "var els = this.parentNode.getElementsByTagName('ul')[0].getElementsByTagName('li');" + \ - "for(var c = 0; c < els.length; c++){" + \ - "if (els[c].getAttribute('data-toggled') == 'false') {" + \ - "els[c].style = 'display: none;';" + \ - "els[c].setAttribute('data-toggled', 'true');" + \ - "} else {" + \ - "els[c].style = '';" + \ - "els[c].setAttribute('data-toggled', 'false');" + \ - "}" + \ - "}" - el.string = "Examples…" - el.insert_before(soup.new_tag("br")) - # transform div structure into 'examples'-like list for el in sense.find_all(class_="entrySynList"): el.name = "ul" - moretag = soup.new_tag("a") - moretag.string = "Synonyms…" - moretag["href"] = "#" - moretag["protect"] = "" # mark - # important: use the 'ul' at index 1 for synonyms - moretag["onclick"] = \ - "var els = this.parentNode.getElementsByTagName('ul')[1].getElementsByTagName('li');" + \ - "for(var c = 0; c < els.length; c++){" + \ - "if (els[c].getAttribute('data-toggled') == 'false') {" + \ - "els[c].style = 'display: none;';" + \ - "els[c].setAttribute('data-toggled', 'true');" + \ - "} else {" + \ - "els[c].style = '';" + \ - "els[c].setAttribute('data-toggled', 'false');" + \ - "}" + \ - "}" - - el.parent.a.insert_after(moretag) - moretag.insert_before(soup.new_tag("br")) - for syno in el.find_all("div"): syno.name = "li" @@ -73,8 +35,7 @@ def lookup(word): # simplify structure for el in sense.find_all("span") + \ - sense.find_all("div") + \ - sense.find_all("a"): + sense.find_all("div"): # skip "more" tags if "onclick" not in el.attrs: el.unwrap() @@ -86,7 +47,7 @@ def lookup(word): # hide examples for el in sense.find_all("li"): - el["style"] = "display: none;" + el["style"] = "font-size: 75%;" entry += str(sense) #.prettify(formatter="html") #entry += "
" -- cgit v1.3.1