`config.define` now propagates schema `default` values, so features like smart quotes no longer need their own fallback constants.
Adds `defineCategory` / `getCategories` for the upcoming configuration manager UI.
Extracts almost all codemirror keyboard shortcuts into proper SB
commands so they can be rebound
Bonus: renders prettier versions of keyboard shortcuts on Mac
No longer cache widget HTML content just widget heights, either way the
widgets will briefly flash as the widget is recalculated and this saves
storage space and reduces issues in Webkit
Now produce "markdown" (or <table> tags for tables) instead of pure
HTML. Hopefully doesn't introduce regressions. Added a test suite for
future iterations.
* Fine tunes a few behaviors (like not adding extra newlines, ever
(should fix#1629))
* When a list item ends with :, it automaticaly indents the next item
* Adds an extensive test suite with various cases
This needs some more testing, but should be a good starting point for
adding more tweaks later.
* tag.define now supports a `tagPage` attribute, allowing what page to
send the user to when clicking on a hash tag in the editor
* index.contentPages() and index.metaPages() are convenience wrappers
around the index.tag("page") collection that filter on content and
meta pages respectively.
Even though the service worker will proactively cache them in the
browser, the browser will not have to load them, parse them, interpret
them unless these languages are actually used. Less JS to load, less
waiting.
* Fix (tasks): Toggle dropdown on re-click and narrow mark decoration range
- Clicking the dropdown icon now dismisses the completion menu if it
is already open (`closeCompletion`).
- The `data-task-state` mark decoration now covers only the inner state
text (excluding brackets). This prevents CodeMirror cursor/editing
issues when the caret is inside the brackets and allows bracket-aware
CSS styling. Example:
```space-style
[data-task-state="DONE"] { color: green; }
[data-task-state="PLANNED"] { color: orange; }
[data-task-state] { font-weight: bold; }
```
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Refactor (tasks): Unify task state data attribute to `data-task-state`
Rename `data-state` to `data-task-state` on extended task state spans in
Markdown renderer and update the corresponding places.
Previously the editor (CodeMirror mark decoration) used
`data-task-state` while the widget HTML renderer used `data-state`,
requiring duplicate CSS selectors. Now a single attribute selector works
everywhere (for example tasks rendered using `template.taskItem` also
follow the styling now):
```css
[data-task-state="PLANNED"] { /* cool CSS here */; }
```
Note: Checkbox inputs (`[ ]`/`[x]`/`[X]`) still use `data-state` since
they follow a different code path.
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
---------
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Add a dropdown picker for custom task states
Add a dropdown picker for custom task states that appears as a small
triangle next to the `[state]` allowing to quickly switch between
defined states with autocomplete.
States marked as done receive strikethrough styling on the task text.
Each state can be styled individually using the `data-task-state`
attribute, for example:
```space-style
[data-task-state=PLANNED] .sb-task-state {
color: black;
background-color: orange;
}
```
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Keep the current task state visible while the dropdown picker is open
Keep the current task state visible while the dropdown picker is open by
disabling built-in filtering and handling it manually — when the state
text exactly matches a known state all options are shown, otherwise
results are filtered by what the user has typed so far.
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Added on-hover completion styling
* Fix: Show all defined task states in the dropdown when clicking the picker on an unrecognized state instead of showing an empty menu
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
---------
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
Co-authored-by: Zef Hemel <zef@zef.me>
* Fix extended task state widget click behavior in widgets
* Add mouse click handler on extended task state span to prevent
CodeMirror from moving selection to widget source on normal click
* Let `Alt+Click` pass to parent div for the "cursor to source" behavior
matching simple checkbox `Alt+Click` behavior
* Skip state cycling on `Alt+Click`
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Prevent task state corruption from concurrent cycling on mobile
On mobile, rapid taps on an enhanced task state (e.g. `[PLANNED]`) could
fire multiple events before the first `taskCycleAtPos` completed. Add
a reentrancy guard to `taskCycleAtPos` so concurrent calls are dropped.
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
---------
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Fix extended task rendering in widgets
This patch addresses several issues.
1. Extended tasks like `[PLANNED]` or `[TODO]` were not rendering
correctly when generated via widgets. The HTML renderer was producing
plain text without brackets or proper styling, while simple `[x]`
tasks worked fine. The fix produces the same DOM structure as
CodeMirror producing coherent styling everywhere.
2. Widget checkboxes are not interactive now. Since widget tasks have no
backing state handler clicking them only caused a misleading visual
toggle with no effect. The `disabled` attribute prevents this
confusion and the dimmed appearanceit signals to the user that the
checkbox is read-only in this context which is the truth.
To see it in action try the following Markdown snippet in SilverBullet:
```
- [x] #foo [att: i]
- [PLANNED] bar #bar [att: i]
${'- [x] #foo [att: i]\n- [PLANNED] bar #bar [att: i]'}
```
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Revert and just prevent widget checkboxes from toggling visually
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Support custom task states in widgets and indexer
Custom task states like `[PLANNED]` or `[IN PROGRESS]` now render
correctly in *widgets*, matching the same DOM structure as CodeMirror
uses in the editor. Widget-rendered tasks that reference a real task
(via `page@pos`) are fully interactive — clicking an extended state
cycles it through the configured states and updates the source task.
Tasks without a reference are disabled to prevent misleading visual
feedback.
The task indexer now respects the `done` flag on custom states defined
via `taskState.define`, so queries like `where not t.done` correctly
exclude tasks in states marked as done. Previously only the built-in
simple tasks (`- [x]` or `- [X]`) states were treated as completed. The
`Task: Remove Completed` command already handled custom done states and
continues to work unchanged.
State cycling now preserves the definition order from `taskState.define`
calls instead of sorting alphabetically. A new `order` field allows
explicit control over the cycle sequence. Without it, states cycle in
definition order. With it, states are sorted by the `order` field value.
This gives users full control over the progression, for example:
PLANNED --> IN PROGRESS --> FINISHED
The `taskState.define` API now validates its input against a schema:
`name` (string, required), `done` (boolean, optional), and `order`
(number, optional).
The `expandMarkdown` no longer injects "fake" `page@pos` references into
tasks rendered via `widget.markdownBlock` or `widget.new` which was
causing broken links and unwanted interactivity on static task content.
The `task:stateChange` event is dispatched when toggling tasks from
widgets, ensuring Lua listeners (such as some custom completed timestamp
management) fire correctly regardless of where the toggle originates.
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
---------
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
Based on https://www.markdownlang.com/extended/footnotes.html
* Both "official" [^1] and [^1]: def
* And inline ^[My foot note]
Features:
* Properly parsed in markdown parser
* Syntax highlighting
* Live Preview to ... when on-hover preview of content, on-click moves
cursor to definition
* Reference completion
* Invalid references are marked
* Fix table row parser
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Remove all `{[command button]}` remnants
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Render `Attribute` nodes in HTML like CodeMirror does
This patch
- ensures always render `Attribute`,
- produces `sb-attribute` span with sub-spans matching CodeMirror DOM,
- removee `preserveAttributes` from Markdown render options and callers.
Finally the attributes looks the same everywhere (table, text, widget).
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
---------
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Fix table row parser
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Remove all `{[command button]}` remnants
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Add tests
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Fix extended task rendering in case of following EoL
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
---------
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
Lua `${...}` expression results are rendered using two parallel paths:
- **HTML path** (display path) for visual display in the editor and
- **Markdown path** (copy path) for the *copy button* output.
Every Lua value is classified as one of:
- **Scalar:** number, string, boolean, or `nil`
- **Empty table:** `{}`
- **Array:** a `LuaTable` with only sequential integer keys (no string keys)
- **Array of tables:** an array where every element is a `LuaTable`
- **Record:** a `LuaTable` with any string key (may also have integer keys)
Scalars are rendered as inline Markdown - wiki links, tags, bold, and
other inline syntax are resolved, `nil` renders as `<span data-empty>`.
Empty tables render as `<table data-table-empty>`.
An array of tables renders as a multi-row `<table>`. Column headers
are the union of all element keys. Each cell value recurses through
the same classification.
An array of scalars (or a mix of scalars and tables) renders as `<ul>`
with one `<li>` per element. Each item value recurses.
A record renders as a single-row `<table>` with one column per key.
Cell values recurse.
Every `<td>` carries `data-table-cell-type` and optionally
`data-table-cell-empty`. Every `<li>` carries `data-list-item-type` and
optionally `data-list-item-empty`. The outermost element carries
`data-type`. These attributes allow CSS styling of rendered widgets.
Nesting is **unlimited**. Tables inside cells, lists inside cells,
tables inside list items all render correctly in HTML.
Scalars render as plain text. Lua `nil` renders as `nil`. Empty tables
render as `*(empty table)*`.
An array of tables renders as a pipe-delimited Markdown table. Nested
values in cells are rendered as Lua literals via `toStringAsync()`
(e.g. `{1, 2, 3}` or `{a = 1}`), since Markdown table cells cannot
contain block-level content.
An array of scalars renders as a Markdown list (`- item`). When a list
item is itself multi-line (a sublist) it uses an empty bullet with
two-space indented content on the next line:
```
- 1
- 2
-
- nested 1
- nested 2
```
Nested tables or arrays **beyond the first list nesting** level are
rendered as Lua literals.
A record renders as a single-row Markdown table.
Column headers follow the order returned by `LuaTable.keys`: string keys
in their insertion order, followed by integer keys in ascending order.
For example, `{a = 1, b = 2, 3, d = 4}` produces columns `a
| b | d | 1`. This is consequence of `LuaTable` storing string keys
and the array part separately (for performance).
Arrays mixing plain scalars and record-like tables (e.g. `{1, 2, 3,
{a=3}}`) were previously rendered as a single flat table due to an
internal JS conversion (`toJS`). They now render as a list, with record
elements shown as nested tables - which more accurately reflects their
Lua structure. This is the only divergence from the original
presentation.
To restore the old tabular layout, wrap all elements as records with
a consistent key:
```lua
-- Before (was a flat table, now a list with nested table):
${{1, 2, 3, {a=3}}}
-- After (explicit records, renders as a table):
${{{value=1}, {value=2}, {value=3}, {a=3}}}
```
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>