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.

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, which should already carry the jsonic grammar (as make arranges): the port of the Feed plugin function.
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 jsonic grammar, then this plugin, the new Tabnas().use(jsonic).use(Feed, options) of the canonical package.
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.