Skip to main content

Capabilities

Struct Capabilities 

Source
pub struct Capabilities {
Show 21 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,
}
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> and an in-cell <br>, and spells no heading marker, no line prefix, no fence, no task box, no link — because its versions of those have a different shape, not a different alphabet. So ⌘B works in an HTML document and ⌘1 does 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 palette — Doc::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.

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.