parseidon-headings-plugin 1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,83 @@
1
+ import re
2
+
3
+ import pluggy
4
+ from parseidon.handlers.content import PagePositionContext
5
+
6
+ hookimpl = pluggy.HookimplMarker(project_name="parseidon")
7
+
8
+
9
+ class RemoveHeadingPlugin:
10
+ @hookimpl
11
+ def post_process_content(self, output):
12
+ """
13
+ Hook for post processing the output from content_handler
14
+
15
+ Parameters:
16
+ output: list of tuples containing documents and their contents
17
+
18
+ Returns:
19
+ The post processed content_handler output, without
20
+ IPv4-like headings
21
+ """
22
+ for _, list_of_contents in output:
23
+ potential_headings = set()
24
+ for content in list_of_contents:
25
+ if isinstance(content.context, PagePositionContext):
26
+ content, potential_headings = self.process_wordlist(
27
+ content, potential_headings
28
+ )
29
+
30
+ content, potential_headings = self.process_content_string(
31
+ content, potential_headings
32
+ )
33
+
34
+ return output
35
+
36
+ def process_wordlist(self, content, potential_headings):
37
+ """
38
+ Helper for processing words in text-output mode
39
+
40
+ Parameters:
41
+ content: Content
42
+
43
+ Returns: Content without IPv4-like headings
44
+ """
45
+ words = content.context.words
46
+ heading_re = re.compile(r"(\d{1,2}\.)*\d{1,2}\.?")
47
+ prev = "\n"
48
+ for ix, word in enumerate(words):
49
+ word_text = word[0].strip().strip(".")
50
+ if heading_re.match(word_text) and prev.endswith("\n"):
51
+ parent = word_text.rsplit(".", 1)[0]
52
+ if parent == word_text:
53
+ potential_headings.add(word_text)
54
+ continue
55
+ if parent in potential_headings:
56
+ potential_headings.add(word_text)
57
+ words[ix] = ("", [])
58
+ prev = word[0]
59
+ return content, potential_headings
60
+
61
+ def process_content_string(self, content, potential_headings):
62
+ """
63
+ Helper for processing words in text-output mode
64
+
65
+ Parameters:
66
+ content: Content
67
+
68
+ Returns: Content without IPv4-like headings
69
+ """
70
+ text = content.content
71
+ heading_re = re.compile(r"(?:(?<=\n)|^)(\d{1,2}\.)*\d{1,2}(?=(\.?(\s+|$)))")
72
+ for match in heading_re.finditer(text):
73
+ word = match.group()
74
+ word_text = word.strip().strip(".")
75
+ parent = word_text.rsplit(".", 1)[0]
76
+ if word_text == parent:
77
+ potential_headings.add(word_text)
78
+ continue
79
+ if parent in potential_headings:
80
+ potential_headings.add(word_text)
81
+ text = re.sub(word, "\u200b" * len(word), text, 1)
82
+ content.content = text
83
+ return content, potential_headings
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.4
2
+ Name: parseidon-headings-plugin
3
+ Version: 1.2
4
+ Summary: Plugin removing IPv4-like headings in documents for parseidon
5
+ Author-email: Parseidon Dev Team <parseidon@foi.se>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/CrateOrg/parseidon
8
+ Project-URL: Repository, https://github.com/CrateOrg/parseidon
9
+ Requires-Python: >=3.9
10
+ Requires-Dist: parseidon>=2.2.6
@@ -0,0 +1,6 @@
1
+ parseidon_headings_plugin/remove_headings.py,sha256=f4pNWX7RGR1HOYhQiOClUMfoGsy-z9ACTHWNw582zOc,2841
2
+ parseidon_headings_plugin-1.2.dist-info/METADATA,sha256=nsD-koTymlHqAd2Boe3McHspHwCkaxrs7FwmbIjbN8g,382
3
+ parseidon_headings_plugin-1.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
4
+ parseidon_headings_plugin-1.2.dist-info/entry_points.txt,sha256=xFe7uIzv4UxVaLtH3Pqa7xIH1jxRq8fayiycZgjLAg8,100
5
+ parseidon_headings_plugin-1.2.dist-info/top_level.txt,sha256=ZO3NekDA1gCKA0Qd_DfCTbocfJLghc0l53fGCl5K_FM,26
6
+ parseidon_headings_plugin-1.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [parseidon.plugins]
2
+ headings_plugin = parseidon_headings_plugin.remove_headings:RemoveHeadingPlugin
@@ -0,0 +1 @@
1
+ parseidon_headings_plugin