gofasthtml

package module
v0.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 37 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-fast-html

Extracts HTML, Markdown, plain text, EPUB, comma- and tab-separated values (CSV, TSV), Jupyter notebooks, JSON and YAML (cut along their structure, records as tables), web pages saved as one file (MHTML, .mht), and subtitles and captions (SubRip .srt, WebVTT .vtt) into the shared go-fast document model, gofastcore.Document (github.com/AOShei/go-fast-core). Standard library and go-fast-core only.

import "github.com/AOShei/go-fast-html" // package gofasthtml

doc, err := gofasthtml.ExtractFile(ctx, "page.html", nil)
if err != nil { ... }
fmt.Print(doc.Markdown())

Source.Format is html, md, txt, epub, csv, tsv, ipynb, json, yaml, mht, srt or vtt. Extractor.Format sets the format; when it is empty, Detect decides it from Options.Name (.html, .htm, .xhtml, .shtml; .md, .markdown, .mdown, .mkd, .mkdn, .mdwn, .mdc, .qmd, .rmd; .txt, .text; .epub; .csv; .tsv, .tab; .ipynb; .json, .jsonl, .ndjson, .jsonlines, .geojson, .jsonc; .yaml, .yml; .mht, .mhtml; .srt; .vtt, .webvtt) and, failing that, from the content: a zip archive whose mimetype member comes first and says application/epub+zip is EPUB, a header of an MHTML file a browser saved is MHTML, input that begins (after a byte order mark) with WEBVTT followed by a space, a tab, a line end or nothing is WebVTT, input that begins with markup, or has a tag of a common HTML element in its first 4 KiB, is HTML, and anything else plain text. Markdown, CSV, notebooks, JSON, YAML and SubRip are never guessed from content, since reading plain text as Markdown takes characters out of it, a text with commas is not a table because of them, and a text is JSON, YAML or a notebook only by its name.

The command cmd/gofasthtml prints JSON, Markdown or text for files, directories and standard input (-); -as html|md|txt|epub|csv|tsv|ipynb|json|yaml|mht|srt|vtt sets the format, and -delimiter, -header and -no-quotes set Extractor.Delimiter, Extractor.Header and Extractor.NoQuotes, and -data-block-bytes sets Extractor.DataBlockBytes. It offers the render flags every go-fast command shares; they affect Markdown and text only, for the document and an EPUB's documents alike, and JSON always has everything:

Flag Effect in Markdown and text
-furniture include running headers and footers
-stored[=kinds] include stored data (data the file keeps but shows nowhere): all of it (-stored, =true, =all), or with =kinds (comma or +) only those kinds, wherever they are; =false or = turn it off. The kinds are core's gofastcore.StoredKindNames() (such as markup_comment, macro, stylesheet, manifest_item); any other name is an error listing them (exit status 2)
-part-markers put a line before each part saying which part it is
-children (default true) include embedded documents (an EPUB's documents beside its chapters), each after a line naming it ([child 1: name] in text); -children=false leaves them out
-exclude-display[=reasons] leave out what the file declares not displayed: all of it (alone, =true or =all), or only the reasons named (=hidden, =no_ink, =hidden,no_ink); =false or = is off, and any other value is an error

This library produces no running headers and footers itself; -furniture is there for the documents other extractors may return as children. Its stored part holds scripts, styles, <input type=hidden> values and EPUB images no chapter shows; markup comments are stored data too, kept where they stand. -stored=markup_comment shows the comments alone (Outlook's conditional comments, for example), -stored=macro the scripts, -stored=stylesheet the styles.

Speed and memory. On 9,835 pages of a web crawl the library is compared with nine Python and Rust extractors in bench/. For a batch, memory is reused from one document to the next: the input buffer and the tree's nodes and attributes go back to pools when a page is done, and nothing in a document refers to them (TestInputReused). Memory can be traded for speed with Go's garbage collector target, GOGC in the environment (or debug.SetGCPercent in a program); the command and the library use Go's default, 100, which uses the least memory. On the 9,835 pages (1.45 GiB), each read from disk as a pipeline does (wall time, peak memory):

GOGC One worker Peak 24 workers Peak
100 (default) 5.24 s 65 MB 0.77 s 355 MB
200 4.70 s 91 MB 0.64 s 690 MB
400 4.54 s 210 MB 0.59 s 1,008 MB

Status: v0.7.0 (2026-11-27). The changes are in CHANGELOG.md; the development history and the items still open are in IMPLEMENTATION_PLAN.md.

What is read

The library has its own HTML5 parser under internal/, since the standard library has none:

  • Encoding (go-fast-core's charset, the series' shared decoder), as the WHATWG encoding sniffing decides it: a byte order mark, then Extractor.Charset (command: -charset), then a <meta charset> or <meta http-equiv="Content-Type"> found by the prescan of the first 1024 bytes (of the first MiB when the input is not valid UTF-8: the standard's parser changes to an encoding a later <meta> declares, and a declaration is taken over a guess), then UTF-8 if the whole input is valid UTF-8 (and has no zero byte, see below); otherwise the encoding is recognised from the bytes when one is certain, and the input is refused when none is (Text that declares no encoding). Decoded are UTF-8, UTF-16LE, UTF-16BE, windows-1252 (following the Encoding standard, the ISO-8859-1 and US-ASCII labels are read as windows-1252), windows-874 (also iso-8859-11, tis-620), windows-1250 to windows-1258 (also cp1251, x-cp1251 and the like; iso-8859-9 and latin5 are windows-1254), macintosh, shift_jis (also sjis, ms932, windows-31j), gbk (also gb2312 and its labels), euc-kr (also ks_c_5601-1987, windows-949), big5, gb18030, euc-jp, ibm866, iso-8859-2 to iso-8859-8 (and iso-8859-8-i), iso-8859-10, iso-8859-13 to iso-8859-16, koi8-r, koi8-u, x-mac-cyrillic and iso-2022-jp, each with the labels the Encoding standard gives it. A document that declares any other encoding (utf-7, ...) is read as windows-1252, with the warning html.charset_unsupported.
  • Extractor.Charset is the encoding the input comes with from outside it, the transport-layer encoding of the sniffing algorithm, given as a label the way a MIME Content-Type charset parameter gives it (quotes are allowed): go-fast-email passes the charset of an HTML or text body this way. It applies to HTML, Markdown, plain text, CSV, TSV, JSON and YAML, not to the chapters of an EPUB, which declare their own. A byte order mark overrides it; it overrides <meta> and detection, so it is the way to read text whose encoding is not recognised, or is recognised wrongly. A label that names no encoding decoded here is ignored, with the warning html.charset_unsupported, and the encoding is decided as if it had not been given.
  • Text that declares no encoding: see the section of that name below.
  • Where the legacy encodings differ from the Encoding standard. The tables are go-fast-core's charset (its README, "Shared readers", and package documentation): Microsoft's code pages as the Unicode Consortium publishes them, not the standard's indexes, and the standard's decoding wherever a code page leaves a byte or a pair undefined. Big5 is code page 950, then, for the pairs 950 leaves undefined, Big5 with HKSCS as the standard's index has it (many of its characters are above U+FFFF), and the four pairs 0x8862, 0x8864, 0x88A3 and 0x88A5 decode to a letter and a combining mark as in the standard. GBK is code page 936, with byte 0x80 the euro sign as in the standard; gb18030 is decoded as the standard's GB18030 decoder does, with its four-byte sequences. EUC-JP and ISO-2022-JP are decoded as the standard does. Shift_JIS and EUC-KR are code pages 932 and 949, which agree with the standard on nearly all characters; Shift_JIS byte 0x80 is U+0080, and the user-defined areas of Shift_JIS and GBK are the Private Use Area characters the standard maps them to; those of EUC-KR are U+FFFD. The other single-byte encodings are the standard's indexes; its KOI8-U is KOI8-RU, with ў and Ў at 0xAE and 0xBE. macintosh is Apple's Mac OS Roman table (0xDB the euro sign). In the single-byte encodings, a byte from 0x80 to 0x9F the code page leaves undefined is the C1 control of the same value, as in the standard's indexes; any other undefined byte is U+FFFD. Bytes that are not a character are U+FFFD and counted in text.unmapped_glyphs; a lead byte followed by an ASCII byte that does not make a character gives U+FFFD and the ASCII byte is read again. Offsets in block locations point into the source bytes in every encoding.
  • Tokenizer (internal/lexer), following the WHATWG tokenization rules for data, RCDATA (title, textarea), RAWTEXT (style, xmp, iframe, noembed, noframes), script data with its escaped and double-escaped states, PLAINTEXT, tags and attributes, comments, bogus comments, DOCTYPE, CDATA in SVG and MathML, and character references: the full table of named references (go-fast-core's entity) with the rule for legacy names without a semicolon, and numeric references with the standard's replacements.
  • Tree (internal/dom), built the way browsers recover from tag soup: implied end tags (p, li, dd, dt, option, table rows and cells), headings that close headings, misnested formatting elements (a simplified adoption agency algorithm), formatting reopened after a block closes it, content misplaced in a table moved in front of it (foster parenting), SVG and MathML with the HTML elements that break out of them. noscript is read with scripting off, as its content.
Text that declares no encoding

Input with no byte order mark, no Extractor.Charset, no <meta> declaration (HTML) and that is not valid UTF-8 says nothing of its encoding. The Encoding standard reads it as windows-1252, which turns Japanese, Chinese, Korean or Russian text into garbage; Japanese and Chinese open data in Shift_JIS and GBK is common. Here the encoding is recognised from the bytes only where one is certain, and otherwise the input is refused. Nothing is guessed: each test is one that the text of its language passes by a wide margin and the same bytes read in another encoding fail by a wide margin.

Read as When
UTF-8 there are at least four valid multi-byte sequences and at most one byte that is not valid for every four of them (UTF-8 with damaged bytes, each of which is U+FFFD with text.unmapped_glyphs)
UTF-16LE, UTF-16BE the input has a zero byte in its first 32 KiB, which UTF-8 text never has, and the bytes at every other offset are nearly all one of four values (0x00 for ASCII, 0x04 for Cyrillic), with no unpaired surrogate or control character. UTF-16 of ASCII and Cyrillic is valid UTF-8, which is why this test comes first. Han text in UTF-16 without a byte order mark is not recognised
Shift_JIS full-width kana are a fifth of the characters past ASCII or more: Japanese writes its grammar in kana, and no other encoding's bytes read as Shift_JIS give them
EUC-KR Hangul syllables of KS X 1001 are six in ten or more, Hanja and lone jamo one in ten and one in twenty or fewer
GBK, Big5 Han characters are six in ten or more, and half of them or more are among the 1,000 most frequent Chinese characters (with their Traditional forms; from the Unicode Consortium's Unihan database, go-fast-core's charset/common.go); the bytes of one read as the other give scattered rare characters
windows-1251 о е а и н т с р are 45 in a hundred of the letters or more, and there are capitals (Russian, Ukrainian, Bulgarian, Serbian; Hebrew in windows-1255, which shares the frequent bytes, has no capitals)
windows-1252 the bytes past ASCII stand alone, beside ASCII letters or spaces, as the accented letters of the languages of western Europe do, and nothing says they are another Latin code page (below)

A double-byte code page is allowed one byte sequence it does not have in a hundred characters. It must be the only encoding that passes: two that pass are not decided. What says text is not windows-1252: a byte windows-1252 leaves undefined; a symbol between two ASCII letters (Polish ł ą ż are ³ ¹ ¿ there); the Icelandic letters ð þ ý, one in twenty bytes or more (Turkish ğ ş ı, Czech ý); õ without ã or ç, or with ö and ü (Hungarian ő); pairs of letters no language of windows-1252 writes in one text (ø beside ì, Czech ř beside ě; ã beside î, Romanian); two valid UTF-8 sequences; a zero byte.

Refused. When no encoding is certain, Extract returns ErrEncodingUnknown, which wraps gofastcore.ErrUnsupported, with a message that says to give the encoding with Extractor.Charset (command: -charset). A program reading a batch can test for it with errors.Is and read the file again with the encoding it knows. The chapters of an EPUB, which must be UTF-8 or UTF-16, are not refused: one whose encoding is not certain is read as windows-1252.

Reported. A document read in an encoding recognised from its bytes, windows-1252 included, has the warning text.encoding_detected (a code shared by the go-fast libraries) naming it (for an EPUB, one warning with the encodings and the number of chapters of each). Input that is valid UTF-8 or declares its encoding is never judged and has no such warning.

Measured. On Wikipedia articles in 30 languages, each encoded in the code pages of its language, 57 files (go-fast-core's TestDetectEval; its charset/gen/fetch_detect_eval.py fetches them), read whole and in 40 windows each of 4 KiB, 1 KiB and 200 bytes:

  • No file, and no window of 1 KiB or more, was read in a wrong encoding.
  • Of the 2,280 windows of 200 bytes (a sentence or two), 30 were: Czech, Polish, Hungarian, Slovak, Romanian or Vietnamese read as windows-1252 (28) when the letters they hold that windows-1252 has elsewhere are too few to show, a Russian one as windows-1252, and a Japanese one in EUC-JP as EUC-KR. The warning names the encoding read.
  • Shift_JIS, GBK, Big5, EUC-KR, windows-1251 and windows-1252 text was recognised in every window of 1 KiB or more; UTF-16 of Russian, Greek and French in every one; damaged UTF-8 in every one.
  • Not decided, as they should not be: KOI8-R, KOI8-U, CP866, ISO-8859-5, EUC-JP, ISO-8859-2, ISO-8859-7, and the Windows code pages of Central Europe (but where windows-1252 gives the same text), Greek, Turkish, Hebrew, Arabic, Vietnamese and Thai. Han text in UTF-16 without a byte order mark is not decided either, nor GB18030 text whose four-byte sequences are more than one in a hundred characters.

Cost. Only input that is neither declared nor UTF-8 is tested, from just before its first byte past ASCII and for at most 32 KiB (4,096 characters for each double-byte code page), so the time is bounded whatever the file's size: about 2 µs for a 1 KiB windows-1252 text, 14 µs for 1 KiB of Japanese, Chinese or Korean, and at most about 0.25 ms (BenchmarkDetect). In a whole extraction that is 12 µs on a 4 KiB Japanese text (read in 22 µs, against 10 µs with -charset shift_jis) and 0.23 ms on 64 KiB (0.83 ms against 0.60 ms).

Markdown

Markdown (internal/md) is parsed with the block and inline structure of CommonMark 0.31: ATX and setext headings, paragraphs, block quotes, bullet and ordered lists with nesting and tight/loose lists, fenced and indented code, thematic breaks, HTML blocks, link reference definitions; emphasis by the delimiter algorithm, code spans, inline and reference links and images, autolinks, raw inline HTML, entity and numeric references, backslash escapes, hard breaks.

Conformance: all 652 examples of the CommonMark 0.31.2 spec pass, compared after the normalization of the reference test runner (normalize.py). The test (commonmark_test.go) reads the spec's JSON from outside the repository ($GOFASTHTML_COMMONMARK_SPEC, by default ../.testdata/commonmark-0.31.2-spec.json; the spec is CC-BY-SA 4.0) and is skipped without it; examples that fail are listed in it with the reason, and the list is empty. The spec is checked with link addresses percent-encoded as the reference renderer encodes them; in extraction a link's address is kept as the source writes it.

GitHub Flavored Markdown extensions read: tables; strikethrough (~~a~~ or ~a~, a strike span); task-list items (- [ ], - [x]: the marker is taken out of the text and the item has Attrs["checked"] "false" or "true"; an HTML list item that begins with a checkbox gets the same); extended autolinks (bare www., http:// and https:// addresses, www. ones linked as http://). Not read: footnotes, extended email autolinks (a bare address such as user@example.com stays text; <user@example.com> is a CommonMark autolink and is read) and the disallowed-raw-HTML filter (raw HTML is read as a page's is).

Front matter. A Markdown file that begins with a line --- and has a line --- or ... further on begins with YAML front matter (Jekyll, Hugo, GitHub, and the SKILL.md, agent, prompt and rule files of AI tools); one that begins with +++ and has a line +++ further on, with TOML front matter (Hugo). The front matter is the first block of the body, a code block of its text between the fences, with Attrs["language"] and Attrs["front_matter"] (AttrFrontMatter) yaml or toml, and Loc its bytes from the first fence to the last; the Markdown after it is read with its offsets in the file. Its values go to the metadata: title to Title, author and authors (names, or the name of each) to Authors, description and summary to Extra["description"] (where a page's <meta name=description> goes), tags and keywords to Keywords, lang, language and locale to Language, date, created and published to Created, lastmod, updated, modified and last_modified_at to Modified (when they are dates); every other value to Extra["front_matter.<path>"] (ExtraFrontMatterPrefix), a nested key as a.b, a list's items joined with , . A YAML null (a plain ~, null, Null, NULL or nothing, and in front matter read line by line a key with nothing after it) or an empty string is no title, author, keyword, language or date: a key whose value is only that is in Extra["front_matter.<key>"] as written (~, null, ""), even when it is title or description; in a list that goes to Extra, a null is an item as written (a, null, b); in a list of authors or keywords it is left out. A string "null" and a null are both null in Extra; the block has them as written. Values in the metadata have their ligatures written as letters; the front matter's block is verbatim. YAML front matter must be a mapping: a file that begins with a thematic break followed by text is Markdown. Front matter that is not YAML but whose every line is key: value or under such a line, as Cursor's rules write globs: **/*.ts, is read line by line, with input.repaired (info) giving the YAML error. TOML values are read when they are strings, numbers, booleans, dates or arrays of these on one line; the keys of an array of tables ([[resources]]) are not read, up to the next [table]. Bounds: 256 values in the metadata, each (a list after joining) cut at 64 KiB; a value whose key path is longer than 1,024 bytes is left out; 256 authors and 256 keywords, those past it left out; each with limit.exceeded on the document giving the count; the front matter's block has them all. A notebook's Markdown cells have no front matter. Detect also reads .mdc (Cursor's rules), .qmd (Quarto) and .rmd (R Markdown) as Markdown.

The document is rendered to HTML as a CommonMark renderer does and read by the HTML path above, so the blocks come out as in the table below (emphasis markers are gone; a link is a link span; code is declared code, verbatim, with the fence's language). Raw HTML in Markdown is read exactly as in a page: its declarations give the same display reasons, and an HTML comment is a note marked Attrs["stored"] markup_comment. Loc.Offset and Loc.Length are into the Markdown source: the lines of the Markdown block a block came from, and for raw HTML the exact bytes of its element.

Encoding: a byte order mark, then Extractor.Charset, else UTF-8 if the whole input is valid UTF-8, else as Text that declares no encoding says. Markdown has no <meta> prescan.

Plain text

Plain text is decoded as Markdown is, and split into paragraph blocks at blank lines and form feeds. Line breaks inside a paragraph are kept as \n: a text file does not say whether its lines are wrapped prose or lines that mean something (an address, a verse, a list), and keeping them loses nothing. Trailing white space on each line and control characters other than tab are dropped. Loc gives each paragraph's byte range. Plain text declares nothing about display, so no block has a display reason.

CSV and TSV

Comma-separated values (csv, MIME text/csv) and tab-separated values (tsv, MIME text/tab-separated-values) are decoded as plain text is (a byte order mark, then Extractor.Charset, then UTF-8 if valid, else as Text that declares no encoding says), and are one part of kind sheet, number 1, named by the file without its directory and extension. Its rows are table blocks.

  • The delimiter, in this order: a first line sep=X (Excel's declaration; sep= in any case, then one character, then the line end), which is read as the declaration and not as a row; Extractor.Delimiter; tab for tsv; for csv, the one of , ; tab | that splits the most of the first 100 rows (in the first 64 KiB) into the same number of fields, more than one, the earlier in that list on a tie, else ,; a first row that runs past the 64 KiB is skipped, and the rows after it decide. Reading the syntax is not judging content: Metadata.Extra["delimiter"] holds the delimiter (written U+XXXX when it is a control character other than tab, or a ligature U+FB00 to U+FB06, which would otherwise be written as its letters) and Metadata.Extra["delimiter_source"] how it was chosen: declared, option, format or detected. A quote or a line end cannot be a delimiter: Extract returns ErrUnsupported for one given as Extractor.Delimiter.
  • Fields are read as RFC 4180 has them, and leniently: quoted fields with doubled quotes, line breaks inside quotes (each of CRLF, CR and LF there is a \n), rows ending in CRLF, LF or CR. A quote inside an unquoted field is text; text after a closing quote is joined to the field ("ab"c is abc, as Python's csv reads it); a quoted field not closed runs to the end of the input. Each of these is counted, and the part has one input.repaired with the number of rows output. Input is never refused for its syntax.
  • Quoting in TSV. By default TSV is read with the same quoting as CSV, as Excel's tab-delimited export, pandas and Python's excel-tab dialect write and read it. The official definition of text/tab-separated-values (IANA) has no quoting: a field cannot hold a tab or a line end, and a quote is an ordinary character. Under the default, a quote that is not balanced therefore merges the rows after it into one field, up to the end of the input, reported as input.repaired. Extractor.NoQuotes (-no-quotes) reads as IANA has it, for CSV and TSV alike: fields end only at the delimiter and rows only at line ends, and quotes are kept as characters.
  • The grid. Rows are padded with empty cells to the widest, so every table is a rectangle. Rows with no text at the end are left out, a row whose fields hold only control characters (which are dropped) having none; blank lines and empty cells before them are kept. Cell text follows core's text conventions (control characters other than tab and line feed are dropped, ligatures written as their letters) and is otherwise as written: nothing is trimmed. A cell is text, never a number, date or formula: a value beginning with = is text and is not evaluated.
  • No header row is inferred: CSV does not declare one, so HeaderRows is 0. Extractor.Header is the declaration RFC 4180's MIME parameter header=present makes, and gives the first table HeaderRows 1.
  • Splitting. A table has at most 1,000 rows and at most 2^20 cells; a longer one is split by rows, and the later pieces are Continued. Each piece has Loc.Range in A1 notation (A1:F1000, A1001:F2000), counting rows of the table (records, after a sep= line), not lines of the file.
  • Bounds. Fields past column 16,384 (MaxCSVColumns) are not read, and a field is read up to 1 MiB (MaxCSVField) and cut there at a character boundary; each gives the part one limit.exceeded with the count. The text budget counts BlockCost for each table block and, for each row, CellCost for each cell, empty or not, and its text; where it runs out the sheet is cut off, with the number of rows not read. The text is read twice, once to count the rows and find the widest and once to build the tables, and besides the output only one row is held.
  • No stored part, no display reasons, no inferred structure.
Jupyter notebooks

A Jupyter notebook (ipynb, MIME application/x-ipynb+json), format version 4 (4.0 to 4.5) or 3, is one part of kind body: its cells in order, each read on its own, so that the HTML of one cell or output cannot run into the next. Version 1 and 2 notebooks give ErrUnsupported; input that is not a JSON object with cells, ErrMalformed. A value of a JSON type the format does not allow where it stands (a cell that is not an object, a source that is a number) is not read, and the part has one input.repaired with the count; nothing else is refused.

  • Markdown cells are read as Markdown is (above). An image a cell names as attachment:name is the cell's attachment, with Image.ID cell-N/attachment:name (with a name that has control characters or is longer than 1,024 bytes, sha256: and the start of its hash in its place) and, with ImagesData, its bytes; it is not a resource loaded from elsewhere.
  • Code cells are a code block with the code, and Attrs["language"] the notebook's language (language_info.name, else kernelspec.language; in version 3, the cell's language). Then come the blocks of their outputs, each with Attrs["output"] (AttrOutput) saying which output it is: stdout or stderr for text the code printed (consecutive outputs of one stream are joined, as a notebook shows them), execute_result for the value of the cell, display_data for what it displayed, error for the traceback of the error it raised. Printed text, tracebacks and text/plain values are read as JupyterLab shows them: colour and cursor escape sequences are left out, a backspace takes out the character before it, and text after a carriage return writes over its line (a progress bar is its last state).
  • Of an output's representations, the one JupyterLab prefers is read: text/html (a pandas DataFrame is its HTML table), text/markdown, text/latex (a formula block, notation latex), an image (SVG, BMP, PNG, JPEG, GIF, WebP, as an image block), then text/plain; the others are alternatives of it and are not read. An output with none of these (only JSON, JavaScript or a widget's state) has no block. HTML is read as a page is: scripts go to the stored part, with input.active_content.
  • Raw cells, and cells of a kind not known, are a code block with their text and no language; version 3's heading cells are headings.
  • What the notebook declares. A cell whose input is collapsed (metadata.jupyter.source_hidden) has its blocks hidden, whole, whatever the HTML in it; so do the outputs of a cell whose outputs are collapsed (metadata.jupyter.outputs_hidden, or metadata.collapsed, and version 3's collapsed).
  • Location. A cell's id (version 4.5) is Loc.Anchor of its blocks. There are no byte offsets.
  • Metadata: Title and Authors from the notebook's metadata, and in Metadata.Extra kernel (the kernel's display name), language, language_version and nbformat (4.5).
  • Bounds. The text budget and the decode budget (which counts the HTML each cell becomes, and the decoded images) apply as for a page; where one runs out the body is cut off, with the number of cells not read. The JSON is held in memory as it is parsed, and the cells are read one at a time.
JSON and YAML

JSON (json, MIME application/json: .json, .jsonc, .geojson, and JSON Lines .jsonl, .ndjson, .jsonlines) and YAML (yaml, MIME application/yaml: .yaml, .yml) are parsed and cut along their structure, so that no value is split between blocks. They are one part of kind body of code blocks with Attrs["language"] json or yaml, and of tables. YAML is read with a parser of YAML 1.2 written for the library (internal/yaml), which passes all 402 cases of the YAML test suite (data release 2022-01-17); JSON with a scanner of RFC 8259 that also takes comments and trailing commas (JSON with comments, as tsconfig.json is written).

  • Blocks follow the structure. A document's top-level value is one block when it is at most the block size, 1 KiB by default (DefaultDataBlockBytes; Extractor.DataBlockBytes, -data-block-bytes). A longer one is split into its members (an object's or mapping's members, an array's or sequence's items); consecutive members are packed into blocks, the members of a block spanning at most the block size (the block also holds the indentation before its first member, the key line of a container split there and the comments around its members, so it can be longer), and a member longer than the block size is split in turn. A scalar longer than it is a block of its own: a value is never cut.
  • The block size. A chunker can join blocks that are next to each other without cutting a value (their paths say where they are), but it cannot cut a block without knowing JSON or YAML: the block size should be at most the size of its chunks. Over the corpus's JSON, JSON Lines and YAML files (6.3 MB), 1 KiB is on average 280 to 350 tokens of OpenAI's cl100k_base and of Gemma's tokenizer, and 310 to 540 of bge-small-en-v1.5's (a BERT tokenizer, whose models read 512), by format, JSON Lines the densest; 4% of the code blocks are over 512 bge tokens at 1 KiB (scalars longer than that, and dense text such as JSON Lines, where 1 KiB can be more), against 79% at 4 KiB. Against 4 KiB, the JSON output is 20% larger and reading takes about 35% more CPU time (0.11 s against 0.08 s).
  • Text as written. A block is the file's text from its first member to its last: indentation, quotes, escapes and ligatures as written, control characters other than tab dropped, line ends \n. The comment lines just above a member, and a comment after it on its line, are in its block; the key line of a split container, and the comments above it, are in the block of its first member, or, when that member is a table's first row, in a code block of their own before the table, whose Loc.Anchor is the container's path. A comment after the last member of a split container (before its closing bracket, or in YAML indented at least as far as that member) is in the block of the last members, or in a block of its own at the container's path. The comments after a document's last block are a block of their own, from the first to the end of the last, with the closing brackets or YAML ... between them as written. Brackets, commas, YAML document markers (---, ...) and directives between blocks are not in any otherwise. Each block has Loc.Offset and Loc.Length, the bytes it was read from.
  • Paths. Loc.Anchor is the path of a block's first member, from the top of its document: keys after dots (spec.containers[0].env), a key that is not a plain name in brackets and quotes (["odd key"]), items by index from 0. When a block holds several members, Attrs["path_end"] (AttrPathEnd) is the path of the last. A top-level value read whole has no path. A path longer than 1,024 bytes is left out, and no longer one is built below it. In a YAML file of several documents every block has Attrs["document"] (AttrDocument), the document's number from 1.
  • Records are tables. In an array or sequence that is split, a run of two or more records (objects or mappings whose values are all scalars, with no key twice and no comment inside, and in YAML with no anchor or tag of their own: a row holds values only) is a table: a header row of their keys in the order first seen, then a row per record, a key a record does not have an empty cell. A comment between two records ends the run there; the comment is in a code block before the next run (or in the block of the record after it, when that record is alone). A cell is the value as written: a string in its quotes, its escapes decoded ("café", 'x'), a number, true, null or a plain YAML scalar as in the file, a YAML alias as *name, a YAML anchor and tag before the value as written (&who "Ann", !!str 1). Header and cells have their ligatures written as letters. Table.RowLocs gives each row's bytes and its path. A table of more than 1,000 rows is cut into pieces of 1,000, the later ones Continued and each with the header row. A top-level array of records is a table whatever its length. A lone record among other members is a member like them.
  • JSON Lines. A file named .jsonl, .ndjson or .jsonlines, or a .json holding several values one after another, is a sequence of values, [0], [1], ...: records are tables, other values packed into blocks. A line that is not JSON is a block as written, with the values around it. In a file named as JSON Lines a value is on one line: a value with an error past the end of its first line makes that line alone the block not read as JSON, and the next line is read as a value. A value nested deeper than 512 is kept as written, too, not read by its structure, and the part has limit.exceeded giving how many and where the first is.
  • Text that is not JSON or YAML (a syntax error) is read as lines, as before: blocks of about 1,000 lines and 256 KiB, cut at line ends, the later ones Continued; Metadata.Extra["json.syntax_error"] or ["yaml.syntax_error"] says where and why (line 2, column 6: '2' where ':' is expected after a key). Nesting deeper than 512 is read as lines too, with limit.exceeded on the part and no syntax error; so is text cut by the decode budget, with no syntax error.
  • Encoding. YAML is decoded as plain text is. JSON is UTF-8 (RFC 8259): JSON whose encoding is not certain is read as UTF-8, bytes that are not UTF-8 U+FFFD with text.unmapped_glyphs, where plain text would be refused.
  • Bounds. The text budget counts each block; a block it ends inside is cut at a line end, and the body ends there, with the number of lines not read. The decode budget cutting the input gives the number of its bytes not read. A file of only blank lines has part.no_text.
Subtitles

SubRip (srt, MIME application/x-subrip) and WebVTT (vtt, text/vtt, the W3C format) are one part of kind body (subtitles.go, internal/subtitle).

  • Encoding. As plain text: a byte order mark (UTF-8, UTF-16, and UTF-32 in either order, decoded here), Extractor.Charset for SubRip (WebVTT is UTF-8 by its spec, and takes none), UTF-8, else the encoding recognised from the bytes. Text whose encoding is not certain is refused with ErrEncodingUnknown, as plain text is; give it with Extractor.Charset (command: -charset). Line ends are CR LF, LF or CR, and CR CR LF (written by files converted twice from Windows line ends) is one line end. A U+FEFF around a SubRip cue number (files joined from others carry one) is ignored there.
  • A cue is a paragraph, in file order. Text is the cue's text as a viewer sees it: its lines joined with \n, markup removed. In WebVTT the cue text parsing of the spec applies: tags (c, i, b, u, ruby, rt, v, lang, timestamp tags; other tags are ignored, as the spec has it) are markup, and character references are decoded with the HTML table; the text of rt is kept after its base. A < with no > after it in the cue is text. In SubRip, <b> <i> <u> <font ...> and their end tags, {b} {i} {u} and their ends, and override codes {\...} ({\an8}) are markup; any other < or { is text, and nothing is decoded.
  • Where it is. Loc.Offset and Loc.Length are the bytes of the input from the cue's identifier or number line (else its timing line) to the end of its last text line. Loc.Anchor is the WebVTT cue identifier, or the SubRip cue number as written.
  • Attributes. start and end are the timings written HH:MM:SS.mmm (hours added when left out, a comma made a point, a fraction padded to three digits); when either does not parse, both are as written, and the part has one input.repaired (info) with the number of such cues. settings holds WebVTT cue settings, or SubRip coordinates (X1:...), as written. voice holds the names of the cue's WebVTT voices (<v Name>), in order, each once, joined by , ; they are not in Text. With Options.Spans, b, i and u give bold, italic and underline spans, in both formats.
  • SubRip layout, read leniently. A cue is an optional number line, a timing line (a line with -->), and text lines up to the next number-and-timing or timing line. A blank line inside the text, when no cue starts after it, is a paragraph break (\n\n). Text before the first cue is a paragraph of its own, with input.repaired (info). A cue with no text has no block and is counted in one input.repaired (info).
  • WebVTT blocks. Blocks, and the header, end at an empty line, as the spec's parser has it: a line of white space is a line of the block; a line with --> is a timing line, and one inside a cue's text ends the cue and starts the next, as the spec's parser has it. NOTE blocks are note blocks marked Attrs["stored"] markup_comment, where they stand. STYLE blocks are code blocks (css, stored=stylesheet) in the stored part, which comes with the whole document only. REGION definitions are in Metadata.Extra["vtt.regions"] as written, joined by \n. A block that is none of these is a paragraph, with input.repaired (info).
  • The header. The text after WEBVTT on the first line, and header lines not of the form Key: value (such as HLS's X-TIMESTAMP-MAP=...), are in Metadata.Extra["vtt.header"], one per line; a header line Key: value is in Extra under vtt. and the key in lower case (vtt.kind, vtt.language), and Language also in Metadata.Language when it has the form of a BCP 47 tag. A file that does not begin with the signature, read as vtt because the caller said so, is read all the same, with input.repaired (info).
  • Bounds. The text budget counts each block, its anchor and attributes; the decode budget applies. A cue's text is read up to 8 MiB, its attributes up to 4 KiB, header values up to 64 KiB and 256 keys, an identifier up to 1,024 bytes as Loc.Anchor, WebVTT tags nested up to Extractor.MaxDepth (default 512; deeper tags and as many end tags are ignored, their text kept); each cut is limit.exceeded. Reading is linear in the input: a <, {\ or <font with no end is looked for once per cue, and header text, repeated header keys and voices stop being collected at their bounds. A part with no block has part.no_text.
  • Corpus. Of the 57 SubRip files of the public corpus's dev set, 5 in code pages not certain from their bytes (sintel_ar, _he, _hu, _pl, _th: Arabic, Hebrew, Hungarian, Polish, Thai) are refused with ErrEncodingUnknown, by design; the other 52 give 4,859 cues, with input.repaired 8 times and text.encoding_detected 6 times. The 83 WebVTT files give 134 cues, 6 notes and 10 stored blocks, with input.repaired 19 times, part.no_text once and text.control_characters_removed twice. All read files pass Validate; on each, the words of every block are in the input at its Loc, and the cues with a block and those counted as empty are as many as the lines with -->. One file, TOS-PT-BR.srt, writes its arrows - >: it has no timing line, and is one paragraph of text before the first cue. fate-MicroDVD_capability_tester.srt is MicroDVD ({start}{end}text), not SubRip: it has no timing line either, and is one paragraph with its lines and their {...} codes as written.
EPUB

EPUB 2 and 3 publications (Source.Format epub, .epub or a zip whose first member says application/epub+zip) are read here rather than in a library of their own, since their content is XHTML and extractors do not import each other.

  • Container. The zip archive is read with a limit on members (Extractor.MaxArchiveMembers, default 100,000; more is ErrLimitExceeded) and every member decompressed within Limits.MaxDecodedBytes, shared with embedded documents. An archive whose central directory is missing (a file cut short) is read by the members' local headers, with input.repaired; a name that occurs twice gives input.ambiguous and the first is read. A missing or wrong mimetype member gives epub.mimetype (info) and the archive is read anyway. META-INF/container.xml leads to the package document (OPF); without one the input is ErrMalformed. container.xml, the package document, the navigation document, the NCX and encryption.xml are read up to 16 MiB each (epub.MaxXML): a larger container.xml or package document is ErrLimitExceeded.
  • Metadata. dc:title (the first) to Title; each dc:creator to Authors; dc:language to Language; each dc:subject to Keywords; dc:date to Created when it parses as ISO 8601, and as written to Extra["date"]; meta property="dcterms:modified" to Modified; dc:description, dc:publisher, dc:contributor, dc:rights, dc:source, dc:type, dc:format, dc:relation, dc:coverage to Extra under their names; the identifiers to Extra["identifier"], one a line, the package's unique identifier first; the package version to Extra["epub_version"]. The text of one metadata element is read up to 64 KiB, up to 4096 Dublin Core elements, and up to 2^20 manifest items and spine entries; past any of these, the document carries limit.exceeded with the count.
  • Chapters. One chapter part per spine item, numbered by its place in the spine, read by the HTML path in XHTML mode (a self-closing tag is an empty element; the XML declaration is not a comment). Loc offsets are into that chapter's file. Part.Name is the chapter's first entry in the table of contents, else its <title>. An item with linear="no" is extracted in its place and carries epub.non_linear (info). Images a chapter shows are resolved in the archive: Image.ID is the member's path, MIME the manifest's media type, and with ImagesData the bytes. References to members of the archive are not counted as external. Options.Parts selects chapters; Limits.MaxParts (default 100,000) bounds them. When Limits.MaxParts or the text budget stops the chapters, the rest of the manifest (below) is not read either, and the document's limit.exceeded names what was not read, as the publication has them: the later chapters, the stored part (the scripts, styles and form values of the chapters read), the images of the manifest that no chapter read shows (some may be ones a later chapter would have shown) and the embedded documents.
  • Navigation. The EPUB 3 navigation document (nav with epub:type="toc"), else the EPUB 2 NCX, becomes Outline: title, nesting level and the number of the chapter it points to (0 when it points outside the spine). Titles count against the text budget before the first chapter. The table of contents is read up to 100,000 entries, lists nested up to 64 levels and titles up to 4 KiB (cut at the same byte however the title's text is split); past any of these, and when the navigation document or NCX is larger than 16 MiB or the decode budget and is not read, the document carries limit.exceeded.
  • The rest of the manifest, with the whole document only (Options.Parts unset): images no chapter shows go to the stored part (after the chapters' scripts and styles), with no display reason, as image blocks with Attrs["stored"] manifest_item and Attrs["name"] the member path (a cover image has the text cover); stylesheets are skipped; every other item (documents outside the spine, fonts, audio, scripts) is handed to Options.ExtractChild and listed in Children. Scripts count as active content.
  • Encryption. Resources META-INF/encryption.xml lists, font obfuscation (IDPF and Adobe) aside, are not read: an encrypted chapter is a part with part.failed and epub.encrypted, an encrypted image an image block without data (its chapter, or the stored part, carries epub.encrypted with the count), an encrypted embedded file a child with child.encrypted, and the document carries epub.encrypted with the count. When every selected chapter is encrypted (DRM), nothing usable is left and the result is ErrUnsupported. An encryption.xml that cannot be read in full (larger than 16 MiB or the decode budget, listing more than 2^20 members, damaged, or XML that cannot be read to its end) leaves which members are encrypted unknown, and none is read as text: every member but mimetype, META-INF/ and the package document is treated as possibly encrypted (a chapter gets part.failed and epub.encrypted saying so, an embedded file child.encrypted, and the navigation document and NCX are not read). Since that leaves no chapter to read, the result is ErrLimitExceeded (too large, too many members) or ErrMalformed (damaged).
  • Display. Each chapter's declarations give display reasons as in a page. That includes the navigation document when it is in the spine: the hidden attribute EPUB 3 puts on its nav and ol elements (landmarks, page list, deeper levels of the table of contents) is a declaration, and those blocks get hidden.
Saved web pages (MHTML)

A web page saved as one file (Source.Format mht, MIME multipart/related; .mht or .mhtml, or a file whose header is that of one a browser saved: a Snapshot-Content-Location field, or From: <Saved by ...> or "Saved by ...", with a multipart/related Content-Type) is a MIME message (RFC 2557) whose parts are the page and the files it uses. Chrome and Edge, Internet Explorer, UnMHT and WebKit write them. It is read here, like an EPUB, since the page is HTML and extractors do not import each other.

  • The page is the part the Content-Type's start parameter names, else the first HTML part. It is read as any HTML page into one part of kind body, with the part's charset parameter as the transport encoding (then Extractor.Charset, which also stands in for a label not decoded here). Each part is decoded from its transfer encoding once, and only when the decode budget can hold it; parts in 7bit, 8bit or binary are not charged, since nothing is decoded. Loc offsets are into the page as decoded from its transfer encoding, as an EPUB chapter's are into its member. Parts nested in a multipart part (Internet Explorer puts the page in a multipart/alternative) are read in their place, up to 8 levels.
  • Images the page shows are resolved in the file: a cid: address by Content-ID, any other by resolving it against the page's location (itself resolved against Snapshot-Content-Location; a Windows path such as C:\dir\page.htm is taken as a file: URL) and comparing it with each part's resolved Content-Location. When an <img>'s src is not in the file, the candidates of its srcset and of the <source> elements of its <picture> are tried in order, since a browser saves the one it showed. Only image parts are images: a frame named by an <img> stays an embedded document. Image.ID is the part's Content-Location (else cid: and its Content-ID; over 2,048 bytes, sha256: and a hash), MIME its type, and with ImagesData its bytes. References to parts of the file are not counted as external.
  • Metadata is the page's, then what the file's header adds: the Subject (the title the browser wrote, encoded words decoded) where the page has no title, the Date (when it was saved) as Created, the program of From: <Saved by X> as Application where the page names no generator, the page's address as Extra["url"], and every header field under its lowercase name in Extra.
  • The other parts, with the whole document only (Options.Parts unset): images the page does not show (a favicon, CSS backgrounds) go to the stored part as image blocks with Attrs["stored"] manifest_item and Attrs["name"] the location, as an EPUB's do; style sheets and fonts are styling and are not listed; every other part (the HTML of frames, scripts, other files) is handed to Options.ExtractChild with its media type and charset, named by its location, and listed in Children. Images inside a frame are not resolved, since the frame is read as a document of its own. Scripts count as active content.
  • Damage. A file with no MIME header is read as one HTML page; a boundary never found makes the body one HTML page; a missing closing boundary lets the last part run to the end; a boundary that follows a binary part with no line break (WebKit wrote such files) is taken as one when a part would otherwise contain it; base64 with characters outside its alphabet is decoded skipping them, an unknown transfer encoding taken as it is. Each is input.repaired (info), once a kind with its count. The file holds at most Extractor.MaxArchiveMembers parts (default 100,000; past it limit.exceeded and the rest are not read); a header section is read up to 1 MiB. A file whose first part is an image (a picture a browser showed by itself) is one image block with part.image_only.

How HTML maps

One part of kind body, numbered 1, and, when the page has script or style text or <input type=hidden> values and Options.Parts is unset, a part of kind stored, numbered 2, that holds them. Every block has Loc.Offset and Loc.Length, its byte range in the source file (also when the file is UTF-16 or windows-1252), and Loc.Anchor from the id of its element, or of an element in it (<a name> counts).

HTML Block
h1–h6 heading, level 1–6
p, div and other block elements, text between blocks paragraph
li in ul, ol, menu, dir list_item, Level the list depth, Ordered, Marker: 3., c., iv. per start, value, type, reversed; a bullet (•, ◦, ▪ by depth, or per type) for unordered lists. Block elements inside an item are line breaks in its text; text after a nested list is a paragraph
table table; rowspan/colspan as Merges (clamped as the standard clamps them; rowspan=0 runs to the end); leading thead rows, or rows of th only, as HeaderRows; with Options.Spans, a cell's first link in Table.Cells. A table inside a cell is written into the cell's text, a line a row
caption, figcaption, legend caption
pre, listing, xmp, plaintext code, verbatim; Attrs["language"] from a language-x or lang-x class on it or its code
blockquote quote, Level the nesting depth
img image with the alt text; Image.ID the src (a sha256: hash for a data: URI or a very long address), Width/Height from the attributes; with ImagesData, the bytes of data: URIs
a href a link span, with Options.Spans
b, strong, i, em, u, s, del, code, kbd, sub, sup, ... style spans, with Options.Spans
br \n in the text
hr (and a Markdown thematic break, ---, ***, ___) thematic_break, no text, with the display reasons of the element; inside a table cell only a line break in the cell's text
select note of type choices, the options a line each, Attrs["field"] its name
textarea, input with a value paragraph with Attrs["field"] the control's name; the value of <input type=hidden> goes to the stored part with Attrs["stored"] form_field
<!-- comment --> note with Attrs["stored"] markup_comment and no note type, after the block it stands in; no display reason; left out of rendered text unless RenderOptions.Stored or StoredKinds asks for it (also in raw HTML in Markdown and in EPUB chapters)
script, style in the stored part as code (language javascript, json or css), verbatim, read as data and never run, with Attrs["stored"] macro (core's StoredMacro) for a script and stylesheet for a style element; no display reason
template read as text where it stands, with the reason hidden (its content is inert by the element's definition)
noscript, noembed, noframes, iframe fallback, closed details/dialog, rp read as text where they stand; no display reason
iframe srcdoc the document in the attribute is parsed as HTML and its blocks come where the iframe stands, before any fallback text; Loc is the (outermost) iframe element in the page; what the iframe declares (hidden, inline display:none, ...) is added to all of it, what the inner document declares applies inside; its title, meta and lang are not the page's metadata and are not read. Its elements count from the iframe's depth against Extractor.MaxDepth: a srcdoc document whose iframe is at the limit is not read (limit.exceeded). Its bytes count against the decode budget (cut with limit.exceeded) and its text against the text budget.
iframe src, frame, embed, object, audio, video the address is not fetched and counts toward input.external_reference (a data: or javascript: address does not); the element's own content, such as an iframe's fallback text, is read where it stands
<title> Metadata.Title
<meta name=author> Metadata.Authors, one entry each, not split
<meta name=keywords> Metadata.Keywords, one entry, not split
<meta name=description> Metadata.Extra["description"]
<meta name=generator> Metadata.Application
<html lang> Metadata.Language

Outside pre (and white-space: pre in inline style), white space is collapsed as CSS white-space: normal does. Ligatures U+FB00–U+FB06 are written as their letters everywhere but in code.

What the file declares

Everything is extracted; nothing is dropped. Where the page itself declares that text is not displayed, or is drawn with no ink, the block (or the span, or the table cells) carries that reason in Display, following the page's own inheritance as CSS does. Only the element's attributes and its style attribute are read: stylesheets (<style> and linked ones) and scripts are not evaluated.

hidden is reported for:

  • the hidden attribute, including hidden="until-found" (unless inline style gives another display);
  • inline display: none;
  • inline visibility: hidden or collapse, inherited, and undone by visibility: visible inside;
  • the SVG presentation attribute display="none";
  • the SVG presentation attribute visibility="hidden" (or collapse), undone by visible inside;
  • the content of template, which is inert by the element's definition.

no_ink is reported for:

  • inline opacity: 0 exactly;
  • inline color: transparent, or a colour whose alpha is exactly 0 (undone by another colour inside).

The same rules apply to raw HTML in Markdown and to every EPUB chapter.

The boundary. Colour, size, position and overlap are not judged. Nothing compares two values or applies a threshold: a text colour equal to its background, a font size of 0 or 1 pixel, a large negative offset, clipping, opacity: 0.01 or a colour with alpha 0.01 give no reason. A rule in a stylesheet that hides a class gives no reason either, since stylesheets are not evaluated. A block with no Display value says nothing about whether a reader can see it.

Not reported, no reason: noscript (shown under a condition), closed details and dialog (shown on interaction), rp, and aria-hidden (which concerns assistive technology; it neither adds a reason nor removes one).

Kept where they are, with no reason: comments and attribute text are note blocks; a comment is stored data (Attrs["stored"] markup_comment), as are script and style text and <input type=hidden> values in the stored part, all left out by the renderers unless RenderOptions.Stored is set or RenderOptions.StoredKinds names their kind. A comment or attribute inside a hidden element still has no reason.

Characters are kept. Zero-width characters, Unicode tag characters, bidirectional controls and variation selectors stay in the text as written, with no reason and no warning.

Attribute text. Text a page keeps in attributes without drawing it in the flow of the page is extracted: aria-label, aria-description, aria-roledescription, aria-placeholder, title and placeholder on any element, and alt on an image map's area. Each becomes a note block with Attrs type: attribute and attribute: <name>, at the element's place (before the block the element is in, when that block has no text yet), with Loc the byte range of the attribute's value. A value that only repeats the element's own text, or an image's alt text, after white space is collapsed, is left out, since that text is extracted already. aria-labelledby and aria-describedby are not followed: the elements they name are read where they stand, with the reasons their own declarations give.

Warnings

Code Severity When
input.active_content info scripts, on... event attributes, javascript: addresses
input.external_reference warning resources loaded from elsewhere: pictures, scripts, stylesheets, frames, embedded objects, media, a refresh to another address, a form's target; nothing is fetched
text.unmapped_glyphs warning bytes not valid in the encoding read, or character references that name no character (&#0;, a surrogate, a number past U+10FFFF), read as U+FFFD; one warning for the bytes and one for the references, each with its count
text.control_characters_removed info control characters with no meaning as text (NUL, ESC, the C1 controls; vertical tab and next line outside text read as HTML) were removed from the text: of the body, a chapter, a sheet's fields, a notebook, a JSON or YAML file (on that part), or of the metadata and the table of contents (on the document), with the count. Not counted: tab, line ends and form feed, which are white space or a break (in text read as HTML, from HTML, Markdown, EPUB and MHTML, vertical tab, next line and the line and paragraph separators are line ends too, as core's blocktext reads them); and what is removed from addresses and names (links, image addresses, anchors, languages, field names), which identify something and are not text. Text the text budget leaves out is not counted
image.unsupported_encoding warning with ImagesData, a data: image that could not be decoded, or an EPUB image that could not be read (not counting images left without data by the decode budget or encryption, which have their own warnings: limit.exceeded, epub.encrypted)
part.no_text, part.image_only warning the body, a CSV or TSV sheet, a notebook, a JSON or YAML file, or an EPUB chapter has no text (part.no_text also when an EPUB has no chapters)
limit.exceeded error a limit cut off the body, an EPUB chapter (saying so too when the chapter's name was left out), the table of contents or the stored part; the text budget left out an EPUB chapter's name; the text budget stopped the reading of an EPUB's chapters (on the document, naming the chapter and what was not read) or of the rest of its manifest (on the document, with the number of images and embedded documents not read); an EPUB has more chapters than Limits.MaxParts (on the document, naming what was not read); the decode budget left data: images undecoded, without ID or data (on their part, in every images mode), EPUB images without data (on their chapter or the stored part) or embedded documents unread (on the document), with the count; an EPUB's table of contents passed a bound of its own (above) or its navigation document or NCX was not read for its size; an EPUB's encryption.xml was too large to read in a document that is returned; an iframe srcdoc document is at the depth limit; a bound of the tree builder lost spans or a declared display: more than 64 formatting elements open at once, the bound on formatting elements reopened, a style attribute longer than 16 KiB (one warning each per part); a bound cut a string of the output (each once, with a count): a metadata value over 64 KiB, more than 256 author or keywords declarations, an <html lang> over 64 bytes (left out), on the document; an id (or an a's name) over 1,024 bytes not used as Loc.Anchor, a code block's language over 64 bytes (left out), on the part; an EPUB chapter's <title> over 64 KiB cut as its name, on the chapter; an EPUB's package metadata text over 64 KiB, Dublin Core elements past 4,096, manifest items or spine entries past 2^20, on the document; in CSV and TSV, fields past column 16,384 and fields over 1 MiB, on the sheet, and the text budget cutting the sheet off, with the number of rows not read; in a notebook, the text or decode budget cutting the body off, with the number of cells not read, and attached images without data; in JSON and YAML, the text budget cutting the body off, with the number of lines not read, and nesting deeper than 512 (the file read as lines), on the part; front matter values over 64 KiB cut in the metadata, values whose key path is over 1,024 bytes left out of it, values past 256 left out of it, and authors or keywords past 256 left out of it, with the count (on the document; the front matter's block has them all)
text.encoding_detected warning the input declares no encoding and is not UTF-8; it was read in the encoding its bytes were recognised as, which the message names (Text that declares no encoding). In an EPUB, one warning for the document with the encodings and the number of chapters of each
html.charset_unsupported warning a declared encoding that is not decoded, read as windows-1252; or an Extractor.Charset label that is not decoded, ignored. In an EPUB, one warning for the document with the number of chapters and the labels (the first 8, with each one's count)
html.nesting_flattened warning elements nested deeper than Extractor.MaxDepth (default 512), or more than 4096 open at once; below that their text is read side by side, with their display reasons kept
input.repaired, input.ambiguous warning EPUB: the archive's directory was unreadable, or a member name occurs twice. CSV and TSV (input.repaired only): rows with a quote outside RFC 4180's rules, with their number. Notebooks (input.repaired only): values of a JSON type the format does not allow where they stand, not read, with their number. Markdown (input.repaired, info, on the document): front matter that is not YAML read line by line, with the YAML error
epub.non_linear info the chapter is linear="no" in the spine
epub.encrypted error resources are encrypted (DRM) and were not read; or encryption.xml could not be read in full and a chapter or image may be encrypted; on a chapter or the stored part, the count of encrypted images left without data
epub.mimetype info the mimetype member is missing or wrong
part.failed error EPUB: a chapter could not be read (missing from the manifest or archive, encrypted)
child.encrypted error EPUB, on a child: an embedded document META-INF/encryption.xml lists; it was not opened
child.not_extracted info, warning EPUB, on a child: not extracted, since Options.Child is not set (info), or the depth limit was reached or its bytes could not be read (warning); set by core's Options.ExtractChild
child.unsupported warning EPUB, on a child: Options.Child returned ErrUnsupported (the command's does for formats other than HTML, Markdown, text and EPUB)
child.failed error EPUB, on a child: Options.Child returned any other error

Limits

Limit Default
Limits.MaxInputBytes 256 MiB the file is held in memory; larger is ErrLimitExceeded
Limits.MaxDecodedBytes 1 GiB the text decoded to UTF-8, the HTML a Markdown document is rendered to, the bytes of data: images, and the parts of an MHTML file decoded from their transfer encoding
Limits.MaxTextBytes 256 MiB core's text budget: block text, cells, markers, link targets, image IDs, BlockCost a block and CellCost a cell of a table (so a small table declaring a huge grid is cut by rows)
Extractor.MaxDepth 512 tree depth
MaxCSVColumns, MaxCSVField 16,384, 1 MiB the fields of a CSV or TSV row read, and the bytes of a field

Every fixed bound that cuts a string of the output (text, names, metadata values, anchors, languages) reports it with limit.exceeded; bounds that lose nothing are not reported: an image address over 2,048 bytes is replaced by sha256: and its hash as Image.ID (the address is in the source at Loc), a width or height outside 1 to 2^24 - 1 is an invalid value and is not given, a number attribute (start, value, colspan, rowspan) of more than 18 digits is an invalid integer and is ignored (shorter ones are read in full; colspan and rowspan are clamped as the HTML standard says), a declared encoding label is read up to 64 bytes (only to look it up and to quote it in html.charset_unsupported), and link labels and ordered-list numbers in Markdown are bounded as CommonMark says. Block quotes and lists in Markdown nest at most 100 deep (md.MaxNest); a marker past that is text, kept. Scans in Markdown that find no end (code spans, comments) are not repeated. Every tag costs bounded work: end tags look at most 512 elements down the stack, at most 64 formatting elements are kept to reopen and the number reopened is bounded, and inline styles are read up to 16 KiB; when a page reaches one of the last three, its part carries limit.exceeded. Extraction stops when the context is cancelled.

Not read

Stylesheets and scripts (not evaluated); aria-labelledby/aria-describedby references (not resolved); srcset; the title and meta of an iframe srcdoc document; CSS generated content; <base href> (addresses are as written); layout tables are tables. In Markdown: GFM footnotes, extended email autolinks and the disallowed-raw-HTML filter, as above; TOML front matter values over several lines (inline tables, multi-line strings and arrays) are in its block only.

Licence

MIT. The named character reference table is from the WHATWG HTML Living Standard; see NOTICE.

Documentation

Overview

Package gofasthtml extracts HTML, Markdown, plain text, EPUB, comma- and tab-separated values and Jupyter notebooks into the shared go-fast document model, gofastcore.Document. An EPUB is a part for each chapter of its spine, read as XHTML. A CSV or TSV file is one part of kind sheet whose rows are table blocks. A notebook is one part of kind body: its Markdown cells read as Markdown is, its code cells as code blocks followed by the blocks of their outputs. JSON and YAML are parsed and cut along their structure: code blocks of members as written, with their paths, and runs of records as tables; text that is neither is read as lines. Markdown front matter is a block and metadata. Markdown is parsed as CommonMark with the GFM tables, strikethrough, task lists and extended autolinks, rendered to HTML and read as a page is, so its raw HTML gets the same checks; blocks are located in the Markdown.

It uses the standard library and go-fast-core only, with an HTML5 tokenizer and tree builder of its own that recover from tag soup the way browsers do. An HTML page, a Markdown document or a plain text file is one part of kind body; an EPUB is one part of kind chapter for each chapter. Script and style text, hidden form values and, in an EPUB, images no chapter shows go to a part of kind stored after them when the whole document is read. Blocks carry their byte range in the source (Loc.Offset, Loc.Length) and the id of their element (Loc.Anchor).

Everything is extracted. Where the page declares, in an attribute or in inline style, that text is not displayed or has no ink, the blocks carry that reason (hidden, no_ink); nothing else about display is judged, and stylesheets and scripts are not evaluated. Script and style text is read as data into the stored part and never run. Nothing the page refers to is fetched. See the README for the mapping, the warnings and the limits.

Index

Constants

View Source
const (
	// MaxCSVColumns is the number of fields of a row that are read, as
	// many columns as a sheet of Excel has. The fields past it are not
	// read, with limit.exceeded.
	MaxCSVColumns = 16384
	// MaxCSVField is the length in bytes of the longest field read in
	// full. A longer field is cut there, at a character boundary, with
	// limit.exceeded.
	MaxCSVField = 1 << 20
)

Bounds of comma- and tab-separated input. Each protects against one hostile row: the text budget bounds the whole.

View Source
const (
	// DefaultMaxArchiveMembers bounds the number of files in an EPUB's
	// zip archive.
	DefaultMaxArchiveMembers = 100_000
	// DefaultMaxParts bounds the chapters read when Limits.MaxParts is
	// zero.
	DefaultMaxParts = 100_000
)

Defaults for EPUB.

View Source
const (
	// WarnNonLinear: the chapter is marked linear="no" in the spine: a
	// reading system shows it only when it is linked to (notes, answers).
	// It is extracted in its place in the spine.
	WarnNonLinear = "epub.non_linear"
	// WarnEncrypted: resources of the publication are encrypted (DRM)
	// and were not read. Font obfuscation is not counted. Also: the
	// chapter may be encrypted, META-INF/encryption.xml not having been
	// read in full, and was not read.
	WarnEncrypted = "epub.encrypted"
	// WarnMimetype: the archive's mimetype member is missing or does not
	// say application/epub+zip; the archive was read as an EPUB all the
	// same.
	WarnMimetype = "epub.mimetype"
)

Warning codes raised while an EPUB is read.

View Source
const (
	// DefaultMaxInputBytes bounds the size of the file. The whole file is
	// held in memory while it is read.
	DefaultMaxInputBytes = 256 << 20
	// DefaultMaxDecodedBytes bounds the bytes decoded: the text the input
	// becomes in UTF-8, and the images given inline as data: URIs.
	DefaultMaxDecodedBytes = 1 << 30
	// DefaultMaxDepth is how deeply elements are nested in the tree that
	// is read; see Extractor.MaxDepth.
	DefaultMaxDepth = dom.DefaultMaxDepth
)

Defaults for the limits of gofastcore.Options.Limits, used where a limit is zero. A negative limit means no limit.

View Source
const (
	// WarnCharsetUnsupported: the document declares a character encoding
	// this library does not decode, and was read as windows-1252, so
	// letters outside ASCII may be wrong; or Extractor.Charset names one,
	// and it was ignored. An EPUB has one such warning for all its
	// chapters, with their number and the labels.
	WarnCharsetUnsupported = "html.charset_unsupported"
	// WarnNestingFlattened: elements are nested deeper than the limit.
	// Below it, elements were placed beside each other instead of inside
	// each other; their text is all there, and the reasons it is hidden
	// are kept, but the blocks there may be joined or split differently.
	WarnNestingFlattened = "html.nesting_flattened"
	// WarnMetadataTruncated was raised by v0.1.1 and earlier when a
	// metadata value was cut or declarations were left out.
	//
	// Deprecated: since v0.1.2 those cuts are reported with
	// gofastcore.WarnLimitExceeded, as every bound that cuts output is,
	// and this code is not raised.
	WarnMetadataTruncated = "html.metadata_truncated"
)

An embedded document handed to gofastcore.Options.ExtractChild may also carry child.not_extracted, child.unsupported or child.failed, which that function sets. The EPUB codes are in epub.go.

View Source
const (
	// AttrFrontMatter marks the code block that holds a Markdown file's
	// front matter; its value is the language, "yaml" or "toml".
	AttrFrontMatter = "front_matter"
	// ExtraFrontMatterPrefix begins the Metadata.Extra keys of the front
	// matter's values that no field of Metadata holds.
	ExtraFrontMatterPrefix = "front_matter."
)

Front matter: the block of metadata at the start of a Markdown file, YAML between "---" lines (Jekyll, Hugo, GitHub, and the skill, agent, prompt and rule files of AI tools) or TOML between "+++" lines (Hugo).

View Source
const (
	OutputStdout        = "stdout"
	OutputStderr        = "stderr"
	OutputExecuteResult = "execute_result"
	OutputDisplayData   = "display_data"
	OutputError         = "error"
)

Values of Attrs[AttrOutput].

View Source
const (

	// AttrPathEnd is the path of a block's last member when it holds
	// several: Loc.Anchor is the first's.
	AttrPathEnd = "path_end"
	// ExtraJSONSyntaxError and ExtraYAMLSyntaxError, in Metadata.Extra,
	// say where and why a JSON or YAML file is not JSON or YAML; it is
	// then read as lines.
	ExtraJSONSyntaxError = "json.syntax_error"
	ExtraYAMLSyntaxError = "yaml.syntax_error"
)

How JSON and YAML are cut by their structure.

A document's top-level value is one block when it is at most Extractor.DataBlockBytes long (dataUnitBytes by default). A longer one is split into its members (an object's members, an array's elements), and consecutive members are packed into blocks whose members span at most dataUnitBytes (a block adds the indentation, head and comments around them); a member longer than that is split in turn, so that no value is ever cut. Each block is the text of its members as the file writes them, with the comments just before a member and after it on its line, and Loc.Anchor is the path of its first member (Attrs["path_end"] that of its last).

In an array that is split, a run of two or more records (objects whose members are all scalars, no key twice, in YAML with no anchor or tag) is a table: a header row of their keys and a row per record, a cell holding the value as written (a string in its quotes, its escapes decoded). A top-level array of records is a table whatever its length. The text before a table that is in no block (a key line, comments) is a code block before it; a comment between two records ends the run.

View Source
const AttrDocument = "document"

AttrDocument is the number of the YAML document (from 1) a block is in, in a file of several documents.

View Source
const AttrOutput = "output"

AttrOutput is the Block.Attrs key that marks a block made from the output of a notebook's code cell, as the notebook stores it: "stdout" or "stderr" for text the code printed to that stream, "execute_result" for the value of the cell, "display_data" for what the code displayed, "error" for the error it raised. The blocks of a cell's code and of its other cells have no such key.

View Source
const DefaultDataBlockBytes = 1 << 10

DefaultDataBlockBytes is the size JSON and YAML are cut to when Extractor.DataBlockBytes is zero: 1 KiB, 280 to 540 tokens on average over the test corpus by tokenizer and format, near the 512 tokens many embedding models read.

View Source
const MaxMetaValue = 64 << 10

MaxMetaValue bounds a value of front matter put in the metadata, as a page's metadata values are bounded.

View Source
const StoredManifestItem = gofastcore.StoredManifestItem

StoredManifestItem is the Attrs["stored"] value of an image the publication stores and no chapter shows. It is core's gofastcore.StoredManifestItem.

View Source
const StoredStylesheet = gofastcore.StoredStylesheet

StoredStylesheet is the Attrs["stored"] value of the text of a style element, kept in the stored part. It is core's gofastcore.StoredStylesheet.

Variables

View Source
var ErrEncodingUnknown = fmt.Errorf("%w: the encoding of the text could not be determined: none is declared, it is not UTF-8, "+
	"and its bytes are not certainly windows-1252, windows-1251, Shift_JIS, GBK, Big5, EUC-KR or UTF-16; "+
	"give the encoding with Extractor.Charset (command: -charset)", gofastcore.ErrUnsupported)

Warning codes specific to this library. Each states a fact about the file. The codes shared by all go-fast libraries are in gofastcore; this library raises these of them besides the ones about parts and limits (part.no_text, part.image_only, part.failed, limit.exceeded):

input.active_content      the page has scripts, event handler attributes
                          or javascript: addresses; script text is read
                          as data into the stored part, and nothing is
                          run
input.external_reference  the page loads resources from elsewhere:
                          pictures, stylesheets, scripts, frames, a
                          refresh to another address, a form's target;
                          nothing is fetched
text.unmapped_glyphs      bytes that are not valid in the encoding read,
                          or character references that name no
                          character (&#0;, a surrogate, a number past
                          U+10FFFF), are read as U+FFFD
image.unsupported_encoding  image data was asked for and an inline
                          data: image could not be decoded
input.repaired            an EPUB's zip archive has no readable central
                          directory and was read by its local headers
input.ambiguous           a member name occurs twice in an EPUB's
                          archive; the first is read
child.encrypted           an embedded document of an EPUB is encrypted
                          and was not opened

ErrEncodingUnknown is returned for text that declares no encoding, is not valid UTF-8, and whose bytes are not certainly one of the encodings recognised: read as windows-1252 it would not be text. Give the encoding with Extractor.Charset (the command's -charset). It wraps gofastcore.ErrUnsupported. The chapters of an EPUB are read as windows-1252 instead, with gofastcore.WarnTextEncodingDetected.

Functions

func Detect

func Detect(name string, src []byte) string

Detect decides the format of an input from its name, and failing that from its content: a name ending in .html, .htm, .xhtml or .shtml is HTML; .md, .markdown, .mdown, .mkd, .mkdn, .mdwn, .mdc (Cursor's rules), .qmd (Quarto) or .rmd (R Markdown) Markdown; .txt or .text plain text; .epub EPUB; .csv comma-separated values; .tsv or .tab tab-separated values; .ipynb a Jupyter notebook; .json, .jsonl, .ndjson, .jsonlines, .geojson or .jsonc JSON; .yaml or .yml YAML; .mht or .mhtml a web page saved as one file (MHTML); .srt SubRip; .vtt or .webvtt WebVTT. A file whose header is that of an MHTML file a browser saved (a Snapshot-Content-Location field, or From "<Saved by ...>", with a multipart/related Content-Type) is MHTML whatever its name. A zip archive whose first member is "mimetype" saying application/epub+zip is EPUB whatever its name, and a text that begins, after a byte order mark, with WEBVTT followed by a space, a tab, a line end or nothing is WebVTT; SubRip is not guessed from content. Without one of those, an input that begins with markup, or has a tag of a common HTML element in its first 4 KiB, is HTML, and any other plain text: Markdown, CSV, notebooks, JSON and YAML are not guessed from content, since reading plain text as Markdown or CSV would take characters out of it or split it where its author did not, and a text is JSON, YAML or a notebook only by its name.

func Extract

func Extract(ctx context.Context, r io.ReaderAt, size int64, opts *gofastcore.Options) (*gofastcore.Document, error)

Extract reads a document with default settings. It is (&Extractor{}).Extract.

func ExtractFile

func ExtractFile(ctx context.Context, path string, opts *gofastcore.Options) (*gofastcore.Document, error)

ExtractFile opens the named file and extracts it with default settings.

Types

type Extractor

type Extractor struct {
	// Format is the format to read the input as: "html", "md", "txt",
	// "epub", "csv", "tsv", "ipynb", "json", "yaml", "mht", "srt" (SubRip)
	// or "vtt" (WebVTT). Empty means to decide it with Detect.
	Format string
	// MaxDepth bounds how deeply elements nest in the tree that is read.
	// Zero means DefaultMaxDepth.
	MaxDepth int
	// MaxArchiveMembers bounds the number of files in an EPUB's archive,
	// and the number of parts of an MHTML file.
	// Zero means DefaultMaxArchiveMembers; negative means no limit.
	MaxArchiveMembers int
	// Charset is the character encoding the input comes with from outside
	// it, as a label such as the charset parameter of a MIME Content-Type
	// gives it ("windows-1251", "shift_jis"): the transport-layer encoding
	// of the WHATWG encoding sniffing. It applies to HTML, Markdown, plain
	// text, CSV, TSV, JSON and YAML, and to the page of an MHTML file whose
	// part declares no charset; not to the chapters of an EPUB. A byte order mark
	// overrides it; it overrides a <meta> declaration and detection. A
	// label that names no encoding this library decodes is ignored, with
	// the warning html.charset_unsupported. Empty means none.
	Charset string
	// Delimiter separates the fields of csv and tsv input. A first line
	// "sep=X", Excel's declaration, overrides it. Zero means tab for tsv
	// and, for csv, the one of , ; tab | that splits the most of the
	// first rows into the same number of fields, more than one, else the
	// comma. A quote or a line end cannot be a delimiter; Extract returns
	// an error wrapping gofastcore.ErrUnsupported for one.
	Delimiter rune
	// Header says that the first row of csv or tsv input is a header row,
	// as RFC 4180's MIME parameter header=present declares; its table
	// then has HeaderRows 1. A header row is never inferred.
	Header bool
	// NoQuotes reads csv and tsv input with no quoting: fields are split
	// at the delimiter and rows at line ends only, and a quote is a
	// character like any other, as the IANA definition of
	// text/tab-separated-values has it. By default fields may be quoted
	// as RFC 4180 has them, in tsv too, as Excel, pandas and Python's
	// excel-tab dialect write and read them.
	NoQuotes bool
	// DataBlockBytes is the size JSON and YAML are cut to: a top-level
	// value of at most this many bytes is one block, and a longer one is
	// split into its members, packed into blocks whose members span at
	// most this many bytes, a longer member split in turn. Zero or less
	// means DefaultDataBlockBytes. A chunker can join blocks that are
	// next to each other without cutting a value, but cannot cut one
	// without knowing JSON: give at most the size of its chunks.
	DataBlockBytes int
}

Extractor extracts HTML, Markdown, plain text, EPUB, comma- and tab-separated values, Jupyter notebooks, JSON and YAML, and web pages saved as one file (MHTML). The zero value is ready to use and safe for concurrent use.

func (*Extractor) Extract

func (e *Extractor) Extract(ctx context.Context, r io.ReaderAt, size int64, opts *gofastcore.Options) (*gofastcore.Document, error)

Extract reads size bytes of HTML, Markdown, plain text, EPUB, csv, tsv or a Jupyter notebook from r, in the format e.Format names or Detect decides from Options.Name and the content, and returns the document. HTML, Markdown and plain text are one part of kind body; an EPUB is a part of kind chapter for each chapter of its spine; csv and tsv are one part of kind sheet, named by the file, whose rows are table blocks; a notebook is one part of kind body; JSON and YAML are one part of kind body of code blocks, their text as written; SubRip and WebVTT are one part of kind body, a paragraph per cue (see subtitles.go). With the whole document (Options.Parts unset), script and style text, hidden form values and an EPUB's images no chapter shows follow in a part of kind stored.

An error wraps one of the gofastcore errors: ErrLimitExceeded when the input is larger than Limits.MaxInputBytes, an EPUB's archive has more members than MaxArchiveMembers, its container.xml or package document is larger than 16 MiB or the decode budget, or its encryption.xml is too large to be read in full; ErrNoPartsSelected when Options.Parts selects no part (part 1 of HTML, Markdown, plain text, csv, tsv or a notebook, a chapter of an EPUB); ErrMalformed when r cannot be read, an EPUB's archive, package document or encryption.xml cannot be read, or a notebook is not a JSON object with cells; ErrUnsupported for a Format this library does not have, an EPUB whose selected chapters are all encrypted, or a notebook of format version 1 or 2. An EPUB whose encryption.xml cannot be read in full has no chapter read, since any may be encrypted. Any input that can be read is a document of its format: tag soup is recovered from the way browsers recover from it.

func (*Extractor) ExtractFile

func (e *Extractor) ExtractFile(ctx context.Context, path string, opts *gofastcore.Options) (*gofastcore.Document, error)

ExtractFile opens the named file and extracts it. The file name is recorded as the document's source name unless opts.Name is set.

func (*Extractor) Formats

func (e *Extractor) Formats() []string

Formats lists the formats this library extracts.

Directories

Path Synopsis
cmd
gofasthtml command
Command gofasthtml extracts HTML, Markdown, plain text, EPUB, CSV, TSV, notebooks, JSON, YAML and MHTML files into the shared document model of the go-fast libraries and prints them as JSON, Markdown or plain text.
Command gofasthtml extracts HTML, Markdown, plain text, EPUB, CSV, TSV, notebooks, JSON, YAML and MHTML files into the shared document model of the go-fast libraries and prints them as JSON, Markdown or plain text.
internal
blocks
Package blocks turns an HTML document tree into the blocks of the shared model: headings, paragraphs, list items, tables, code, quotes, captions, images, comments and form values, with white space collapsed as CSS white-space: normal does, links and styles as spans, and the display reasons the page declares.
Package blocks turns an HTML document tree into the blocks of the shared model: headings, paragraphs, list items, tables, code, quotes, captions, images, comments and form values, with white space collapsed as CSS white-space: normal does, links and styles as spans, and the display reasons the page declares.
css
Package css reads the declarations of an inline style attribute that say how content is displayed: display, visibility, opacity, the alpha of the text colour, and white-space.
Package css reads the declarations of an inline style attribute that say how content is displayed: display, visibility, opacity, the alpha of the text colour, and white-space.
dom
Package dom builds a document tree from HTML tokens, recovering from tag soup the way the WHATWG HTML standard's tree construction does for the cases that change what text belongs where: implied end tags (p, li, dd, dt, option, table cells and rows), misnested formatting elements (a simplified adoption agency algorithm), reopening of formatting elements closed by a block, foster parenting of content misplaced in tables, foreign content (SVG, MathML) and the elements that break out of it.
Package dom builds a document tree from HTML tokens, recovering from tag soup the way the WHATWG HTML standard's tree construction does for the cases that change what text belongs where: implied end tags (p, li, dd, dt, option, table cells and rows), misnested formatting elements (a simplified adoption agency algorithm), reopening of formatting elements closed by a block, foster parenting of content misplaced in tables, foreign content (SVG, MathML) and the elements that break out of it.
epub
Package epub reads the container of an EPUB 2 or 3 publication: the zip archive, META-INF/container.xml, the package document (OPF) with its metadata, manifest and spine, the navigation (EPUB 3 nav document or EPUB 2 NCX) and META-INF/encryption.xml.
Package epub reads the container of an EPUB 2 or 3 publication: the zip archive, META-INF/container.xml, the package document (OPF) with its metadata, manifest and spine, the navigation (EPUB 3 nav document or EPUB 2 NCX) and META-INF/encryption.xml.
jsonscan
Package jsonscan reads the tokens of JSON text with their byte offsets, in one pass and without building values: the structure of a document (objects, arrays, members, scalars) and where each piece is.
Package jsonscan reads the tokens of JSON text with their byte offsets, in one pass and without building values: the structure of a document (objects, arrays, members, scalars) and where each piece is.
lexer
Package lexer is an HTML tokenizer following the WHATWG HTML standard, section 13.2.5 "Tokenization", for the states that decide what text a document holds: data, RCDATA, RAWTEXT, script data with its escaped states, PLAINTEXT, tags and attributes, comments, bogus comments, DOCTYPE, CDATA sections in foreign content, and character references.
Package lexer is an HTML tokenizer following the WHATWG HTML standard, section 13.2.5 "Tokenization", for the states that decide what text a document holds: data, RCDATA, RAWTEXT, script data with its escaped states, PLAINTEXT, tags and attributes, comments, bogus comments, DOCTYPE, CDATA sections in foreign content, and character references.
md
Package md parses Markdown, following the block and inline structure of CommonMark 0.31 (with the GFM tables, strikethrough, task lists and extended autolinks), and renders it to HTML as a CommonMark renderer does, keeping a map from offsets in the HTML back to offsets in the Markdown.
Package md parses Markdown, following the block and inline structure of CommonMark 0.31 (with the GFM tables, strikethrough, task lists and extended autolinks), and renders it to HTML as a CommonMark renderer does, keeping a map from offsets in the HTML back to offsets in the Markdown.
subtitle
Package subtitle reads SubRip (.srt) and WebVTT (.vtt) text, decoded to UTF-8, into cues and the other blocks of the file, with their offsets in that text.
Package subtitle reads SubRip (.srt) and WebVTT (.vtt) text, decoded to UTF-8, into cues and the other blocks of the file, with their offsets in that text.
yaml
Package yaml is a streaming, event-based parser of YAML 1.2.2 that gives every node its place in the input.
Package yaml is a streaming, event-based parser of YAML 1.2.2 that gives every node its place in the input.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL