MCPcopy Index your code
hub / github.com/unclecode/crawl4ai / handle_emphasis

Method handle_emphasis

crawl4ai/html2text/__init__.py:237–308  ·  view source on GitHub ↗

Handles various text emphases

(
        self, start: bool, tag_style: Dict[str, str], parent_style: Dict[str, str]
    )

Source from the content-addressed store, hash-verified

235 return None
236
237 def handle_emphasis(
238 self, start: bool, tag_style: Dict[str, str], parent_style: Dict[str, str]
239 ) -> None:
240 """
241 Handles various text emphases
242 """
243 tag_emphasis = google_text_emphasis(tag_style)
244 parent_emphasis = google_text_emphasis(parent_style)
245
246 # handle Google's text emphasis
247 strikethrough = "line-through" in tag_emphasis and self.hide_strikethrough
248
249 # google and others may mark a font's weight as `bold` or `700`
250 bold = False
251 for bold_marker in config.BOLD_TEXT_STYLE_VALUES:
252 bold = bold_marker in tag_emphasis and bold_marker not in parent_emphasis
253 if bold:
254 break
255
256 italic = "italic" in tag_emphasis and "italic" not in parent_emphasis
257 fixed = (
258 google_fixed_width_font(tag_style)
259 and not google_fixed_width_font(parent_style)
260 and not self.pre
261 )
262
263 if start:
264 # crossed-out text must be handled before other attributes
265 # in order not to output qualifiers unnecessarily
266 if bold or italic or fixed:
267 self.emphasis += 1
268 if strikethrough:
269 self.quiet += 1
270 if italic:
271 self.o(self.emphasis_mark)
272 self.drop_white_space += 1
273 if bold:
274 self.o(self.strong_mark)
275 self.drop_white_space += 1
276 if fixed:
277 self.o("`")
278 self.drop_white_space += 1
279 self.code = True
280 else:
281 if bold or italic or fixed:
282 # there must not be whitespace before closing emphasis mark
283 self.emphasis -= 1
284 self.space = False
285 if fixed:
286 if self.drop_white_space:
287 # empty emphasis, drop it
288 self.drop_white_space -= 1
289 else:
290 self.o("`")
291 self.code = False
292 if bold:
293 if self.drop_white_space:
294 # empty emphasis, drop it

Callers 1

handle_tagMethod · 0.95

Calls 3

oMethod · 0.95
google_text_emphasisFunction · 0.85
google_fixed_width_fontFunction · 0.85

Tested by

no test coverage detected