MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / is_markup_text

Function is_markup_text

src/textcode/markup.py:79–105  ·  view source on GitHub ↗

Return True if ``text`` is likely markup.

(text)

Source from the content-addressed store, hash-verified

77
78
79def is_markup_text(text):
80 """
81 Return True if ``text`` is likely markup.
82 """
83 if text.startswith("<"):
84 return True
85
86 # count whitespaces
87 no_spaces = "".join(text.split())
88
89 # count opening and closing tags_count
90 counts = Counter(c for c in no_spaces if c in "<>")
91
92 if not all(c in counts for c in "<>"):
93 return False
94
95 if not all(counts.values()):
96 return False
97
98 # ~ 5 percent of tag <> markers measn we have tags
99 has_tags = sum(counts.values()) / len(no_spaces) > 0.05
100
101 # check if we have some significant proportion of tag-like characters
102 open_close = counts[">"] / counts["<"]
103 # ratio of open to close tags should approach 1: accept a 20% drift
104 balanced = abs(1 - open_close) < 0.2
105 return has_tags and balanced
106
107
108def is_kept_tag(

Callers 3

prepare_textFunction · 0.90
clean_textFunction · 0.90
is_markupFunction · 0.85

Calls 3

joinMethod · 0.45
splitMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected