iced_markdown_editor/lib.rs
1//! # iced-markdown-editor
2//!
3//! A Word-style WYSIWYG CommonMark editor widget for [Iced](https://iced.rs),
4//! with the GFM extensions strikethrough, task lists and tables. Desktop and
5//! web.
6//!
7//! ```ignore
8//! use iced_markdown_editor::{markdown_editor, Action, EditorState, Event};
9//!
10//! struct App { editor: EditorState }
11//!
12//! #[derive(Debug, Clone)]
13//! enum Message { Editor(Action) }
14//!
15//! impl App {
16//! fn update(&mut self, message: Message) -> iced::Task<Message> {
17//! match message {
18//! Message::Editor(action) => {
19//! let output = self.editor.update(action);
20//! if output.events.contains(&Event::Changed) {
21//! println!("{}", self.editor.markdown());
22//! }
23//! output.task.map(Message::Editor)
24//! }
25//! }
26//! }
27//!
28//! fn view(&self) -> iced::Element<'_, Message> {
29//! markdown_editor(&self.editor).view().map(Message::Editor)
30//! }
31//!
32//! fn subscription(&self) -> iced::Subscription<Message> {
33//! self.editor.subscription().map(Message::Editor)
34//! }
35//! }
36//! ```
37//!
38//! ## Features
39//!
40//! | Feature | Default | Adds |
41//! |---|---|---|
42//! | `syntect` | off | [`SyntectHighlighter`], a ready-made code highlighter |
43//! | `images` | off | Showing images, and pasting images from the clipboard (desktop) |
44//!
45//! ## Tables
46//!
47//! GFM tables are edited in place: [`Command::InsertTable`], row and column
48//! commands, [`Command::SetColumnAlign`] with [`ColumnAlign`]. `Tab` moves to
49//! the next cell, `Enter` to the cell below.
50//!
51//! ## Switching features off
52//!
53//! Tables, task lists and strikethrough can be disabled at runtime with
54//! [`Features`] ([`EditorState::features`]).
55//!
56//! ## Theme
57//!
58//! Colours and font sizes come from an [`EditorStyle`]: a preset, one
59//! derived from the application's Iced theme, or your own [`Palette`] and
60//! [`Typography`] ([`EditorState::style`]).
61//!
62//! ```
63//! use iced_markdown_editor::{EditorState, EditorStyle};
64//!
65//! let editor = EditorState::new().style(EditorStyle::dark());
66//!
67//! // Match the rest of the application.
68//! let editor = EditorState::new().style(EditorStyle::from_theme(&iced::Theme::Dark));
69//! ```
70//!
71//! [`EditorState::set_style`] changes it at runtime, e.g. when the
72//! application theme changes.
73//!
74//! ## Languages
75//!
76//! The toolbar, link bar and status bar speak English, German, French,
77//! Spanish and Italian ([`Language`], [`EditorState::language`]). The
78//! document itself is never translated.
79//!
80//! ```
81//! use iced_markdown_editor::{EditorState, Language};
82//!
83//! // E.g. from the operating system locale; unknown tags fall back to English.
84//! let language = Language::from_tag("de-CH").unwrap_or_default();
85//! let editor = EditorState::new().language(language);
86//! ```
87//!
88//! [`EditorState::set_language`] switches it at runtime.
89//!
90//! ## Extensions
91//!
92//! A [`BlockRenderer`] (from your own crate) draws fenced code blocks of
93//! chosen languages, e.g. formulas or diagrams
94//! ([`EditorState::block_renderer`]). A [`CodeHighlighter`] colours code.
95
96#![cfg_attr(docsrs, feature(doc_cfg))]
97
98pub(crate) mod doc;
99pub mod extension;
100pub mod features;
101pub(crate) mod fonts;
102pub mod highlight;
103pub mod i18n;
104pub mod images;
105pub(crate) mod layout;
106mod markdown;
107pub mod page;
108mod render;
109pub mod style;
110pub mod widget;
111pub mod zoom;
112
113#[cfg(feature = "syntect")]
114#[cfg_attr(docsrs, doc(cfg(feature = "syntect")))]
115pub mod syntect;
116
117pub use doc::{BlockKind, ColumnAlign};
118pub use extension::{BlockRenderer, RenderRequest};
119pub use features::Features;
120pub use fonts::FONTS;
121pub use highlight::{CodeHighlighter, HighlightRequest, HighlightSpan};
122pub use i18n::Language;
123pub use images::{
124 ImageId, ImageLoader, ImageMode, ImageRejection, ImageSettings, ImageSource, PastedImage,
125};
126pub use markdown::normalize;
127pub use page::{IsoSeries, Margins, Measure, Orientation, PageSize, Paper, ParseError, Unit};
128pub use style::{EditorStyle, Palette, Typography};
129pub use widget::{
130 Action, Command, DEFAULT_TAB_WIDTH, EditorState, Event, Formatting, MarkdownEditor, Mode,
131 Output, markdown_editor,
132};
133pub use zoom::{KeyBinding, ZoomSettings, ZoomShortcuts};
134
135#[cfg(feature = "syntect")]
136#[cfg_attr(docsrs, doc(cfg(feature = "syntect")))]
137pub use crate::syntect::SyntectHighlighter;