Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/turbohtml/extract/_article.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

17 statements  

1""" 

2The Article record :meth:`turbohtml.Node.article` returns. 

3 

4The content scoring and metadata harvesting all live in the C core (``turbohtml._html``), exposed as the 

5:meth:`~turbohtml.Node.article` method. The core builds one :class:`Article` per call; importing this module registers 

6the record type with it. 

7""" 

8 

9from __future__ import annotations 

10 

11from typing import NamedTuple 

12 

13from turbohtml._html import Element, _register_article # Element stays importable so autodoc resolves it 

14 

15 

16class Article(NamedTuple): 

17 """ 

18 The dominant content of a document and the metadata harvested beside it. 

19 

20 ``element`` is the scored content body (``None`` when nothing reads as content) and ``text`` its layout-aware plain 

21 text (empty then). ``title``, ``byline``, ``date``, ``description``, ``lang``, ``canonical`` (the ``<link 

22 rel=canonical>`` URL or ``og:url``), ``site_name`` (``og:site_name`` or ``<meta name=application-name>``) and 

23 ``image`` (the ``og:image`` or ``twitter:image`` lead image) are single-valued page metadata, each 

24 whitespace-normalized or ``None`` when the source is absent. ``tags`` collects every ``<meta name=keywords>`` value 

25 (comma-split) and ``article:tag`` in document order, an empty tuple when none appear. This makes 

26 :meth:`~turbohtml.Node.article` a one-call replacement for trafilatura and newspaper3k. 

27 """ 

28 

29 element: Element | None 

30 text: str 

31 title: str | None 

32 byline: str | None 

33 date: str | None 

34 description: str | None 

35 lang: str | None 

36 canonical: str | None 

37 site_name: str | None 

38 tags: tuple[str, ...] 

39 image: str | None 

40 

41 

42_register_article(Article)