MCPcopy Index your code
hub / github.com/clips/pattern / _plaintext

Method _plaintext

pattern/web/__init__.py:1776–1795  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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)

Callers 2

plaintextMethod · 0.95
plaintextMethod · 0.80

Calls 3

strip_betweenFunction · 0.85
strip_elementFunction · 0.85
plaintextFunction · 0.85

Tested by

no test coverage detected