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//! ## Extensions
57//!
58//! A [`BlockRenderer`] (from your own crate) draws fenced code blocks of
59//! chosen languages, e.g. formulas or diagrams
60//! ([`EditorState::block_renderer`]). A [`CodeHighlighter`] colours code.
61
62#![cfg_attr(docsrs, feature(doc_cfg))]
63
64pub(crate) mod doc;
65pub mod extension;
66pub mod features;
67pub(crate) mod fonts;
68pub mod highlight;
69pub mod images;
70pub(crate) mod layout;
71mod markdown;
72pub mod page;
73mod render;
74pub mod style;
75pub mod widget;
76pub mod zoom;
77
78#[cfg(feature = "syntect")]
79#[cfg_attr(docsrs, doc(cfg(feature = "syntect")))]
80pub mod syntect;
81
82pub use doc::{BlockKind, ColumnAlign};
83pub use extension::{BlockRenderer, RenderRequest};
84pub use features::Features;
85pub use fonts::FONTS;
86pub use highlight::{CodeHighlighter, HighlightRequest, HighlightSpan};
87pub use images::{
88 ImageId, ImageLoader, ImageMode, ImageRejection, ImageSettings, ImageSource, PastedImage,
89};
90pub use markdown::normalize;
91pub use page::{IsoSeries, Margins, Measure, Orientation, PageSize, Paper, ParseError, Unit};
92pub use style::{EditorStyle, Palette, Typography};
93pub use widget::{
94 Action, Command, DEFAULT_TAB_WIDTH, EditorState, Event, Formatting, MarkdownEditor, Mode,
95 Output, markdown_editor,
96};
97pub use zoom::{KeyBinding, ZoomSettings, ZoomShortcuts};
98
99#[cfg(feature = "syntect")]
100#[cfg_attr(docsrs, doc(cfg(feature = "syntect")))]
101pub use crate::syntect::SyntectHighlighter;