Search documentation of Plushie

# Plushie.Widget.Markdown (Plushie v0.7.2)

Copy Markdown View Source

Markdown display, renders parsed markdown content.

The renderer manages an internal `markdown::Items` cache keyed by node ID.

## Props

Name | Type | Default | Description
--- | --- | --- | ---
`content` | `String.t() | atom()` | required | Raw markdown text (used to seed the parser cache).
`width` | `:fill | :shrink | {:fill_portion, pos_integer()} | number()` | `nil` | Container width.
`text_size` | `number()` | `nil` | Base text size in pixels.
`h1_size` | `number()` | `nil` | Heading 1 size in pixels.
`h2_size` | `number()` | `nil` | Heading 2 size in pixels.
`h3_size` | `number()` | `nil` | Heading 3 size in pixels.
`code_size` | `number()` | `nil` | Code block text size in pixels.
`spacing` | `number()` | `nil` | Spacing between markdown elements in pixels.
`link_color` | `String.t()` | `nil` | Color to override the default link color.
`code_theme` | `String.t() | atom()` | `nil` | Syntax highlighting theme for code blocks.
`event_rate` | `integer()` | `nil` | Max events per second for coalescable events.
`a11y` | `%Plushie.Type.A11y{} | map() | keyword()` | `%{role: :document}` | Accessibility annotations.

## Constructor

    Markdown.new(id, content)
    Markdown.new(id, content, opts)

## Summary

### Types

option()
t()

### Functions

a11y(widget, descriptor)

Accessibility annotations.

build(widget)

Converts this widget struct to a `ui_node()` map.

code_size(widget, descriptor)

Code block text size in pixels.

code_theme(widget, descriptor)

Syntax highlighting theme for code blocks.

content(widget, descriptor)

Raw markdown text (used to seed the parser cache).

event_rate(widget, descriptor)

Max events per second for coalescable events.

h1_size(widget, descriptor)

Heading 1 size in pixels.

h2_size(widget, descriptor)

Heading 2 size in pixels.

h3_size(widget, descriptor)

Heading 3 size in pixels.

link_color(widget, descriptor)

Color to override the default link color.

markdown(id, opts \\ [])

Creates a `:markdown` widget.

new(id, content, opts \\ [])

Creates a new widget struct with the given positional args and keyword options.

spacing(widget, descriptor)

Spacing between markdown elements in pixels.

text_size(widget, descriptor)

Base text size in pixels.

width(widget, descriptor)

Container width.

with_options(widget, opts)

Applies keyword options to an existing widget struct.

## Types

# option()

    @type option() ::
      ((((((((({:width, :fill | :shrink | {:fill_portion, pos_integer()} | number()}
               | {:text_size, number()})
              | {:h1_size, number()})
             | {:h2_size, number()})
            | {:h3_size, number()})
           | {:code_size, number()})
          | {:spacing, number()})
         | {:link_color, atom() | String.t() | map()})
        | {:code_theme, String.t() | atom()})
       | {:event_rate, integer()})
      | {:a11y,
         %Plushie.Type.A11y{
           active_descendant: term(),
           busy: term(),
           described_by: term(),
           description: term(),
           disabled: term(),
           error_message: term(),
           expanded: term(),
           has_popup: term(),
           hidden: term(),
           invalid: term(),
           label: term(),
           label_from: term(),
           labelled_by: term(),
           level: term(),
           live: term(),
           mnemonic: term(),
           modal: term(),
           orientation: term(),
           position_in_set: term(),
           radio_group: term(),
           read_only: term(),
           required: term(),
           role: term(),
           selected: term(),
           size_of_set: term(),
           toggled: term(),
           value: term()
         }
         | map()
         | keyword()}

# t()

    @type t() :: %Plushie.Widget.Markdown{
      a11y:
        (%Plushie.Type.A11y{
           active_descendant: term(),
           busy: term(),
           described_by: term(),
           description: term(),
           disabled: term(),
           error_message: term(),
           expanded: term(),
           has_popup: term(),
           hidden: term(),
           invalid: term(),
           label: term(),
           label_from: term(),
           labelled_by: term(),
           level: term(),
           live: term(),
           mnemonic: term(),
           modal: term(),
           orientation: term(),
           position_in_set: term(),
           radio_group: term(),
           read_only: term(),
           required: term(),
           role: term(),
           selected: term(),
           size_of_set: term(),
           toggled: term(),
           value: term()
         }
         | map()
         | keyword())
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      code_size:
        number()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      code_theme:
        (String.t() | atom())
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      content:
        (String.t() | atom())
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      event_rate:
        integer()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      h1_size:
        number()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      h2_size:
        number()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      h3_size:
        number()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      id: String.t(),
      link_color:
        String.t()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      spacing:
        number()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      text_size:
        number()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      width:
        (:fill | :shrink | {:fill_portion, pos_integer()} | number())
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil
    }

## Functions

# a11y(widget, descriptor)

    @spec a11y(
      widget :: t(),
      value ::
        (%Plushie.Type.A11y{
           active_descendant: term(),
           busy: term(),
           described_by: term(),
           description: term(),
           disabled: term(),
           error_message: term(),
           expanded: term(),
           has_popup: term(),
           hidden: term(),
           invalid: term(),
           label: term(),
           label_from: term(),
           labelled_by: term(),
           level: term(),
           live: term(),
           mnemonic: term(),
           modal: term(),
           orientation: term(),
           position_in_set: term(),
           radio_group: term(),
           read_only: term(),
           required: term(),
           role: term(),
           selected: term(),
           size_of_set: term(),
           toggled: term(),
           value: term()
         }
         | map()
         | keyword())
        | nil
    ) :: t()

Accessibility annotations.

Accepts `%Plushie.Type.A11y{} | map() | keyword()`.

# build(widget)

    @spec build(widget :: t()) :: Plushie.Widget.ui_node()

Converts this widget struct to a `ui_node()` map.

# code_size(widget, descriptor)

    @spec code_size(widget :: t(), value :: number() | nil) :: t()

Code block text size in pixels.

Accepts `number()`.

# code_theme(widget, descriptor)

    @spec code_theme(widget :: t(), value :: (String.t() | atom()) | nil) :: t()

Syntax highlighting theme for code blocks.

Accepts `String.t() | atom()`.

# content(widget, descriptor)

    @spec content(widget :: t(), value :: (String.t() | atom()) | nil) :: t()

Raw markdown text (used to seed the parser cache).

Accepts `String.t() | atom()`.

# event_rate(widget, descriptor)

    @spec event_rate(widget :: t(), value :: integer() | nil) :: t()

Max events per second for coalescable events.

Accepts `integer()`.

# h1_size(widget, descriptor)

    @spec h1_size(widget :: t(), value :: number() | nil) :: t()

Heading 1 size in pixels.

Accepts `number()`.

# h2_size(widget, descriptor)

    @spec h2_size(widget :: t(), value :: number() | nil) :: t()

Heading 2 size in pixels.

Accepts `number()`.

# h3_size(widget, descriptor)

    @spec h3_size(widget :: t(), value :: number() | nil) :: t()

Heading 3 size in pixels.

Accepts `number()`.

# link_color(widget, descriptor)

    @spec link_color(widget :: t(), value :: (atom() | String.t() | map()) | nil) :: t()

Color to override the default link color.

Accepts `String.t()`.

# markdown(id, opts \\ [])

(macro)

Creates a `:markdown` widget.

Shorthand for `new/2`. Import this macro to use the widget name directly in view functions:

    import Plushie.Widget.Markdown, only: [markdown: 2]

    markdown("my-id", prop: value)

# new(id, content, opts \\ [])

Creates a new widget struct with the given positional args and keyword options.

## Arguments

- `id` - unique widget identifier
- `content` - Raw markdown text (used to seed the parser cache).
- `opts` - keyword list of optional props

# spacing(widget, descriptor)

    @spec spacing(widget :: t(), value :: number() | nil) :: t()

Spacing between markdown elements in pixels.

Accepts `number()`.

# text_size(widget, descriptor)

    @spec text_size(widget :: t(), value :: number() | nil) :: t()

Base text size in pixels.

Accepts `number()`.

# width(widget, descriptor)

    @spec width(
      widget :: t(),
      value :: (:fill | :shrink | {:fill_portion, pos_integer()} | number()) | nil
    ) ::
      t()

Container width.

Accepts `:fill | :shrink | {:fill_portion, pos_integer()} | number()`.

# with_options(widget, opts)

    @spec with_options(widget :: t(), opts :: [option()]) :: t()

Applies keyword options to an existing widget struct.