CommonMarkViewer

Struct CommonMarkViewer 

Source
pub struct CommonMarkViewer<'f> { /* private fields */ }

Implementations§

Source§

impl<'f> CommonMarkViewer<'f>

Source

pub fn new() -> Self

Source

pub fn indentation_spaces(self, spaces: usize) -> Self

The amount of spaces a bullet point is indented. By default this is 4 spaces.

Source

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

Source

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

Source

pub fn show_alt_text_on_hover(self, show: bool) -> Self

Show alt text when hovering over images. By default this is enabled.

Source

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/");
Source

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

Source

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

Source

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

Source

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

Source

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),
    );
    }));
Source

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

Source

pub fn show( self, ui: &mut Ui, cache: &mut CommonMarkCache, text: &str, ) -> InnerResponse<()>

Shows rendered markdown

Source

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.

Trait Implementations§

Source§

impl<'f> Debug for CommonMarkViewer<'f>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'f> Default for CommonMarkViewer<'f>

Source§

fn default() -> CommonMarkViewer<'f>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'f> Freeze for CommonMarkViewer<'f>

§

impl<'f> !RefUnwindSafe for CommonMarkViewer<'f>

§

impl<'f> !Send for CommonMarkViewer<'f>

§

impl<'f> !Sync for CommonMarkViewer<'f>

§

impl<'f> Unpin for CommonMarkViewer<'f>

§

impl<'f> !UnwindSafe for CommonMarkViewer<'f>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.