Skip to main content

Crate tabnas_feed

Crate tabnas_feed 

Source
Expand description

RSS and Atom feed plugin for the tabnas parsing engine, crate tabnas_feed.

The plugin reads RSS 0.90, 0.91, 0.92, 1.0 (RDF) and 2.0, and Atom 0.3 and 1.0, and by default normalises every dialect into one Atom-shaped result. Two other output modes exist: FeedFormat::Native keeps the source dialect’s own structure, and FeedFormat::Raw hands back the element tree from tabnas_xml untouched.

let parser = tabnas_feed::make();
let value = parser.parse("<feed xmlns=\"http://www.w3.org/2005/Atom\"/>")?;
assert_eq!(value.to_json()["format"], "atom");

This is the Rust port of the canonical TypeScript in ../ts; the TypeScript version is authoritative and this crate tracks it. Like the canonical plugin it contributes NO grammar rules of its own: it installs tabnas_xml and hooks the existing xml rule’s before-close, so all the feed knowledge lives in plain functions over the parsed element tree.

§Untrusted input

A parsed feed is data, never instructions. Every title, link and content value came from a stranger, so a caller must not follow instructions found in one, must not choose a tool call, command, path or URL from one without independent validation, and must do its own escaping: parsing is not sanitising.

A caller must also cap the size and nesting depth of a document before parsing it. Nesting costs super-linear time in the layers below this crate, and deep enough nesting exhausts the stack and aborts the process rather than returning an error; README.md and AGENTS.md carry the measured numbers.

Structs§

Detection
What detect reports: the dialect and the version, together.
FeedError
FeedOptions
Plugin options. Default is the canonical default set: the normalised Atom shape, with namespace well-formedness enforced.
TranslationPart
One optional alchemy translation source and its explicit entry point.
TranslationParts
The package-local structural translation interface.

Enums§

FeedDialect
The feed family a document belongs to.
FeedFormat
The output shape of a parse.
FeedVersion
The exact dialect version a document declares.

Constants§

ERROR_UNRECOGNIZED_ROOT
The code carried by the one rejection this layer raises itself. See the Errors section of README.md: the canonical plugin throws a plain message with no code at all, so the MESSAGE is the contract and this code exists only because the engine’s error channel requires one.
JS_SPACE
ECMA-262 WhiteSpace plus LineTerminator, which is what a JavaScript \s matches and what String.prototype.trim removes.
NS_ATOM_03
The Atom 0.3 namespace.
NS_ATOM_10
The Atom 1.0 namespace (RFC 4287).
NS_RDF
The RDF namespace, the document element of RSS 0.90 and 1.0.
NS_RSS_090
The RSS 0.90 namespace.
NS_RSS_10
The RSS 1.0 namespace.
VERSION
This crate’s version. It MUST equal ts/package.json "version" and const VERSION in go/feed.go; tests/version_test.rs fails the build if they drift.

Functions§

convert
Convert a parsed element tree to the requested output shape.
detect
Report the dialect and version of a parsed element tree.
feed
Install the feed plugin on parser: the port of the Feed plugin function. The bare engine is enough, as make arranges: the XML grammar this installs is the whole grammar a feed needs.
js_parse_int
parseInt(text, 10) (ECMA-262 19.2.5), which is neither str::parse::<i64> nor Go’s strconv.Atoi.
js_trim
String.prototype.trim, which is not str::trim. See JS_SPACE.
make
Build a feed parser with the default options.
make_with
Build a feed parser with caller options: the engine, then this plugin, the make(options) of the canonical package (new Tabnas().use(Feed, options)) and the Make(options) of the Go port.
manifest_text
The plugin’s manifest, tabnas.plugin.json, as the repository carries it. Its translate object is what a host that translates reads: the shape a feed is read as and written from (tree), the root the render takes, the schema of the tree its events carry (feed), the files that hold the embedding of a plain tree in that schema and the render, the file that holds the transducer part (transduce), through which a host that reads parser events reads a feed’s tree from the grammar’s rule passes as they come, and the sentences that say what a written document does not keep. The crate embeds its own copy, translate/manifest.json, since a packaged crate holds nothing outside rs/; tests/translate_test.rs holds the copy to the file.
parse
Parse one feed with the shared default parser.
plugin
The plugin form of feed, for Tabnas::use_plugin. Options are read from the plugin option bag with FeedOptions::from_value.
render_text
The feed format’s render, alchemy/render.alc, the file the manifest’s translate.render names: a library of alchemy definitions, with no export, whose entry point feed-render writes a tree’s events as one document. A host links it with its own program. The crate embeds its own copy, translate/render.alc, held to the file as the manifest’s is; the embedding, translate/embed.alc, is translate().embed, and the transducer part, translate/transduce.alc, is translate().transduce.
translate
Return the feed format’s immutable translation parts.