A file in the document (type "attachment"), for example an image.
The JSON keys are camelCase, as in Lexical: key, url, name,
contentType, bytes, width, height, preview and caption.
In HTML, an attachment is a figure with the class kotoba-attachment.
Its caption, when it has one, is its text; else its file name:
- An image has an
img, with the caption (else the name) as itsalt, and afigcaptionwith the caption (else the name). - A PDF (
figure.kotoba-attachment-pdf) has anobjectthat shows it in the browser's viewer, with a download link inside for a browser that has none; with apreview, a link to the PDF with the preview image instead. - A video (
figure.kotoba-attachment-video) has avideowith controls,preload="metadata", no autoplay, thepreviewas its poster, and a download link inside. - Another file has only its
figcaption. Thefigcaptionof a PDF, a video and another file is a download link, with the caption (else the name) as its text; the caption also names the viewer and the player (aria-label).
As plain text, an attachment is its caption, else its name; in Markdown,
 for an image and [caption](url) for another file,
with the name when there is no caption. With the :untrusted policy,
only the caption (else the name) is rendered, escaped.
key- the storage key of the file.url- the URL of the file.name- the file name.content_type- the media type, for example"image/png".bytes- the size of the file.widthandheight- the size of an image in pixels, ornil.preview- the URL of an image of a PDF's first page or a video's poster frame, ornil. The app makes it (see the:previewoption ofKotoba.Live.consume_uploads/4).caption- what the attachment shows, written by the person, ornil: for an image, its alternative text and caption. The editor writes it under the selected attachment;Kotoba.Content.from_markdown/2reads it from the alternative text of.
Summary
Functions
Returns true when the attachment is an image.
Returns the text of the attachment: its caption, or its name when it has none (or a blank one).
Returns true when the attachment is a PDF.
Returns true when the attachment is a video (video/mp4 or video/webm).
Types
Functions
Returns true when the attachment is an image.
Examples
iex> Kotoba.Nodes.Attachment.image?(%Kotoba.Nodes.Attachment{content_type: "image/png"})
true
Returns the text of the attachment: its caption, or its name when it has none (or a blank one).
Examples
iex> Kotoba.Nodes.Attachment.label(%Kotoba.Nodes.Attachment{name: "timeline.png", caption: "The timeline"})
"The timeline"
iex> Kotoba.Nodes.Attachment.label(%Kotoba.Nodes.Attachment{name: "timeline.png", caption: nil})
"timeline.png"
Returns true when the attachment is a PDF.
Returns true when the attachment is a video (video/mp4 or video/webm).