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
detectreports: the dialect and the version, together. - Feed
Error - Feed
Options - Plugin options.
Defaultis the canonical default set: the normalised Atom shape, with namespace well-formedness enforced. - Translation
Part - One optional alchemy translation source and its explicit entry point.
- Translation
Parts - The package-local structural translation interface.
Enums§
- Feed
Dialect - The feed family a document belongs to.
- Feed
Format - The output shape of a parse.
- Feed
Version - The exact dialect version a document declares.
Constants§
- ERROR_
UNRECOGNIZED_ ROOT - The code carried by the one rejection this layer raises itself. See
the
Errorssection ofREADME.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
WhiteSpaceplusLineTerminator, which is what a JavaScript\smatches and whatString.prototype.trimremoves. - 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"andconst VERSIONingo/feed.go;tests/version_test.rsfails 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 theFeedplugin function. The bare engine is enough, asmakearranges: 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 neitherstr::parse::<i64>nor Go’sstrconv.Atoi.- js_trim
String.prototype.trim, which is notstr::trim. SeeJS_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 theMake(options)of the Go port. - manifest_
text - The plugin’s manifest,
tabnas.plugin.json, as the repository carries it. Itstranslateobject 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 outsiders/;tests/translate_test.rsholds the copy to the file. - parse
- Parse one feed with the shared default parser.
- plugin
- The plugin form of
feed, forTabnas::use_plugin. Options are read from the plugin option bag withFeedOptions::from_value. - render_
text - The feed format’s render,
alchemy/render.alc, the file the manifest’stranslate.rendernames: a library of alchemy definitions, with noexport, whose entry pointfeed-renderwrites 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, istranslate().embed, and the transducer part,translate/transduce.alc, istranslate().transduce. - translate
- Return the feed format’s immutable translation parts.