diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2015-10-03 16:43:44 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2015-10-03 16:43:44 +0200 |
| commit | 23b9dbd75bcfd976f2912cf074719ca7a1a4a717 (patch) | |
| tree | 8b2e0a26be39721aad516394a4a6677199f488a1 | |
| parent | 677f68bd92951d05c6e2ac5f83f17edc62bede75 (diff) | |
| download | ankivoc-23b9dbd75bcfd976f2912cf074719ca7a1a4a717.tar.gz ankivoc-23b9dbd75bcfd976f2912cf074719ca7a1a4a717.zip | |
always show examples and synonyms
| -rw-r--r-- | ankivoc.py | 47 |
1 files changed, 4 insertions, 43 deletions
@@ -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 += "<br/>" |
