Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39fdb8e0e9 | ||
|
|
b5ee79da8e | ||
|
|
ff2f94e549 | ||
|
|
be954bc43e |
Generated
+20
-1
@@ -2948,7 +2948,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "portal"
|
name = "portal"
|
||||||
version = "0.3.7"
|
version = "0.3.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"arc-swap",
|
"arc-swap",
|
||||||
@@ -2970,6 +2970,7 @@ dependencies = [
|
|||||||
"leptos_router",
|
"leptos_router",
|
||||||
"openidconnect",
|
"openidconnect",
|
||||||
"proptest",
|
"proptest",
|
||||||
|
"pulldown-cmark",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_yaml",
|
"serde_yaml",
|
||||||
@@ -3104,6 +3105,24 @@ dependencies = [
|
|||||||
"unarray",
|
"unarray",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pulldown-cmark"
|
||||||
|
version = "0.13.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e9f068eba8e7071c5f9511831b44f32c740d5adf574e990f946ddb53db2f314e"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.13.1",
|
||||||
|
"memchr",
|
||||||
|
"pulldown-cmark-escape",
|
||||||
|
"unicase",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pulldown-cmark-escape"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "007d8adb5ddab6f8e3f491ac63566a7d5002cc7ed73901f72057943fa71ae1ae"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quick-error"
|
name = "quick-error"
|
||||||
version = "1.2.3"
|
version = "1.2.3"
|
||||||
|
|||||||
+4
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "portal"
|
name = "portal"
|
||||||
version = "0.3.7"
|
version = "0.3.9"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
@@ -12,6 +12,9 @@ leptos_meta = { version = "0.8" }
|
|||||||
leptos_router = { version = "0.8" }
|
leptos_router = { version = "0.8" }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
|
# Inline markdown for content descriptions (links, emphasis, code) -
|
||||||
|
# runs on both server and client renders, so not feature-gated.
|
||||||
|
pulldown-cmark = { version = "0.13", default-features = false, features = ["html"] }
|
||||||
|
|
||||||
# --- server only ---
|
# --- server only ---
|
||||||
leptos_axum = { version = "0.8", optional = true }
|
leptos_axum = { version = "0.8", optional = true }
|
||||||
|
|||||||
+68
-7
@@ -49,6 +49,9 @@ class GestureWidget {
|
|||||||
this.hidden = hidden || null;
|
this.hidden = hidden || null;
|
||||||
this.relayUrl = relayUrl || '';
|
this.relayUrl = relayUrl || '';
|
||||||
this.ghost = null;
|
this.ghost = null;
|
||||||
|
this.ownKey = null;
|
||||||
|
this.selected = null; // {key, path, distance} - a place the visitor picked
|
||||||
|
this.seenKeys = new Set();
|
||||||
this.points = [];
|
this.points = [];
|
||||||
this.drawing = false;
|
this.drawing = false;
|
||||||
this.stopped = false;
|
this.stopped = false;
|
||||||
@@ -62,7 +65,12 @@ class GestureWidget {
|
|||||||
container.appendChild(this.canvas);
|
container.appendChild(this.canvas);
|
||||||
this.echoes = document.createElement('div');
|
this.echoes = document.createElement('div');
|
||||||
this.echoes.className = 'gesture-echoes';
|
this.echoes.className = 'gesture-echoes';
|
||||||
|
this.echoes.setAttribute('role', 'listbox');
|
||||||
|
this.echoes.setAttribute('aria-label', 'places near your shape');
|
||||||
container.appendChild(this.echoes);
|
container.appendChild(this.echoes);
|
||||||
|
this.empty = document.createElement('p');
|
||||||
|
this.empty.className = 'gesture-empty';
|
||||||
|
container.appendChild(this.empty);
|
||||||
if (this.relayUrl) {
|
if (this.relayUrl) {
|
||||||
this.status = document.createElement('span');
|
this.status = document.createElement('span');
|
||||||
this.status.className = 'gesture-status offline';
|
this.status.className = 'gesture-status offline';
|
||||||
@@ -116,6 +124,11 @@ class GestureWidget {
|
|||||||
// (and any ghost from the previous round).
|
// (and any ghost from the previous round).
|
||||||
this.drawing = true;
|
this.drawing = true;
|
||||||
this.ghost = null;
|
this.ghost = null;
|
||||||
|
this.ownKey = null;
|
||||||
|
this.selected = null;
|
||||||
|
this.seenKeys.clear();
|
||||||
|
this.echoes.replaceChildren();
|
||||||
|
this.empty.textContent = '';
|
||||||
this.points = [this.pos(e)];
|
this.points = [this.pos(e)];
|
||||||
this.render();
|
this.render();
|
||||||
}
|
}
|
||||||
@@ -214,14 +227,20 @@ class GestureWidget {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.type === 'ack') {
|
if (msg.type === 'ack') {
|
||||||
if (this.points.length >= 2) {
|
this.ownKey = msg.key;
|
||||||
this.setValue({ points: this.normalized(), key: msg.key });
|
|
||||||
}
|
|
||||||
// Version nibble is the key's first hex digit.
|
// Version nibble is the key's first hex digit.
|
||||||
const version = parseInt((msg.key || '0')[0], 16);
|
const version = parseInt((msg.key || '0')[0], 16);
|
||||||
this.ghost = version >= 2 && Array.isArray(msg.path) ? msg.path : null;
|
this.ownGhost = version >= 2 && Array.isArray(msg.path) ? msg.path : null;
|
||||||
this.render();
|
this.applySelection();
|
||||||
} else if (msg.type === 'echo') {
|
// Places arrive right after the ack; say so if none do.
|
||||||
|
clearTimeout(this.emptyTimer);
|
||||||
|
this.emptyTimer = setTimeout(() => {
|
||||||
|
if (!this.echoes.children.length) this.empty.textContent = msg.empty || 'Nothing kept at this shape yet.';
|
||||||
|
}, 1500);
|
||||||
|
} else if (msg.type === 'echo' || msg.type === 'place') {
|
||||||
|
if (!msg.key || this.seenKeys.has(msg.key)) return;
|
||||||
|
this.seenKeys.add(msg.key);
|
||||||
|
this.empty.textContent = '';
|
||||||
this.addEchoThumbnail(msg);
|
this.addEchoThumbnail(msg);
|
||||||
}
|
}
|
||||||
// 'error' frames are intentionally silent: the widget is a
|
// 'error' frames are intentionally silent: the widget is a
|
||||||
@@ -229,9 +248,50 @@ class GestureWidget {
|
|||||||
// alarm anyone mid-form.
|
// alarm anyone mid-form.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The key the input carries: the visitor's own, or the place they
|
||||||
|
// picked (selection re-derives the key - the ghost under the
|
||||||
|
// stroke becomes that place's decode, and the answer records both).
|
||||||
|
applySelection() {
|
||||||
|
if (this.points.length < 2) return;
|
||||||
|
const points = this.normalized();
|
||||||
|
if (this.selected) {
|
||||||
|
this.ghost = this.selected.path;
|
||||||
|
this.setValue({ points, key: this.selected.key, own_key: this.ownKey, selected_from: this.ownKey, selected_distance: this.selected.distance });
|
||||||
|
} else {
|
||||||
|
this.ghost = this.ownGhost || null;
|
||||||
|
this.setValue({ points, key: this.ownKey });
|
||||||
|
}
|
||||||
|
for (const el of this.echoes.children) {
|
||||||
|
el.classList.toggle('selected', !!this.selected && el.dataset.key === this.selected.key);
|
||||||
|
el.setAttribute('aria-selected', String(!!this.selected && el.dataset.key === this.selected.key));
|
||||||
|
}
|
||||||
|
this.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
select(thumb) {
|
||||||
|
const key = thumb.dataset.key;
|
||||||
|
if (this.selected && this.selected.key === key) {
|
||||||
|
this.selected = null;
|
||||||
|
} else {
|
||||||
|
this.selected = { key, path: JSON.parse(thumb.dataset.path), distance: Number(thumb.dataset.distance) };
|
||||||
|
}
|
||||||
|
this.applySelection();
|
||||||
|
}
|
||||||
|
|
||||||
addEchoThumbnail(msg) {
|
addEchoThumbnail(msg) {
|
||||||
const thumb = document.createElement('canvas');
|
const thumb = document.createElement('canvas');
|
||||||
thumb.className = 'gesture-echo';
|
thumb.className = 'gesture-echo' + (msg.type === 'place' ? ' place' : '');
|
||||||
|
thumb.dataset.key = msg.key;
|
||||||
|
thumb.dataset.path = JSON.stringify(msg.path || []);
|
||||||
|
thumb.dataset.distance = String(msg.distance || 0);
|
||||||
|
thumb.setAttribute('role', 'option');
|
||||||
|
thumb.setAttribute('tabindex', '0');
|
||||||
|
thumb.setAttribute('aria-selected', 'false');
|
||||||
|
thumb.title = msg.type === 'place'
|
||||||
|
? `A place with ${msg.recordings || 0} recording${msg.recordings === 1 ? '' : 's'} - tap to make it your address`
|
||||||
|
: 'Someone at this shape right now';
|
||||||
|
thumb.addEventListener('click', () => this.select(thumb));
|
||||||
|
thumb.addEventListener('keydown', (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); this.select(thumb); } });
|
||||||
// Closer strokes render stronger; 500 is comfortably past the
|
// Closer strokes render stronger; 500 is comfortably past the
|
||||||
// relay's default threshold, so everything stays visible.
|
// relay's default threshold, so everything stays visible.
|
||||||
const strength = Math.max(0.35, Math.min(1, 1 - msg.distance / 500));
|
const strength = Math.max(0.35, Math.min(1, 1 - msg.distance / 500));
|
||||||
@@ -296,6 +356,7 @@ class GestureWidget {
|
|||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
this.stopped = true;
|
this.stopped = true;
|
||||||
|
clearTimeout(this.emptyTimer);
|
||||||
if (this.reconnectTimer) clearTimeout(this.reconnectTimer);
|
if (this.reconnectTimer) clearTimeout(this.reconnectTimer);
|
||||||
if (this.ws) {
|
if (this.ws) {
|
||||||
// The close event still fires, but scheduleReconnect
|
// The close event still fires, but scheduleReconnect
|
||||||
|
|||||||
+13
-15
@@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
use crate::answers::{Answer, SelfTransitionAnswer, TransitionAnswers, TransitionItem};
|
use crate::answers::{Answer, SelfTransitionAnswer, TransitionAnswers, TransitionItem};
|
||||||
use crate::auth::{current_user, User};
|
use crate::auth::{current_user, User};
|
||||||
use crate::content::{is_qualified, Alternative, Question, Responsible, SiteConfig, Transition};
|
use crate::content::{is_qualified, render_inline_markdown, Alternative, Question, Responsible, SiteConfig, Transition};
|
||||||
use crate::resource::{get_requirement_binding, get_requirement_options, get_resource};
|
use crate::resource::{get_requirement_binding, get_requirement_options, get_resource};
|
||||||
|
|
||||||
/// The visible site name/wordmark - "portal" is just this codebase's
|
/// The visible site name/wordmark - "portal" is just this codebase's
|
||||||
@@ -680,7 +680,7 @@ fn AlternativeCard(
|
|||||||
return view! {
|
return view! {
|
||||||
<section class="alt-card">
|
<section class="alt-card">
|
||||||
<h2>{alternative.name.clone()}</h2>
|
<h2>{alternative.name.clone()}</h2>
|
||||||
<p class="alt-description">{alternative.description.clone()}</p>
|
<p class="alt-description" inner_html=render_inline_markdown(&alternative.description)></p>
|
||||||
{move || {
|
{move || {
|
||||||
let question_id_for_action = question_id_for_action.clone();
|
let question_id_for_action = question_id_for_action.clone();
|
||||||
let alt_name_for_action = alt_name_for_action.clone();
|
let alt_name_for_action = alt_name_for_action.clone();
|
||||||
@@ -902,7 +902,7 @@ fn AlternativeCard(
|
|||||||
<section class="alt-card">
|
<section class="alt-card">
|
||||||
<AltImages images=alternative.images.clone() />
|
<AltImages images=alternative.images.clone() />
|
||||||
<h2>{alternative.name.clone()}</h2>
|
<h2>{alternative.name.clone()}</h2>
|
||||||
<p class="alt-description">{alternative.description.clone()}</p>
|
<p class="alt-description" inner_html=render_inline_markdown(&alternative.description)></p>
|
||||||
<div class="features">
|
<div class="features">
|
||||||
<For
|
<For
|
||||||
each={
|
each={
|
||||||
@@ -945,22 +945,13 @@ fn AlternativeCard(
|
|||||||
let name = feature.name.clone();
|
let name = feature.name.clone();
|
||||||
move || !name.is_empty()
|
move || !name.is_empty()
|
||||||
}>
|
}>
|
||||||
<h3>
|
<h3>{feature.name.clone()}</h3>
|
||||||
{match feature.link.clone() {
|
|
||||||
Some(href) => view! {
|
|
||||||
<a href=href target="_blank" rel="noopener noreferrer">
|
|
||||||
{feature.name.clone()}
|
|
||||||
</a>
|
|
||||||
}.into_any(),
|
|
||||||
None => feature.name.clone().into_any(),
|
|
||||||
}}
|
|
||||||
</h3>
|
|
||||||
</Show>
|
</Show>
|
||||||
<Show when={
|
<Show when={
|
||||||
let description = feature.description.clone();
|
let description = feature.description.clone();
|
||||||
move || !description.is_empty()
|
move || !description.is_empty()
|
||||||
}>
|
}>
|
||||||
<p>{feature.description.clone()}</p>
|
<p inner_html=render_inline_markdown(&feature.description)></p>
|
||||||
</Show>
|
</Show>
|
||||||
{resource.map(|spec| {
|
{resource.map(|spec| {
|
||||||
view! {
|
view! {
|
||||||
@@ -2008,11 +1999,18 @@ pub async fn submit_answer(
|
|||||||
if alt.disabled {
|
if alt.disabled {
|
||||||
return Err(ServerFnError::new("this alternative isn't open yet"));
|
return Err(ServerFnError::new("this alternative isn't open yet"));
|
||||||
}
|
}
|
||||||
let next = alt.action.clone();
|
|
||||||
let record_as = alt.record_as.clone();
|
let record_as = alt.record_as.clone();
|
||||||
|
|
||||||
let responses: serde_json::Value = serde_json::from_str(&responses_json)
|
let responses: serde_json::Value = serde_json::from_str(&responses_json)
|
||||||
.map_err(|e| ServerFnError::new(format!("invalid responses: {e}")))?;
|
.map_err(|e| ServerFnError::new(format!("invalid responses: {e}")))?;
|
||||||
|
// `/shape/{curve.key}`: the next page may be chosen by the answer.
|
||||||
|
let next = match alt.action.as_deref() {
|
||||||
|
Some(action) => Some(
|
||||||
|
crate::content::template_action(action, &responses)
|
||||||
|
.ok_or_else(|| ServerFnError::new("this answer is missing what the next page needs"))?,
|
||||||
|
),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
let parent_hashes: Vec<String> = parent_hash.into_iter().collect();
|
let parent_hashes: Vec<String> = parent_hash.into_iter().collect();
|
||||||
let timestamp_ms = chrono::Utc::now().timestamp_millis();
|
let timestamp_ms = chrono::Utc::now().timestamp_millis();
|
||||||
|
|||||||
+122
-15
@@ -136,6 +136,76 @@ impl Question {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An alternative's `action` may carry `{field}` / `{field.sub}`
|
||||||
|
/// placeholders filled from the submitted responses - `/shape/{curve.key}`
|
||||||
|
/// lands on the dynamic page `/shape/[key]` for the key the visitor's
|
||||||
|
/// stroke was given. Returns `None` when a placeholder has no value
|
||||||
|
/// (or a non-scalar one) in `responses`.
|
||||||
|
pub fn template_action(action: &str, responses: &serde_json::Value) -> Option<String> {
|
||||||
|
let mut out = String::new();
|
||||||
|
let mut rest = action;
|
||||||
|
while let Some(start) = rest.find('{') {
|
||||||
|
out.push_str(&rest[..start]);
|
||||||
|
let end = rest[start..].find('}')? + start;
|
||||||
|
let path = &rest[start + 1..end];
|
||||||
|
let mut value = responses;
|
||||||
|
for seg in path.split('.') {
|
||||||
|
value = value.get(seg)?;
|
||||||
|
}
|
||||||
|
let scalar = match value {
|
||||||
|
serde_json::Value::String(s) => s.clone(),
|
||||||
|
serde_json::Value::Number(n) => n.to_string(),
|
||||||
|
serde_json::Value::Bool(b) => b.to_string(),
|
||||||
|
_ => return None,
|
||||||
|
};
|
||||||
|
if scalar.is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
// A URL segment: keep it to what a segment can carry.
|
||||||
|
let safe: String = scalar
|
||||||
|
.chars()
|
||||||
|
.map(|c| if c.is_ascii_alphanumeric() || "-_.".contains(c) { c } else { '-' })
|
||||||
|
.collect();
|
||||||
|
out.push_str(&safe);
|
||||||
|
rest = &rest[end + 1..];
|
||||||
|
}
|
||||||
|
out.push_str(rest);
|
||||||
|
Some(out)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Descriptions are inline markdown: `[text](https://…)` links,
|
||||||
|
/// `*emphasis*`, `**strong**`, `` `code` ``. Block structure is
|
||||||
|
/// flattened (a description is one paragraph) and raw HTML in the
|
||||||
|
/// source is dropped, so content can link out without being able to
|
||||||
|
/// inject markup. Link targets are limited to https, mailto and
|
||||||
|
/// site-relative paths; anything else renders as plain text.
|
||||||
|
pub fn render_inline_markdown(text: &str) -> String {
|
||||||
|
use pulldown_cmark::{html, Event, Options, Parser, Tag, TagEnd};
|
||||||
|
let parser = Parser::new_ext(text, Options::empty());
|
||||||
|
let mut in_link = 0usize;
|
||||||
|
let filtered = parser.filter_map(|event| match event {
|
||||||
|
Event::Html(_) | Event::InlineHtml(_) => None,
|
||||||
|
Event::Start(Tag::Paragraph) | Event::End(TagEnd::Paragraph) => None,
|
||||||
|
Event::SoftBreak => Some(Event::Text(" ".into())),
|
||||||
|
Event::Start(Tag::Link { dest_url, .. })
|
||||||
|
if !(dest_url.starts_with("https://")
|
||||||
|
|| dest_url.starts_with("mailto:")
|
||||||
|
|| dest_url.starts_with('/')) =>
|
||||||
|
{
|
||||||
|
in_link += 1;
|
||||||
|
None
|
||||||
|
}
|
||||||
|
Event::End(TagEnd::Link) if in_link > 0 => {
|
||||||
|
in_link -= 1;
|
||||||
|
None
|
||||||
|
}
|
||||||
|
other => Some(other),
|
||||||
|
});
|
||||||
|
let mut out = String::new();
|
||||||
|
html::push_html(&mut out, filtered);
|
||||||
|
out.trim().to_string()
|
||||||
|
}
|
||||||
|
|
||||||
/// Directory-scoped defaults: a `_section.yaml` file applies to every
|
/// Directory-scoped defaults: a `_section.yaml` file applies to every
|
||||||
/// question at or below its directory (nearest ancestor wins per
|
/// question at or below its directory (nearest ancestor wins per
|
||||||
/// field, and a question's own declaration always overrides). This is
|
/// field, and a question's own declaration always overrides). This is
|
||||||
@@ -237,11 +307,6 @@ pub struct Feature {
|
|||||||
/// rendered via Iconify's public SVG API - no icon library bundled.
|
/// rendered via Iconify's public SVG API - no icon library bundled.
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub icon: Option<String>,
|
pub icon: Option<String>,
|
||||||
/// An https URL the card's name links to - an announcement's
|
|
||||||
/// programme page, a venue. Plain-text descriptions can't carry
|
|
||||||
/// links, so this is the one place a card points elsewhere.
|
|
||||||
#[serde(default)]
|
|
||||||
pub link: Option<String>,
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub requirements: Vec<Requirement>,
|
pub requirements: Vec<Requirement>,
|
||||||
/// Live data this feature pulls in. Read-only unless `transitions`
|
/// Live data this feature pulls in. Read-only unless `transitions`
|
||||||
@@ -1022,19 +1087,29 @@ pub fn validate_questions(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for alternative in &question.alternatives {
|
for alternative in &question.alternatives {
|
||||||
for feature in &alternative.features {
|
|
||||||
if let Some(link) = &feature.link {
|
|
||||||
if !link.starts_with("https://") {
|
|
||||||
anyhow::bail!(
|
|
||||||
"question {:?} feature {:?}: link {:?} must be an https:// URL",
|
|
||||||
question.id, feature.name, link
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// A dangling action is a literal dead end: the submit
|
// A dangling action is a literal dead end: the submit
|
||||||
// button navigates to "Nothing here".
|
// button navigates to "Nothing here".
|
||||||
if let Some(action) = &alternative.action {
|
if let Some(action) = &alternative.action {
|
||||||
|
if action.contains('{') {
|
||||||
|
// Placeholders are filled at submit time; the
|
||||||
|
// shape must land on a dynamic page once filled.
|
||||||
|
let probe = template_action(action, &serde_json::json!({}));
|
||||||
|
let filled = {
|
||||||
|
let mut a = action.clone();
|
||||||
|
while let (Some(i), Some(j)) = (a.find('{'), a.find('}')) {
|
||||||
|
a.replace_range(i..=j, "x");
|
||||||
|
}
|
||||||
|
a
|
||||||
|
};
|
||||||
|
let _ = probe;
|
||||||
|
match resolve_question(questions, &filled) {
|
||||||
|
Some(target) if target.is_dynamic() => continue,
|
||||||
|
_ => anyhow::bail!(
|
||||||
|
"question {:?} alternative {:?}: templated action {:?} must land on a dynamic page ([name].yaml)",
|
||||||
|
question.id, alternative.name, action
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
match questions.get(action) {
|
match questions.get(action) {
|
||||||
None => anyhow::bail!(
|
None => anyhow::bail!(
|
||||||
"question {:?} alternative {:?}: action {:?} does not match any declared question id",
|
"question {:?} alternative {:?}: action {:?} does not match any declared question id",
|
||||||
@@ -1912,4 +1987,36 @@ alternatives:
|
|||||||
assert!(bucket_is_read(&qs, "things"));
|
assert!(bucket_is_read(&qs, "things"));
|
||||||
assert!(!bucket_is_read(&qs, EVENTS_BUCKET));
|
assert!(!bucket_is_read(&qs, EVENTS_BUCKET));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── inline markdown ──────────────────────────────────────────────────
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn markdown_links_and_emphasis() {
|
||||||
|
assert_eq!(
|
||||||
|
render_inline_markdown("See [the programme](https://attac.no/x) *soon*."),
|
||||||
|
"See <a href=\"https://attac.no/x\">the programme</a> <em>soon</em>."
|
||||||
|
);
|
||||||
|
assert_eq!(render_inline_markdown("plain text"), "plain text");
|
||||||
|
assert_eq!(render_inline_markdown("a\nb"), "a b");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn markdown_drops_html_and_unsafe_links() {
|
||||||
|
assert_eq!(render_inline_markdown("x <script>y</script> z"), "x y z");
|
||||||
|
assert_eq!(render_inline_markdown("[bad](javascript:alert(1))"), "bad");
|
||||||
|
assert_eq!(render_inline_markdown("[ok](/shape)"), "<a href=\"/shape\">ok</a>");
|
||||||
|
assert_eq!(render_inline_markdown("[mail](mailto:bl@uhhm.no)"), "<a href=\"mailto:bl@uhhm.no\">mail</a>");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn action_templates_from_responses() {
|
||||||
|
let r = serde_json::json!({"curve": {"key": "20aa98", "points": [[0,0]]}, "n": 3});
|
||||||
|
assert_eq!(template_action("/shape/{curve.key}", &r).as_deref(), Some("/shape/20aa98"));
|
||||||
|
assert_eq!(template_action("/x/{n}/y", &r).as_deref(), Some("/x/3/y"));
|
||||||
|
assert_eq!(template_action("/shape", &r).as_deref(), Some("/shape"));
|
||||||
|
assert!(template_action("/shape/{curve.missing}", &r).is_none());
|
||||||
|
assert!(template_action("/shape/{curve.points}", &r).is_none());
|
||||||
|
let odd = serde_json::json!({"k": "a/b c"});
|
||||||
|
assert_eq!(template_action("/p/{k}", &odd).as_deref(), Some("/p/a-b-c"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+39
-4
@@ -448,15 +448,22 @@ main.not-found {
|
|||||||
margin-bottom: 0.15em;
|
margin-bottom: 0.15em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.feature h3 a {
|
/* links inside markdown descriptions */
|
||||||
|
.alt-description a,
|
||||||
|
.feature p a {
|
||||||
color: inherit;
|
color: inherit;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
border-bottom: 0.06rem solid var(--line);
|
border-bottom: 0.06rem solid var(--accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
.feature h3 a:hover {
|
.alt-description a:hover,
|
||||||
|
.feature p a:hover {
|
||||||
color: var(--accent);
|
color: var(--accent);
|
||||||
border-bottom-color: var(--accent);
|
}
|
||||||
|
|
||||||
|
.alt-description code,
|
||||||
|
.feature p code {
|
||||||
|
font-size: 0.9em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.feature p {
|
.feature p {
|
||||||
@@ -590,6 +597,34 @@ textarea:focus {
|
|||||||
opacity: var(--echo-strength, 1);
|
opacity: var(--echo-strength, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* places are pickable: the pick re-derives the input's key */
|
||||||
|
.gesture-echo {
|
||||||
|
cursor: pointer;
|
||||||
|
transition: opacity 0.5s ease, border-color 120ms, transform 120ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gesture-echo:hover,
|
||||||
|
.gesture-echo:focus-visible {
|
||||||
|
border-color: var(--accent);
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gesture-echo.selected {
|
||||||
|
border-color: var(--accent);
|
||||||
|
box-shadow: 0 0 0 0.12rem var(--accent);
|
||||||
|
transform: translateY(-0.1rem);
|
||||||
|
}
|
||||||
|
|
||||||
|
.gesture-empty {
|
||||||
|
margin: 0.5rem 0 0;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
color: var(--ink-dim);
|
||||||
|
}
|
||||||
|
|
||||||
|
.gesture-empty:empty {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.gesture-status {
|
.gesture-status {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0.55rem;
|
top: 0.55rem;
|
||||||
|
|||||||
Reference in New Issue
Block a user