pub struct AddAttributesToSVGElement {
pub attributes: BTreeMap<String, String>,
}Expand description
Adds attributes to SVG elements in the document. This is not an optimisation and will increase the size of SVG documents.
§Differences to SVGO
It’s not possible to set a none value to an attribute. Elements like
<svg data-icon /> are valid in HTML but not XML, so it’s only possible to create
an attribute like <svg data-icon="" />.
It’s also not possible to create React-like syntax. In SVGO it’s possible to define
an attribute as { "key={value}": undefined } to produce an attribute like
<svg key={value} />, however in OXVG you have to provide a string value, so it’s
output would look like <svg key={value}="" />.
§Examples
Add an attribute with a prefix
use std::collections::BTreeMap;
use oxvg_optimiser::{Jobs, AddAttributesToSVGElement};
let jobs = Jobs {
add_attributes_to_s_v_g_element: Some(AddAttributesToSVGElement {
attributes: BTreeMap::from([(String::from("prefix:local"), String::from("value"))]),
}),
..Jobs::none()
};§Correctness
This job may visually change documents if the attribute is a presentation attribute or selected via CSS.
No validation is applied to provided attribute and may produce incorrect or invalid documents.
§Errors
Never.
If this job produces an error or panic, please raise an issue
Fields§
§attributes: BTreeMap<String, String>Pairs of qualified names and attribute values that are assigned to the svg
Trait Implementations§
Source§impl Clone for AddAttributesToSVGElement
impl Clone for AddAttributesToSVGElement
Source§fn clone(&self) -> AddAttributesToSVGElement
fn clone(&self) -> AddAttributesToSVGElement
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AddAttributesToSVGElement
impl Debug for AddAttributesToSVGElement
Source§impl Default for AddAttributesToSVGElement
impl Default for AddAttributesToSVGElement
Source§fn default() -> AddAttributesToSVGElement
fn default() -> AddAttributesToSVGElement
Source§impl<'de> Deserialize<'de> for AddAttributesToSVGElement
impl<'de> Deserialize<'de> for AddAttributesToSVGElement
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<'input, 'arena> Visitor<'input, 'arena> for AddAttributesToSVGElement
impl<'input, 'arena> Visitor<'input, 'arena> for AddAttributesToSVGElement
Source§fn element(
&self,
element: &Element<'input, 'arena>,
context: &mut Context<'input, 'arena, '_>,
) -> Result<(), Self::Error>
fn element( &self, element: &Element<'input, 'arena>, context: &mut Context<'input, 'arena, '_>, ) -> Result<(), Self::Error>
Source§fn document(
&self,
document: &Element<'input, 'arena>,
context: &Context<'input, 'arena, '_>,
) -> Result<(), Self::Error>
fn document( &self, document: &Element<'input, 'arena>, context: &Context<'input, 'arena, '_>, ) -> Result<(), Self::Error>
Source§fn exit_document(
&self,
document: &Element<'input, 'arena>,
context: &Context<'input, 'arena, '_>,
) -> Result<(), Self::Error>
fn exit_document( &self, document: &Element<'input, 'arena>, context: &Context<'input, 'arena, '_>, ) -> Result<(), Self::Error>
Source§fn exit_element(
&self,
element: &Element<'input, 'arena>,
context: &mut Context<'input, 'arena, '_>,
) -> Result<(), Self::Error>
fn exit_element( &self, element: &Element<'input, 'arena>, context: &mut Context<'input, 'arena, '_>, ) -> Result<(), Self::Error>
Source§fn doctype(
&self,
doctype: &'arena Node<'input, 'arena>,
) -> Result<(), Self::Error>
fn doctype( &self, doctype: &'arena Node<'input, 'arena>, ) -> Result<(), Self::Error>
Source§fn style(&self, style: &'arena Node<'input, 'arena>) -> Result<(), Self::Error>
fn style(&self, style: &'arena Node<'input, 'arena>) -> Result<(), Self::Error>
Source§fn text_or_cdata(
&self,
node: &'arena Node<'input, 'arena>,
) -> Result<(), Self::Error>
fn text_or_cdata( &self, node: &'arena Node<'input, 'arena>, ) -> Result<(), Self::Error>
Source§fn comment(
&self,
comment: &'arena Node<'input, 'arena>,
) -> Result<(), Self::Error>
fn comment( &self, comment: &'arena Node<'input, 'arena>, ) -> Result<(), Self::Error>
Source§fn processing_instruction(
&self,
processing_instruction: &'arena Node<'input, 'arena>,
context: &Context<'input, 'arena, '_>,
) -> Result<(), Self::Error>
fn processing_instruction( &self, processing_instruction: &'arena Node<'input, 'arena>, context: &Context<'input, 'arena, '_>, ) -> Result<(), Self::Error>
Source§fn prepare(
&self,
document: &Element<'input, 'arena>,
context: &mut Context<'input, 'arena, '_>,
) -> Result<PrepareOutcome, Self::Error>
fn prepare( &self, document: &Element<'input, 'arena>, context: &mut Context<'input, 'arena, '_>, ) -> Result<PrepareOutcome, Self::Error>
Source§fn start(
&self,
root: &'arena Node<'input, 'arena>,
allocator: Allocator<'input, 'arena>,
) -> Result<PrepareOutcome, Self::Error>
fn start( &self, root: &'arena Node<'input, 'arena>, allocator: Allocator<'input, 'arena>, ) -> Result<PrepareOutcome, Self::Error>
Source§fn start_with_path(
&self,
root: &'arena Node<'input, 'arena>,
allocator: Allocator<'input, 'arena>,
path: Option<PathBuf>,
) -> Result<PrepareOutcome, Self::Error>
fn start_with_path( &self, root: &'arena Node<'input, 'arena>, allocator: Allocator<'input, 'arena>, path: Option<PathBuf>, ) -> Result<PrepareOutcome, Self::Error>
Source§fn start_with_info(
&self,
root: &Element<'input, 'arena>,
info: &Info<'input, 'arena>,
flags: Option<ContextFlags>,
) -> Result<PrepareOutcome, Self::Error>
fn start_with_info( &self, root: &Element<'input, 'arena>, info: &Info<'input, 'arena>, flags: Option<ContextFlags>, ) -> Result<PrepareOutcome, Self::Error>
Source§fn start_with_context(
&self,
root: &Element<'input, 'arena>,
context: &mut Context<'input, 'arena, '_>,
) -> Result<PrepareOutcome, Self::Error>
fn start_with_context( &self, root: &Element<'input, 'arena>, context: &mut Context<'input, 'arena, '_>, ) -> Result<PrepareOutcome, Self::Error>
Auto Trait Implementations§
impl Freeze for AddAttributesToSVGElement
impl RefUnwindSafe for AddAttributesToSVGElement
impl Send for AddAttributesToSVGElement
impl Sync for AddAttributesToSVGElement
impl Unpin for AddAttributesToSVGElement
impl UnwindSafe for AddAttributesToSVGElement
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more