JBrowser Source Docs

jbrowser.engine.reader

Generated from the source code of JBrowser 2.0.3.

jbrowser/engine/reader.py · 153 lines

Reading mode: finds out whether a page is an article and pulls the article out of it.

Both steps use Mozilla's Readability (the engine behind Firefox Reader View), vendored in engine/vendor/readability under the Apache License 2.0. The scripts run in JBrowser's isolated world (BRIDGE_WORLD): they read the page's DOM, the page can't see or change them. The article is shown by ui/reader_view.py in a separate page where no script from the website can run.

Constants#

Name Value
VENDOR Path(__file__).with_name('vendor') / 'readability'
MIN_ARTICLE_CHARS 900
FONTS {'serif': "Charter, 'Bitstream Charter', 'Sitka Text', Cambria, Georgia, serif", 'sans'…
THEMES ('auto', 'light', 'sepia', 'dark')
ZOOM_STEPS (0.8, 0.9, 1.0, 1.1, 1.2, 1.35, 1.5, 1.7)
MAX_HTML 1900000

Functions#

available#

available() -> boolsource

readerable_js#

readerable_js() -> strsource

Evaluates to true when the page is probably an article.

extract_js#

extract_js() -> strsource

Evaluates to a JSON string with the article (title, byline, content, ...) or null.

parse_result#

parse_result(result) -> dict | Nonesource

reading_minutes#

reading_minutes(chars: int) -> intsource

About 1300 characters (~230 words) a minute, a typical silent-reading speed.

render#

render(article: dict, url: str, font: str, theme: str, dark_app: bool, accent: str) -> strsource

The reading-mode page. The site's HTML has already been cleaned by Readability; the CSP below also stops any script, frame, form or plugin that might be left.

classes#

classes(font: str, theme: str, dark_app: bool) -> strsource