pub struct CommonMarkViewer<'f> { /* private fields */ }Implementations§
Source§impl<'f> CommonMarkViewer<'f>
impl<'f> CommonMarkViewer<'f>
pub fn new() -> Self
Sourcepub fn indentation_spaces(self, spaces: usize) -> Self
pub fn indentation_spaces(self, spaces: usize) -> Self
The amount of spaces a bullet point is indented. By default this is 4 spaces.
Sourcepub fn max_image_width(self, width: Option<usize>) -> Self
pub fn max_image_width(self, width: Option<usize>) -> Self
The maximum size images are allowed to be. They will be scaled down if they are larger
Sourcepub fn default_width(self, width: Option<usize>) -> Self
pub fn default_width(self, width: Option<usize>) -> Self
The default width of the ui. This is only respected if this is larger than
the max_image_width
Sourcepub fn show_alt_text_on_hover(self, show: bool) -> Self
pub fn show_alt_text_on_hover(self, show: bool) -> Self
Show alt text when hovering over images. By default this is enabled.
Sourcepub fn default_implicit_uri_scheme<S: Into<String>>(self, scheme: S) -> Self
pub fn default_implicit_uri_scheme<S: Into<String>>(self, scheme: S) -> Self
Allows changing the default implicit file:// uri scheme.
This does nothing if explicit_image_uri_scheme is enabled
§Example
CommonMarkViewer::new().default_implicit_uri_scheme("https://example.org/");Sourcepub fn explicit_image_uri_scheme(self, use_explicit: bool) -> Self
pub fn explicit_image_uri_scheme(self, use_explicit: bool) -> Self
By default any image without a uri scheme such as foo:// is assumed to
be of the type file://. This assumption can sometimes be wrong or be done
incorrectly, so if you want to always be explicit with the scheme then set
this to true
Sourcepub fn syntax_theme_light<S: Into<String>>(self, theme: S) -> Self
pub fn syntax_theme_light<S: Into<String>>(self, theme: S) -> Self
Set the syntax theme to be used inside code blocks in light mode
Sourcepub fn syntax_theme_dark<S: Into<String>>(self, theme: S) -> Self
pub fn syntax_theme_dark<S: Into<String>>(self, theme: S) -> Self
Set the syntax theme to be used inside code blocks in dark mode
Sourcepub fn alerts(self, alerts: AlertBundle) -> Self
pub fn alerts(self, alerts: AlertBundle) -> Self
Specify what kind of alerts are supported. This can also be used to localize alerts.
By default github flavoured markdown style alerts are used
Sourcepub fn render_math_fn(self, func: Option<&'f RenderMathFn>) -> Self
pub fn render_math_fn(self, func: Option<&'f RenderMathFn>) -> Self
Allows rendering math. This has to be done manually as you might want a different implementation for the web and native.
The example is template code for rendering a svg image. Make sure to enable the
egui_extras/svg feature for the result to show up.
§Example
let mut math_images = Rc::new(RefCell::new(HashMap::new()));
CommonMarkViewer::new()
.render_math_fn(Some(&move |ui, math, inline| {
let mut map = math_images.borrow_mut();
let svg = map
.entry(math.to_string())
.or_insert_with(|| {
if inline {
// render as inline
// dummy data for the example
Arc::new([0])
} else {
Arc::new([0])
}
});
let uri = format!("{}.svg", egui::Id::from(math.to_string()).value());
ui.add(
egui::Image::new(egui::ImageSource::Bytes {
uri: uri.into(),
bytes: egui::load::Bytes::Shared(svg.clone()),
})
.fit_to_original_size(1.0),
);
}));Sourcepub fn render_html_fn(self, func: Option<&'f RenderHtmlFn>) -> Self
pub fn render_html_fn(self, func: Option<&'f RenderHtmlFn>) -> Self
Allows custom handling of html. Enabling this will disable plain text rendering of html blocks. Nodes are included in the provided text
Sourcepub fn show(
self,
ui: &mut Ui,
cache: &mut CommonMarkCache,
text: &str,
) -> InnerResponse<()>
pub fn show( self, ui: &mut Ui, cache: &mut CommonMarkCache, text: &str, ) -> InnerResponse<()>
Shows rendered markdown
Sourcepub fn show_mut(
self,
ui: &mut Ui,
cache: &mut CommonMarkCache,
text: &mut String,
) -> InnerResponse<()>
pub fn show_mut( self, ui: &mut Ui, cache: &mut CommonMarkCache, text: &mut String, ) -> InnerResponse<()>
Shows rendered markdown, and allows the rendered ui to mutate the source text.
The only currently implemented mutation is allowing checkboxes to be toggled through the ui.