Strips HTML tags, whitespace and wiki markup from the HTML source, including: metadata, info box, table of contents, annotations, thumbnails, disambiguation link. This is called internally from MediaWikiArticle.string.
(self, string, **kwargs)
| 1774 | setattr(self, k, v) |
| 1775 | |
| 1776 | def _plaintext(self, string, **kwargs): |
| 1777 | """ Strips HTML tags, whitespace and wiki markup from the HTML source, including: |
| 1778 | metadata, info box, table of contents, annotations, thumbnails, disambiguation link. |
| 1779 | This is called internally from MediaWikiArticle.string. |
| 1780 | """ |
| 1781 | s = string |
| 1782 | s = strip_between("<table class=\"metadata", "</table>", s) # Metadata. |
| 1783 | s = strip_between("<table id=\"toc", "</table>", s) # Table of contents. |
| 1784 | s = strip_between("<table class=\"infobox", "</table>", s) # Infobox. |
| 1785 | s = strip_between("<table class=\"wikitable", "</table>", s) # Table. |
| 1786 | s = strip_element(s, "table", "class=\"navbox") # Navbox. |
| 1787 | s = strip_between("<div id=\"annotation", "</div>", s) # Annotations. |
| 1788 | s = strip_between("<div class=\"dablink", "</div>", s) # Disambiguation message. |
| 1789 | s = strip_between("<div class=\"magnify", "</div>", s) # Thumbnails. |
| 1790 | s = strip_between("<div class=\"thumbcaption", "</div>", s) # Thumbnail captions. |
| 1791 | s = re.sub(r"<img class=\"tex\".*?/>", "[math]", s) # LaTex math images. |
| 1792 | s = plaintext(s, **kwargs) |
| 1793 | s = re.sub(r"\[edit\]\s*", "", s) # [edit] is language dependent (e.g. nl => "[bewerken]") |
| 1794 | s = s.replace("[", " [").replace(" [", " [") # Space before inline references. |
| 1795 | return s |
| 1796 | |
| 1797 | def plaintext(self, **kwargs): |
| 1798 | return self._plaintext(self.source, **kwargs) |
no test coverage detected