Skip to main content

Capabilities

Struct Capabilities 

Source
pub struct Capabilities {
Show 27 fields pub bold: bool, pub italic: bool, pub code: bool, pub mark: bool, pub underline: bool, pub strike: bool, pub mark_color: bool, pub superscript: bool, pub subscript: bool, pub heading: bool, pub blockquote: bool, pub bullet_list: bool, pub ordered_list: bool, pub task: bool, pub link: bool, pub image: bool, pub thematic_break: bool, pub footnote: bool, pub code_language: bool, pub table: bool, pub cell_line_break: bool, pub alignment: bool, pub line_spacing: bool, pub font_size: bool, pub font_family: bool, pub text_color: bool, pub page_break: bool,
}
Expand description

Which of leaf’s authoring controls this document’s format can actually spell — one flag per toolbar button, resolved once so a frontend can build its chrome instead of discovering each refusal on a click.

Every field but table is Format::supports_with on the gesture the matching Doc method calls, so this record cannot drift from what the ops do; table is [spells_pipe_tables], the one answer twig doesn’t export.

supports_with rather than supports because two of these are facts about the parse options as much as about the format. Format::supports answers for twig’s defaults, and leaf never parses with those — it parses with [parse_extensions], and a document’s toolbar has to describe the document it is over. A Markdown editor holding highlight authors ==text==; one without it would mint bytes its own reparse hands back as plain text, which is why twig asks before it writes.

The formats are ragged, and that is the point. A single per-document boolean was enough while the two authorable formats were Markdown and djot and everything else spelled nothing. HTML is neither: it writes seven of the eight inline marks as a tag pair, plus <code>, <hr>, an in-cell <br>, and — since twig 3.4 — a heading or paragraph rebuilt as its tag pair, and since 3.5 a quote, a list, a code block, a link and an image printed as fresh nodes; it spells no task box (a form control there) and no footnote, and its <table> is one twig reads but will not write. So ⌘B, ⌘1 and the quote button work in an HTML document and the task and table buttons do not, and no one flag can say that. Markdown and djot differ from each other too: ^superscript^ is djot-only, and an in-cell <br> is Markdown-only.

Fields§

§bold: bool

⌘B — InlineKind::Strong.

§italic: bool

⌘I — InlineKind::Emph.

§code: bool

Inline code — InlineKind::Verbatim.

§mark: bool

Highlight — InlineKind::Mark. Djot spells it, and so does Markdown under the highlight extension [parse_extensions] turns on: the button writes ==text==, which is what the reparse reads back.

§underline: bool

⌘U — InlineKind::Insert, which every format that marks at all spells.

§strike: bool

Strikethrough — InlineKind::Delete. Markdown spells GFM’s ~~text~~ out of the box, since twig parses it out of the box.

§mark_color: bool

The highlight paletteDoc::set_mark_color. Narrower than mark and deliberately its own flag: Markdown spells a colour on a highlight (==🔴 text==) and djot spells only the highlight, so a toolbar offering the swatches wherever the button lights would offer them in a document that cannot write one. Pair with Doc::caret_in_mark, which asks the other question — the palette needs a highlight to colour as much as a format that spells one.

§superscript: bool§subscript: bool§heading: bool

Heading levels and “make this a paragraph” — Doc::set_block.

§blockquote: bool§bullet_list: bool§ordered_list: bool§task: bool

The checkbox controls: giving an item a box, and ticking one.

§link: bool§image: bool

Covers Doc::insert_media too — see the note there on why the three media kinds stand or fall together.

§thematic_break: bool

The horizontal-rule button. HTML spells this one (<hr>).

§footnote: bool

The footnote button — Doc::insert_footnote. Markdown and djot spell the pair; HTML has no footnote of its own, so the button goes away rather than writing brackets that would render as brackets.

§code_language: bool

Setting a fenced block’s language — a control only ever offered with the caret already in a fence.

§table: bool

The grid controls: insert/delete/move a row or column, set a column’s alignment. Pair with Doc::caret_in_table, which asks the other question — an HTML <table> holds the caret and still can’t be edited.

§cell_line_break: bool

Shift+Return inside a cell. Markdown and HTML spell it; djot has no idiomatic in-cell break.

§alignment: bool

The alignment control — Doc::set_alignment, twig’s Gesture::SetBlockAttrs. Every format leaf opens but XML spells a block’s attributes, Markdown under the html_elements [parse_extensions] turns on (a <div> around the block) and AsciiDoc through its […] line.

§line_spacing: bool

The line-spacing menu — Doc::set_line_spacing. The same gesture as alignment and so the same answer, and its own flag because a toolbar dims controls one at a time and the pair may yet diverge.

§font_size: bool

The size menu — Doc::set_font_size, twig’s Gesture::WrapRangeAttrs over a selection. Narrower than the block pair: AsciiDoc’s [#id.role]#text# keeps an id and a role and has no slot for a data- key, so twig refuses the span there and this is false while alignment is true. The block-level form of the same property — the caret in a paragraph, no selection — goes through SetBlockAttrs and still works, which is why the flag describes the control rather than the caret.

§font_family: bool

The face menu — Doc::set_font_family. WrapRangeAttrs, as font_size is.

§text_color: bool

The text-colour swatches — Doc::set_text_color. WrapRangeAttrs, and not to be confused with mark_color: that is a highlight’s background and rides the mark node twig already owns, this is a run’s foreground and rides an attributed span.

§page_break: bool

The page-break button — Doc::insert_page_break, twig’s Gesture::InsertDirective. Markdown under the directives extension [parse_extensions] turns on (::page-break) and djot, which spells it as an empty ::: page-break fence.

Those two and no others, though twig spells the gesture in HTML and AsciiDoc as well — see Capabilities::of.

Implementations§

Source§

impl Capabilities

Source

pub fn of(format: Format) -> Self

Resolve every flag for format, as leaf parses it. Pure and cheap — twig computes each from a static table — but a frontend that wants to hold them can.

The extensions are not a parameter because they are not a choice a caller makes: every leaf document is parsed with [parse_extensions], so the format is the whole of what varies.

Trait Implementations§

Source§

impl Clone for Capabilities

Source§

fn clone(&self) -> Capabilities

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Capabilities

Source§

impl Debug for Capabilities

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Capabilities

Source§

impl PartialEq for Capabilities

Source§

fn eq(&self, other: &Capabilities) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Capabilities

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.