gitoria

layouts

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit2dbe0df52dbe0df5Re-vendor Hybriel to the shared static build 0f396652 (plugins; bin/ is git-ignored), compose cache volume + tmpfs /tmp, gate wait 120 s, report 004mre2dbe0df5/components/md-editor/README.md

8.2 KB

  1. # Markdown editor
  2. A Markdown field you edit **visually**: headings look like headings, **bold** is bold, lists are lists — while you type.
  3. The value stays **plain Markdown**. A port of `worldapi-components/md-editor.js` as a pure Hybriel component: no JavaScript
  4. of its own. Demo: `/md-editor`.
  5. Use it in a page:
  6. ```
  7. import MdEditor from './md-editor.hl'
  8. form { method = "post" action = "/save"
  9. MdEditor { name = "summary" value = "# Title" }
  10. }
  11. ```
  12. ## Files
  13. Copy `md-editor.hl` (one file; it has its own `Style`). Nothing else. It needs the WorldAPI colour tokens only as an option:
  14. every colour is `var(--color-…, <base value>)`, so an app that declares the tokens (and its `--color-accent`) wins and
  15. an app without them shows the base look (black, white, greys, no frames — root README "Look").
  16. ## Attributes
  17. | Attribute | Meaning |
  18. |---|---|
  19. | `name` | the field name the Markdown posts under (default `markdown`) |
  20. | `value` | the start Markdown |
  21. | `placeholder` | the grey text of an empty editor (default `Write…`) |
  22. | `rows` | the height of the source view (default 6) |
  23. ## Reading the value
  24. The Markdown lives in a hidden `<input name="…">` inside `<md-editor>`. It posts with the form, and every change fires a
  25. bubbling DOM `input` event on that input: a wrapper element catches it with `on input(e) { text = e.target.value }`
  26. (`e.target.name` says which editor, when there are several). A host cannot read a child member (hybriel#87), so the DOM
  27. event is the way out.
  28. ## What it makes (the Markdown tickets renders)
  29. Headings `#`…`######` (toolbar: H cycles paragraph → H1 → H2 → H3), paragraphs (a single line break is kept), `-` / `1.` lists
  30. (one level), fenced code blocks, `` `code` ``, links `[text](url)` / `<https://…>` / bare `https://…` (only `http(s)://`,
  31. `mailto:`, `/path`, `#anchor` become links), *em*, **strong**. Images `![alt](address)` (http(s) or a `/path`; no `data:` / `javascript:`).
  32. **Tables**: GitHub pipe tables (below). Nothing else (quotes, nesting, HTML) can be made; pasted text is read as Markdown and
  33. pasted HTML is kept as plain text — except an HTML table, which becomes a table.
  34. ## Tables (mission 004, creator notes#5)
  35. The behaviour of notes' `md-editor.js` (9acc27f), built in Hybriel:
  36. ```
  37. | Item | Qty | Note \| x |
  38. | :------- | :-: | --------: |
  39. | **milk** | `2` | fresh |
  40. ```
  41. - **Syntax**: a header row, a delimiter row with the same number of cells (`---`; `:--` left, `:-:` center, `--:` right), then body rows
  42. up to a blank line, a heading, a list or a fence. Outer pipes are optional; `\|` is a pipe inside a cell (also in `code`); inline
  43. Markdown (bold, italic, code, links, images) works in cells. Missing cells are padded, extra cells dropped. A table can follow a
  44. paragraph line directly.
  45. - **Typing**: type the header row (`| Item | Qty |`), Enter, the delimiter row (`|---|--:|`), Enter: the two lines become a table with
  46. an empty row, the caret in its first cell. **Tab** / **Shift+Tab** go to the next / previous cell, Tab in the last cell adds a row;
  47. **Enter** adds a row below; Enter in an empty last row removes it and leaves the table. A cell is one line (Shift+Enter does
  48. nothing there) and takes no block (heading / list / code block buttons and keys do nothing in a cell).
  49. - **Never merged**: Backspace at the start of a cell goes to the end of the cell before; Delete at the end of a cell does nothing;
  50. Backspace / Delete next to a table never joins it with the text (an empty paragraph next to it goes). A selection that reaches
  51. into a table empties the selected cells (the table stays); a table selected as a whole goes.
  52. - **Writing**: an unchanged table is written back byte for byte (its own spelling), also when the text around it changes. A changed
  53. table is written padded to its column widths, `| :--- | :-: | --: |`, with `\|` for a pipe in a cell. A table whose cells are all
  54. empty is dropped.
  55. - **Pasting**: Markdown text with a table becomes a table. Copied HTML with a `<table>` (a spreadsheet, a web page) becomes a table of
  56. its cells' text (`align` / `text-align` of the first row kept, short rows padded); the rest of that HTML is taken as plain text.
  57. Into a cell everything is pasted on one line. The HTML is read in an inert document (no script runs, nothing loads).
  58. - **Look**: thin grey cell lines (`var(--color-border, #999)`), a bold header, no colour. A wide table scrolls inside its own box
  59. (`display: block; overflow-x: auto`), the page does not scroll sideways on a phone.
  60. - **Limits**: adding a row, leaving a table and turning typed lines into a table change the DOM directly, not through the browser's
  61. editing commands, so Ctrl+Z does not take those steps back one by one (typing inside cells undoes as usual). No column
  62. add / remove buttons; rows and columns come from typing or the Markdown source view.
  63. ## Keyboard and toolbar (the toolbar also works on a phone)
  64. | Action | Keys | Toolbar |
  65. |---|---|---|
  66. | bold / italic / inline code | Ctrl+B / Ctrl+I / Ctrl+E (Cmd on Mac) | B, I, `<>` |
  67. | link (add / change / remove) | Ctrl+K | Link → small form (Enter applies, Esc closes) |
  68. | heading 1/2/3, paragraph | Ctrl+Alt+1/2/3, Ctrl+Alt+0 | H |
  69. | bulleted / numbered list | Ctrl+Shift+8 / Ctrl+Shift+7 | • List, 1. List |
  70. | code block | Ctrl+Alt+C | Block |
  71. | undo / redo | Ctrl+Z / Ctrl+Shift+Z | ↶ ↷ |
  72. | send the form | Ctrl+Enter | |
  73. | line break inside a paragraph | Shift+Enter | |
  74. **Typing Markdown formats it**: `# `, `- `, `* `, `1. ` at the start of a line make a heading / list; ```` ``` ```` + Enter a code
  75. block; a closed `**x**`, `*x*`, `_x_`, `` `x` `` becomes formatted (Ctrl+Z turns it back). Backspace at the start of a heading /
  76. list item / code block makes it a paragraph. Ctrl/Cmd+click opens a link.
  77. ## Files and images
  78. Drop files on the editor, paste them, or press **File** in the toolbar (several at once). Each file is sent to the app with
  79. `emit server mdUpload(files)` — the framework uploads it over HTTP in parts and a progress bar per file shows under the toolbar
  80. (`on client uploadProgress`). The **app decides where files are stored**: it must answer that face, or the upload fails
  81. ("The upload failed." under the toolbar). The face gets a list of `{ bytes, name, type, size }` and returns a list of addresses,
  82. one per file, in order. An image (`image/*`) lands in the text as `![name](address)` and is drawn; any other file as `[name](address)`.
  83. Dropped files land where they were dropped, pasted / chosen ones at the caret (or at the end).
  84. ```
  85. on server mdUpload(files) {
  86. let urls = []
  87. for (f of files) { writeFile('storage/files/' + f.name, f.bytes) urls.push('/files/' + f.name) }
  88. return urls
  89. }
  90. ```
  91. The app also sets `uploadMax` on `WebFramework` (default 1 GiB) and serves the address (`directory` route). Demo: `demo.hl` (the site's `lib/uploads.hl`) keeps
  92. files 24 h in `storage/md-files` under a random name, with a known extension only, served with `nosniff` + `sandbox`.
  93. ## Markdown source
  94. A "Markdown source" button in the footer switches the field to a plain textarea holding the raw Markdown (for copying it
  95. out or pasting a larger text in) and back to "Visual editor"; switching back reads the typed text again.
  96. ## How it is built (and its limits)
  97. - The formatted surface is a `contenteditable` element; its content is built with `createElement` / text nodes only (never
  98. `innerHTML` of user text) and is never re-rendered by the framework. Hybriel has no mount event, so a 100 ms CSS animation
  99. on the surface fires `animationiteration` once the page is live and that hands the editor its first content.
  100. - An untouched value is returned byte for byte; a changed value is written in one canonical form (`*em*`, `**strong**`, `- item`,
  101. `1. item`, ```` ``` ```` fences, backslash escapes where needed). What Markdown cannot hold is dropped (empty paragraphs).
  102. - Tables: every cell is a `th` / `td` of a real `<table>` in the surface; the browser edits the text inside the cells, the editor
  103. owns the structure (rows, leaving, the never-merge rules) in `beforeinput`.
  104. - Not ported from the JS version: the `<textarea>` "enhance" mode, `disabled` / `readonly` / `toolbar="none"`, the `[text](url)`
  105. typing rule, per-block byte-for-byte spelling, and the `MdEditor.markdown` test API.
  106. - Undo / redo is the browser's own; typing rules and the toolbar use the browser's editing commands so they undo.

Branches

Latest commits

  • 2dbe0df5Re-vendor Hybriel to the shared static build 0f396652 (plugins; bin/ is git-ignored), compose cache volume + tmpfs /tmp, gate wait 120 s, report 004mre
  • 0adc551emission brief 004mre
  • 1376e905deploy.sh: wait up to DEPLOY_URL_WAIT (120 s) for 200 after the restart, as the other apps (cold compile, hybriel#148)mre
  • c0fdbf6cdocker-compose: init: true (hybriel#156, PID 1 ignored SIGTERM, every restart waited 10 s)mre
  • ecf70665usage: layouts on components a567b57mre
  • 315731efcomponents re-synced to components.hybriel a567b57 (md-editor tables)mre
  • b59e2ee9docs/usage.md + tools/usage.sh: which app carries which component/theme/tokens copy, and whether it matches the sourcemre
  • 0222f67ctheme: two corner radii only (radiusSmall 5px, radiusLarge 10px); check-theme flags any other radius; gate 76/0mre
  • 877b63acdesign rules: two radii only (5px small, 10px large)mre
  • 635234dfcomponents re-synced to components.hybriel 5a98d77 (#15 black/white base look); gate 73/0, check-theme 0, screenshots unchangedmre
  • 876b2064docs: workaround note for hybriel#130 (slot marker mid-line)mre
  • 85b56541layouts mission 002 3/3: same-output tests, letcount, shots ports, docs, reportmre
  • 0f325d3blayouts mission 002 2/3: code rules — styles.hl -> components/styles.hl, the one never-reassigned let dropped; gate 73/0, same outputmre
  • a3e74c8alayouts mission 002 1/3: components re-copied byte-verbatim from components.hybriel 3f93d71 by tools/sync-components.sh (+ --check, components/SOURCE); gate 73/0, check-theme 0mre
  • 80ce6ba9report 001 (mission 075)mre
  • 5c6e338flayouts.worldapi.org in Hybriel: WorldAPI theme (tokens, borderless elements, themed components.hybriel components), shells (header, main/user menu, sidebar overlay, content-first, list-first, three-pane), showcase, check-theme helper; gate 73/0 (mission 075)mre