#[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, rendered, serialized (Target::Asciidoc) and authored into:
every block gesture and the inline marks work over an AsciiDoc
document, while the link, image, footnote and table gestures report
Error::UnsupportedFormat — their AsciiDoc spellings have a shape
the gesture algorithms cannot write (see Format::supports).
The parser covers the language as the AsciiDoc ASG schema enumerates
it. The few constructs it leaves unmodelled (menu:, icon:,
include::, the CSV table forms) survive as literal source text
rather than failing the parse.
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.
Sourcepub fn supports_with(
self,
extensions: MarkdownExtensions,
gesture: Gesture,
) -> bool
pub fn supports_with( self, extensions: MarkdownExtensions, gesture: Gesture, ) -> bool
Format::supports for a document parsed with extensions — the same
question asked of the table an Editor created with them actually
holds.
A Markdown extension can widen what may be authored, which is why
the format alone is not always the whole answer. ==x== is literal text
under default options and a mark under
MarkdownExtensions::highlight, so a toggle that wrote it without the
extension would mint bytes the reparse hands back as plain text — one
press that a second press cannot undo. Gesture::SetMarkColor needs
MarkdownExtensions::highlight_colors on top of that.
let exts = MarkdownExtensions { highlight: true, ..Default::default() };
assert!(!Format::Markdown.supports(Gesture::ToggleInline(InlineKind::Mark)));
assert!(Format::Markdown.supports_with(exts, Gesture::ToggleInline(InlineKind::Mark)));Pass the extensions the editor was (or will be) created with in
Editor::new_ext; anything else answers a question about a
document you do not have. extensions is ignored for every
non-Markdown format, exactly as it is at creation.
Whether this format can be authored into at all — false for a
parse-only format (Format::Xml), 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).