poka-viewer-common API
<!-- GENERATED by build/scripts/gen-viewer-common-api.py from viewers/poka-viewer-common/src. Do not edit by hand: change the doc comments, then run the script. -->Generated page. The public items of the crate every viewer depends on, with their doc comments.
lib.rs
Helpers shared by the viewer crates (poka-viewers#35).
Every viewer used to carry its own word-for-word copy of these. Escaping is the viewers' main security boundary (poka-viewers#3), so a fix to it now has to be made once, here.
pub use card::{card, card_close, card_open, metadata_sections, row, section, sections_have, text, CARD_CSS}
pub use theme::{error_html, THEME_CSS}
pub fn html_escape(s: &str) -> String
Escape &, <, > and " for use in HTML text and double-quoted
attribute values. Single quotes are left as they are, so never put the
result inside a single-quoted attribute.
pub fn fmt_bytes(b: u64) -> String
Format a byte count as B, KB or MB (1024-based, one decimal place).
pub mod test_support
Shared by the viewer crates' tests (not used by any viewer at run time): a string that is live markup wherever it reaches HTML unescaped, and the check that it did not.
pub const HOSTILE: &str
Breaks out of a double-quoted attribute (PWN"), opens a tag and a
script, and closes a comment.
pub fn assert_inert(html: &str)
Panics unless html shows [HOSTILE] only as text: it must appear
(so the test really reached the field), escaped, and none of its
markup may have survived.
pub const CARD_PLACEHOLDERS: [&str; 9]
The host's placeholders the shared card leaves for the file and the engine run (poka-viewers#98).
pub fn assert_one_card(html: &str, filename: &str, file_size: u64)
Panics unless html holds exactly one shared card, with each of its
placeholders once, and does not show the file's name or size itself:
those come from the card's header, so the Ast's copies must not
appear a second time.
theme.rs
The one palette every viewer's HTML uses: plain black and white that follow
the reader's light/dark system setting (prefers-color-scheme).
Viewer HTML runs in a sandboxed iframe of its own, so the page's CSS does
not reach it; each viewer puts [THEME_CSS] at the top of its <style>
and writes its rules with var(--fg) and friends. The values are the
home screen's tokens. Colour stays only where it carries meaning (diff
add/remove, chart series) or comes from the user's file.
pub const THEME_CSS: &str
A :root block of custom properties (light), a dark override under
prefers-color-scheme: dark, and the page background/foreground. Put it
first inside <style>.
pub fn error_html(viewer: &str, msg: &str) -> String
The HTML a viewer prints when its input would not decode: the theme plus a one-line message, so even a failure follows the reader's light/dark setting.
Theme tokens
The custom properties THEME_CSS defines, read from its source. The light value is the default; the dark value applies under prefers-color-scheme: dark.
| Token | Light | Dark |
|---|---|---|
--bg |
#fff |
#000 |
--fg |
#000 |
#fff |
--muted |
#444 |
#d4d4d4 |
--faint |
#595959 |
#b3b3b3 |
--border |
#767676 |
#666 |
--line |
#ddd |
#2a2a2a |
--surface |
#f5f5f5 |
#111 |
--highlight |
#eee |
#1f1f1f |
--add-bg |
#dafbe1 |
#0b2a12 |
--add-fg |
#0a5c1d |
#6fdd8b |
--rem-bg |
#ffebe9 |
#331015 |
--rem-fg |
#a0122a |
#ff8f9c |