latexml_core/document/resource.rs
1//======================================================================
2// Support for requiring "Resources", ie CSS, Javascript, whatever
3#[derive(Debug, Clone, Default)]
4pub struct Resource {
5 pub name: String,
6 pub media: String,
7 pub mimetype: String,
8 pub content: String,
9 /// Who required it; under `--nodefaultresources` only a binding's remote style sheet is linked (OD #1249).
10 pub origin: ResourceOrigin,
11}
12
13/// Who required a resource: a compiled binding, or the document (`\lxRequireResource`, a runtime binding, which may
14/// sit beside the source). Not in Perl, whose `--nodefaultresources` drops every resource (Post/XSLT.pm:63-65).
15#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
16pub enum ResourceOrigin {
17 #[default]
18 Document,
19 Binding,
20}
21
22/// The class `add_resource` gives a remote resource a compiled binding required: post's `--nodefaultresources` keeps
23/// such a style sheet and drops every other remote resource (DG ruling 2026-12-05, OD #1249).
24pub const BINDING_RESOURCE_CLASS: &str = "ltx_binding_resource";
25
26/// A resource linked where it lives, never read or copied (Perl Post/XSLT.pm:93): `http://`, `https://` or
27/// protocol-relative `//`.
28pub fn is_remote(src: &str) -> bool {
29 src.starts_with("http://") || src.starts_with("https://") || src.starts_with("//")
30}
31
32pub fn resource_type(abbrev: &str) -> String {
33 match abbrev {
34 "css" => "text/css",
35 "js" => "text/javascript",
36 _ => "",
37 }
38 .to_string()
39}