#[non_exhaustive]pub enum Format {
Djot,
Markdown,
Xml,
Html,
Asciidoc,
}Expand description
Every format Twig can parse — the input axis, as opposed to Target,
which is where output bytes can go.
#[non_exhaustive] for the same reason Target is: Twig’s parser list
grows (reStructuredText is written and awaiting a registry entry), and a
caller matching on this enum should not have to be recompiled to keep
compiling. Match with a _ arm.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Djot
Markdown
Xml
Html
Asciidoc
Parsed and rendered, but not serialized: Target::Asciidoc reports
Error::UnsupportedFormat, and no Editor gesture applies to an
AsciiDoc document.
The parser also covers a slice of AsciiDoc rather than all of it — the header, paragraphs, sections, lists, delimited blocks and the inline spans. What it does not implement survives as literal source text rather than failing the parse, so a successful parse is not by itself a claim that the whole document was understood.
Implementations§
Source§impl Format
impl Format
Sourcepub fn supports(self, gesture: Gesture) -> bool
pub fn supports(self, gesture: Gesture) -> bool
Whether this format can spell gesture — the toolbar’s gray-out
question, answered without a document, so a caller can build its UI
before it has one. Pure and cheap: ask at startup and cache.
true means the gesture will not fail with
Error::UnsupportedFormat. It is not a promise the call succeeds —
the caret still decides, so a supported gesture can still report
Error::NotFound, Error::NotEditable or Error::EditConflict at
the position it is actually run. Gray out on false; do not read true
as “this will work here”.
Returns a plain bool rather than a Result because the two ways the C
query can fail — an unknown format code, a kind from the wrong
vocabulary — are both unrepresentable here: Format and Gesture
are enums, and a Gesture carries a kind only where one applies.
Distinct from BOTH neighbouring questions:
Format::is_authorableis “is there a door in”, true forFormat::Htmlon its inline marks alone.Warning::fidelityis “what survives a conversion to this target”, which is a different table with genuinely different answers — Djot round-trips a smart-quote container faithfully while no editor gesture may author one. Use that for a save-as warning, this for a button.
Whether this format can be authored into at all — false for a
parse-only format (Format::Xml, Format::Asciidoc), where every
gesture refuses and an editor should offer no toolbar. The
open-read-only question.
true is a weaker claim than it looks, and driving per-button state
from it is the mistake this doc exists to prevent: Format::Html
answers true — it spells the inline marks — while
Gesture::SetBlock, the container, code-block, task and footnote
gestures and Gesture::InsertLiteral are all still unsupported there.
Use Format::supports per button.
Trait Implementations§
impl Copy for Format
impl Eq for Format
Source§impl From<Format> for TwigFormat
impl From<Format> for TwigFormat
Source§impl From<Format> for Target
Total: every input format is also an output target, even the ones with no
serializer yet (converting into XML reports Error::UnsupportedFormat
rather than being unnameable).
impl From<Format> for Target
Total: every input format is also an output target, even the ones with no
serializer yet (converting into XML reports Error::UnsupportedFormat
rather than being unnameable).