oficina / mapa Public

Columns (WIP): commands, menus, CSS, server guards, the grammar version, History's words, and the importer's layouts

Insert and / make two to four columns from a block or a selection; Add
a column, Remove this column, Undo columns, Backspace in an empty
column, and opt-cmd arrows between columns (columns.mjs, COL3's tests).
Layouts are a grid of equal tracks that stack below 36rem of the page
column. MarkBlock and Link it refuse fences; Make team page refuses a
cut layout; the four index routes refuse a post counted by another
grammar with the reload sentence (409), forms and the editor carrying
grammar=2. History says Added columns, Added a column, Removed columns.
notionmd writes a column list of two to four columns as a layout,
flattening one, five or a nested list, and neutralises fence-like text
lines. COL7, COL8, COL11 and COL13 gates.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev c0f7272403d9caf6ad027bf76d90687b7ab36e15 parent 3301bf2
55 files changed, +1,159 −32
  • editor/columns.mjs +168 −0
  • editor/columns.test.mjs +138 −0
  • editor/commands.mjs +3 −1
  • editor/keys.mjs +5 −1
  • editor/maketeam.mjs +4 −2
  • editor/saver.mjs +2 −2
  • editor/slash.mjs +2 −1
  • internal/mapa/funcs.go +4 −0
  • internal/mapa/grammar.go +44 −0
  • internal/mapa/handlers_edit.go +2 −2
  • internal/mapa/handlers_history.go +1 −1
  • internal/mapa/markers.go +2 −1
  • internal/mapa/markup/merge_columns.go +36 −0
  • internal/mapa/markup/render.go +6 −0
  • internal/mapa/markup/testdata/corpus/import.json +6 −1
  • internal/mapa/markup/testdata/editor.json +7 −2
  • internal/mapa/markup/testdata/golden.json +6 −1
  • internal/mapa/mentions.go +3 −2
  • internal/mapa/menus.go +15 −0
  • internal/mapa/notionmd/blocks.go +26 −2
  • internal/mapa/notionmd/fixtures_blocks_test.go +24 −0
  • internal/mapa/notionmd/mapper.go +13 −1
  • internal/mapa/notionmd/neutral.go +3 −1
  • internal/mapa/notionmd/parts.go +5 −0
  • internal/mapa/notionmd/testdata/fixtures/columns-empty.json +39 −0
  • internal/mapa/notionmd/testdata/fixtures/columns-fence-text.json +52 −0
  • internal/mapa/notionmd/testdata/fixtures/columns-five.json +106 −0
  • internal/mapa/notionmd/testdata/fixtures/columns-nested.json +84 −0
  • internal/mapa/notionmd/testdata/fixtures/columns-one.json +34 −0
  • internal/mapa/notionmd/testdata/golden/columns-empty.json +5 −0
  • internal/mapa/notionmd/testdata/golden/columns-empty.md +11 −0
  • internal/mapa/notionmd/testdata/golden/columns-fence-text.json +6 −0
  • internal/mapa/notionmd/testdata/golden/columns-fence-text.md +13 −0
  • internal/mapa/notionmd/testdata/golden/columns-five.json +8 −0
  • internal/mapa/notionmd/testdata/golden/columns-five.md +9 −0
  • internal/mapa/notionmd/testdata/golden/columns-nested.json +8 −0
  • internal/mapa/notionmd/testdata/golden/columns-nested.md +15 −0
  • internal/mapa/notionmd/testdata/golden/columns-one.json +5 −0
  • internal/mapa/notionmd/testdata/golden/columns-one.md +1 −0
  • internal/mapa/notionmd/testdata/golden/columns.json +1 −4
  • internal/mapa/notionmd/testdata/golden/columns.md +10 −0
  • internal/mapa/private.go +2 −2
  • internal/mapa/share.go +8 −0
  • internal/mapa/static/prose.css +30 −0
  • internal/mapa/templates/blocks.html +1 −1
  • internal/mapa/templates/conflict.html +1 −1
  • internal/mapa/templates/frame.html +2 −1
  • internal/mapa/templates/partials.html +1 −1
  • internal/mapa/templates/share.html +1 −1
  • internal/mapa/versions.go +4 −0
  • internal/mapa/versions_columns.go +45 −0
  • internal/mapatest/columns_test.go +107 −0
  • internal/mapatest/gate8_test.go +1 −0
  • internal/mapatest/harness_test.go +23 −0
  • internal/mapatest/saving_test.go +1 −0
diff --git a/editor/columns.mjs b/editor/columns.mjs
new file mode 100644
index 0000000..11f03a7
--- /dev/null
+++ b/editor/columns.mjs
@@ -0,0 +1,168 @@
+// columns.mjs — making, changing and undoing column layouts in the
+// editor (columns and icons spec §1.7). A layout is a columns node of two
+// to four column nodes; each column holds ordinary blocks, never another
+// layout. Every command here is one ordinary transaction, so ⌘Z undoes
+// it and autosave writes it as an edit.
+
+import { TextSelection } from 'prosemirror-state'
+import { Fragment } from 'prosemirror-model'
+
+// layoutAround is the layout and column the selection's head is in:
+// { layout, layoutPos, column, columnPos, index }, or null.
+export function layoutAround ($pos) {
+ for (let depth = $pos.depth; depth > 0; depth--) {
+ if ($pos.node(depth).type.name === 'column') {
+ return {
+ layout: $pos.node(depth - 1),
+ layoutPos: $pos.before(depth - 1),
+ column: $pos.node(depth),
+ columnPos: $pos.before(depth),
+ index: $pos.index(depth - 1)
+ }
+ }
+ }
+ return null
+}
+
+function emptyColumn (schema) {
+ return schema.nodes.column.create(null, schema.nodes.paragraph.create())
+}
+
+// topRange is the run of top-level blocks the selection touches.
+function topRange (state) {
+ const { $from, $to } = state.selection
+ if ($from.depth < 1) return null
+ return { from: $from.before(1), to: $to.after(1) }
+}
+
+// makeColumns turns the blocks the selection touches into column 1 of a
+// layout of count columns, the rest empty, with the caret in column 2
+// when column 1 took text, or in column 1 when the block was empty.
+// Not inside a layout: layouts do not nest.
+export function makeColumns (count) {
+ return (state, dispatch) => {
+ const schema = state.schema
+ if (layoutAround(state.selection.$from) || layoutAround(state.selection.$to)) return false
+ const range = topRange(state)
+ if (!range) return false
+ if (dispatch) {
+ const moved = state.doc.slice(range.from, range.to).content
+ const filled = moved.textBetween(0, moved.size, '', '').trim() !== ''
+ const first = schema.nodes.column.create(null,
+ moved.size ? moved : schema.nodes.paragraph.create())
+ const columns = [first]
+ for (let at = 1; at < count; at++) columns.push(emptyColumn(schema))
+ const layout = schema.nodes.columns.create(null, columns)
+ const tr = state.tr.replaceWith(range.from, range.to, layout)
+ const target = filled ? range.from + 1 + first.nodeSize + 1 : range.from + 2
+ tr.setSelection(TextSelection.near(tr.doc.resolve(target)))
+ dispatch(tr.scrollIntoView())
+ }
+ return true
+ }
+}
+
+// addColumn adds an empty column after the caret's, up to four.
+export function addColumn (state, dispatch) {
+ const around = layoutAround(state.selection.$head)
+ if (!around || around.layout.childCount >= 4) return false
+ if (dispatch) {
+ const at = around.columnPos + around.column.nodeSize
+ const tr = state.tr.insert(at, emptyColumn(state.schema))
+ tr.setSelection(TextSelection.near(tr.doc.resolve(at + 2)))
+ dispatch(tr.scrollIntoView())
+ }
+ return true
+}
+
+// removeColumn moves the caret's column's blocks to the end of the
+// column before it (or the start of the next, for the first), and takes
+// the column out. It never deletes text. From two columns it undoes the
+// layout instead.
+export function removeColumn (state, dispatch) {
+ const around = layoutAround(state.selection.$head)
+ if (!around) return false
+ if (around.layout.childCount <= 2) return undoColumns(state, dispatch)
+ if (dispatch) {
+ const kept = written(around.column.content)
+ const tr = state.tr.delete(around.columnPos, around.columnPos + around.column.nodeSize)
+ const neighbour = around.index > 0 ? around.index - 1 : 0
+ let pos = around.layoutPos + 1
+ for (let at = 0; at < neighbour; at++) pos += tr.doc.nodeAt(around.layoutPos).child(at).nodeSize
+ const column = tr.doc.nodeAt(pos)
+ const into = around.index > 0 ? pos + column.nodeSize - 1 : pos + 1
+ if (kept.size) tr.insert(into, kept)
+ tr.setSelection(TextSelection.near(tr.doc.resolve(into)))
+ dispatch(tr.scrollIntoView())
+ }
+ return true
+}
+
+// undoColumns puts every column's blocks at the top level, in reading
+// order, in the layout's place.
+export function undoColumns (state, dispatch) {
+ const around = layoutAround(state.selection.$head)
+ if (!around) return false
+ if (dispatch) {
+ const blocks = []
+ around.layout.forEach(column => column.forEach(child => blocks.push(child)))
+ const content = written(Fragment.from(blocks))
+ const tr = state.tr.replaceWith(around.layoutPos,
+ around.layoutPos + around.layout.nodeSize,
+ content.size ? content : state.schema.nodes.paragraph.create())
+ tr.setSelection(TextSelection.near(tr.doc.resolve(around.layoutPos + 1)))
+ dispatch(tr.scrollIntoView())
+ }
+ return true
+}
+
+// written is content less the empty paragraphs, which write nothing.
+function written (content) {
+ const kept = []
+ content.forEach(node => {
+ if (!(node.type.name === 'paragraph' && node.content.size === 0)) kept.push(node)
+ })
+ return Fragment.from(kept)
+}
+
+// emptyColumnBackspace is Backspace at the start of an empty column that
+// holds only its empty paragraph: the column goes, by removeColumn's rule.
+export function emptyColumnBackspace (state, dispatch) {
+ const { $head, empty } = state.selection
+ const around = layoutAround($head)
+ if (!empty || !around) return false
+ const only = around.column.childCount === 1 &&
+ around.column.firstChild.type.name === 'paragraph' &&
+ around.column.firstChild.content.size === 0
+ if (!only) return false
+ return removeColumn(state, dispatch)
+}
+
+// toColumn moves the caret to the start of the next (step 1) or the
+// previous (step -1) column: ⌥⌘→ and ⌥⌘←.
+export function toColumn (step) {
+ return (state, dispatch) => {
+ const around = layoutAround(state.selection.$head)
+ if (!around) return false
+ const target = around.index + step
+ if (target < 0 || target >= around.layout.childCount) return false
+ if (dispatch) {
+ let pos = around.layoutPos + 1
+ for (let at = 0; at < target; at++) pos += around.layout.child(at).nodeSize
+ dispatch(state.tr.setSelection(TextSelection.near(state.doc.resolve(pos + 1))).scrollIntoView())
+ }
+ return true
+ }
+}
+
+// columnCommands are the Insert menu's and the / list's, by name.
+export function columnCommands () {
+ return {
+ 'insert-columns-2': makeColumns(2),
+ 'insert-columns-3': makeColumns(3),
+ 'insert-columns-4': makeColumns(4),
+ 'add-column': addColumn,
+ 'remove-column': removeColumn,
+ 'undo-columns': undoColumns
+ }
+}
diff --git a/editor/columns.test.mjs b/editor/columns.test.mjs
new file mode 100644
index 0000000..00f0615
--- /dev/null
+++ b/editor/columns.test.mjs
@@ -0,0 +1,138 @@
+// columns.test.mjs — COL3's commands (columns and icons spec §1.7, §9):
+// making a layout from a block and from a selection, adding, removing
+// and undoing columns, Backspace in an empty column, ⌥⌘ arrows, and
+// typed fences. Each result is written, parsed back as the layout the
+// document holds, and undone to the body it started from.
+
+import { test } from 'node:test'
+import assert from 'node:assert/strict'
+import { TextSelection } from 'prosemirror-state'
+import { undo } from 'prosemirror-history'
+import { editor } from './testkit.mjs'
+import { serialise, structureCheck } from './serialize.mjs'
+import { parse, isFence, Columns } from './markup.mjs'
+import {
+ makeColumns, addColumn, removeColumn, undoColumns, emptyColumnBackspace,
+ toColumn, layoutAround
+} from './columns.mjs'
+
+function at (view, pos) {
+ view.dispatch(view.state.tr.setSelection(TextSelection.create(view.state.doc, pos)))
+}
+
+// textPos is the position just inside the first textblock holding text.
+function textPos (view, text) {
+ let found = null
+ view.state.doc.descendants((node, pos) => {
+ if (found === null && node.isTextblock && node.textContent.includes(text)) found = pos + 1
+ return found === null
+ })
+ return found
+}
+
+function saved (view, fidelity) {
+ const check = structureCheck(view.state.doc, fidelity)
+ assert.ok(check.ok, 'the body reloads as this document')
+ return serialise(view.state.doc, fidelity)
+}
+
+function fenceKinds (body) {
+ return parse(body).filter(block => isFence(block.kind)).map(block => block.kind)
+}
+
+function undoAll (view) {
+ while (undo(view.state, tr => view.dispatch(tr)));
+}
+
+const layout = ':::: columns\n\n::: column\nLeft.\n\n:::\n\n::: column\nRight.\n\n:::\n\n::::'
+
+test('a block becomes column 1 of two, and undo gives it back', () => {
+ const body = 'Before.\n\nTurn me.\n\nAfter.'
+ const { view, fidelity } = editor(body)
+ at(view, textPos(view, 'Turn me'))
+ assert.ok(view.run(makeColumns(2)))
+ const out = saved(view, fidelity)
+ assert.equal(out, 'Before.\n\n:::: columns\n\n::: column\nTurn me.\n\n:::\n\n' +
+ '::: column\n:::\n\n::::\n\nAfter.')
+ assert.ok(layoutAround(view.state.selection.$head)?.index === 1, 'the caret is in column 2')
+ undoAll(view)
+ assert.equal(serialise(view.state.doc, fidelity), body)
+})
+
+test('a selection over blocks moves them all into column 1', () => {
+ const body = 'One.\n\nTwo.\n\nThree.'
+ const { view, fidelity } = editor(body)
+ view.dispatch(view.state.tr.setSelection(TextSelection.create(view.state.doc,
+ textPos(view, 'One'), textPos(view, 'Two') + 2)))
+ assert.ok(view.run(makeColumns(3)))
+ const out = saved(view, fidelity)
+ assert.deepEqual(fenceKinds(out).filter(kind => kind === 'column').length, 3)
+ assert.match(out, /::: column\nOne\.\n\nTwo\.\n\n:::/u)
+})
+
+test('no layout is made inside a layout', () => {
+ const { view } = editor(layout)
+ at(view, textPos(view, 'Left'))
+ assert.equal(view.run(makeColumns(2)), false)
+})
+
+test('Add a column, Remove this column and Undo columns', () => {
+ const { view, fidelity } = editor(layout)
+ at(view, textPos(view, 'Left'))
+ assert.ok(view.run(addColumn))
+ assert.equal(fenceKinds(saved(view, fidelity)).filter(kind => kind === 'column').length, 3)
+ at(view, textPos(view, 'Right'))
+ assert.ok(view.run(removeColumn))
+ const two = saved(view, fidelity)
+ assert.equal(fenceKinds(two).filter(kind => kind === 'column').length, 2)
+ assert.match(two, /Right\./u, 'removing a column keeps its text')
+ at(view, textPos(view, 'Left'))
+ assert.ok(view.run(removeColumn), 'from two, removing undoes the layout')
+ const flat = saved(view, fidelity)
+ assert.deepEqual(fenceKinds(flat), [])
+ assert.match(flat, /Left\.\n\nRight\./u)
+})
+
+test('Undo columns puts the blocks in reading order', () => {
+ const { view, fidelity } = editor(layout)
+ at(view, textPos(view, 'Right'))
+ assert.ok(view.run(undoColumns))
+ assert.equal(saved(view, fidelity), 'Left.\n\nRight.')
+})
+
+test('Backspace in an empty column takes the column away', () => {
+ const body = ':::: columns\n\n::: column\nA\n\n:::\n\n::: column\nB\n\n:::\n\n' +
+ '::: column\n:::\n\n::::'
+ const { view, fidelity } = editor(body)
+ let empty = null
+ view.state.doc.descendants((node, pos) => {
+ if (node.type.name === 'column' && node.textContent === '') empty = pos + 2
+ })
+ at(view, empty)
+ assert.ok(view.run(emptyColumnBackspace))
+ assert.equal(fenceKinds(saved(view, fidelity)).filter(kind => kind === 'column').length, 2)
+ at(view, textPos(view, 'A'))
+ assert.equal(view.run(emptyColumnBackspace), false, 'a column with text is not taken')
+})
+
+test('⌥⌘→ and ⌥⌘← move between columns', () => {
+ const { view } = editor(layout)
+ at(view, textPos(view, 'Left'))
+ assert.ok(view.run(toColumn(1)))
+ assert.equal(layoutAround(view.state.selection.$head).index, 1)
+ assert.equal(view.run(toColumn(1)), false)
+ assert.ok(view.run(toColumn(-1)))
+ assert.equal(layoutAround(view.state.selection.$head).index, 0)
+})
+
+test('typing a fence line in a column never closes it (D16)', () => {
+ const { view, fidelity } = editor(layout)
+ const pos = textPos(view, 'Left')
+ for (const typed of [':::', '::: column', ':::: columns', ' :::']) {
+ view.dispatch(view.state.tr.insertText(typed, pos, pos + view.state.doc.resolve(pos).parent.content.size))
+ const out = saved(view, fidelity)
+ assert.deepEqual(fenceKinds(out), [Columns, 'column', 'column_end', 'column', 'column_end', 'columns_end'],
+ `after typing ${JSON.stringify(typed)}: ${JSON.stringify(out)}`)
+ assert.ok(out.includes('​'), 'the typed line is neutralised')
+ }
+})
diff --git a/editor/commands.mjs b/editor/commands.mjs
index 7dca057..b6c3a28 100644
--- a/editor/commands.mjs
+++ b/editor/commands.mjs
@@ -8,6 +8,7 @@ import { setBlockType, wrapIn, toggleMark, chainCommands, exitCode } from 'prose
import { wrapInList } from 'prosemirror-schema-list'
import { TextSelection } from 'prosemirror-state'
import { readsBack, refusals } from './pagelink.mjs'
+import { columnCommands } from './columns.mjs'
// today is the date it is now, ISO, in the zone "today" uses for the
// viewer: their own, else the team's (<body data-zone>, the zone offer's
@@ -135,7 +136,8 @@ export function blockCommands (schema) {
'insert-rule': rule(schema),
'insert-link': insertText('[['),
'insert-date': date(),
- 'insert-paragraph': setBlockType(schema.nodes.paragraph)
+ 'insert-paragraph': setBlockType(schema.nodes.paragraph),
+ ...columnCommands()
}
}
diff --git a/editor/keys.mjs b/editor/keys.mjs
index 6baa80b..300cca0 100644
--- a/editor/keys.mjs
+++ b/editor/keys.mjs
@@ -16,6 +16,7 @@ import { Plugin, TextSelection } from 'prosemirror-state'
import { undoInputRule } from 'prosemirror-inputrules'
import { markCommands, safeUndo, safeRedo } from './commands.mjs'
import { unchip } from './suggest.mjs'
+import { emptyColumnBackspace, toColumn } from './columns.mjs'
// inItem is whether the caret is in a list item.
function inItem (state) {
@@ -75,7 +76,10 @@ export function keys (schema, { save, linkPage = null }) {
const composing = command => (state, dispatch, view) =>
view?.composing ? false : command(state, dispatch, view)
const bindings = keymap({
- Backspace: chainCommands(undoInputRule, unchip),
+ Backspace: chainCommands(undoInputRule, unchip, emptyColumnBackspace),
+ // ⌥⌘→ and ⌥⌘←: the next or previous column (columns and icons §1.7).
+ 'Mod-Alt-ArrowRight': toColumn(1),
+ 'Mod-Alt-ArrowLeft': toColumn(-1),
'Mod-z': safeUndo,
'Shift-Mod-z': safeRedo,
'Mod-y': safeRedo,
diff --git a/editor/maketeam.mjs b/editor/maketeam.mjs
index 17d10e3..941a7a6 100644
--- a/editor/maketeam.mjs
+++ b/editor/maketeam.mjs
@@ -11,7 +11,7 @@
import { Plugin, PluginKey } from 'prosemirror-state'
import { Decoration, DecorationSet } from 'prosemirror-view'
-import { parse, cleanBody } from './markup.mjs'
+import { parse, cleanBody, Grammar } from './markup.mjs'
import { serialiseDetailed } from './serialize.mjs'
import { held } from './busy.mjs'
@@ -152,7 +152,9 @@ export function makeTeamPage ({ saver, fidelity, post, notify }) {
if (!numbers) return { error: 'Your note changed while it was saved. Choose the blocks again.' }
let reply
try {
- reply = await post(`/p/${saver.page}/share`, { title, revision: saver.base, block: numbers.map(String) })
+ reply = await post(`/p/${saver.page}/share`, {
+ title, revision: saver.base, block: numbers.map(String), grammar: String(Grammar)
+ })
} catch {
return { error: 'Nothing was moved: the server could not be reached.' }
}
diff --git a/editor/saver.mjs b/editor/saver.mjs
index 4f0e11b..f57ecc1 100644
--- a/editor/saver.mjs
+++ b/editor/saver.mjs
@@ -26,7 +26,7 @@
// The editor, the network, storage, timers and the page around it are
// all passed in, so the gates can drive it without a browser.
-import { cleanBody, goTrimSpace } from './markup.mjs'
+import { cleanBody, goTrimSpace, Grammar } from './markup.mjs'
export const AUTOSAVE_DELAY = 1200
export const IDLE_COMMIT = 2 * 60 * 1000
@@ -519,7 +519,7 @@ export class Saver {
if (this.conflict?.hunks !== shown.hunks) return 'conflicted'
}
const conflict = this.conflict
- const fields = { current: conflict.against, version: conflict.version }
+ const fields = { current: conflict.against, version: conflict.version, grammar: String(Grammar) }
choices.forEach((choice, index) => { fields[`choice-${index}`] = choice })
let reply
try {
diff --git a/editor/slash.mjs b/editor/slash.mjs
index c5c71a3..ebfc37c 100644
--- a/editor/slash.mjs
+++ b/editor/slash.mjs
@@ -18,7 +18,8 @@ export const blocks = [
['Heading 3', '###', 'insert-h3'], ['List', '-', 'insert-list'],
['Numbered', '1.', 'insert-numbered'], ['Checklist', '- [ ]', 'insert-check'],
['Quote', '>', 'insert-quote'], ['Code', '```', 'insert-code'],
- ['Divider', '---', 'insert-rule'], ['Link to a page', '[[', 'insert-link'],
+ ['Divider', '---', 'insert-rule'], ['Columns', 'two side by side', 'insert-columns-2'],
+ ['Link to a page', '[[', 'insert-link'],
['Date', 'choose a day', 'insert-date-pick'], ['Today’s date', 'today’s note', 'insert-date'],
['Image', 'upload an image', 'insert-image']
]
diff --git a/internal/mapa/funcs.go b/internal/mapa/funcs.go
index 31e7dd2..acbe0f4 100644
--- a/internal/mapa/funcs.go
+++ b/internal/mapa/funcs.go
@@ -2,6 +2,7 @@ package mapa
import (
"amadan.net/oficina/mapa/internal/mapa/locale"
+ "amadan.net/oficina/mapa/internal/mapa/markup"
"html/template"
"strings"
@@ -20,6 +21,9 @@ var templateFuncs = template.FuncMap{
// (import_failures.go).
"importFailure": importFailure,
"hasSuffix": strings.HasSuffix,
+ // grammar is the block grammar a form's indices are counted by
+ // (grammar.go): every form that posts one carries it.
+ "grammar": func() int { return markup.Grammar },
// pageIcon is a page's icon in a glyph cell (looks_render.go).
"pageIcon": pageIcon,
// emojiHref is the icon picker's list (emoji_route.go).
diff --git a/internal/mapa/grammar.go b/internal/mapa/grammar.go
new file mode 100644
index 0000000..c3cae2a
--- /dev/null
+++ b/internal/mapa/grammar.go
@@ -0,0 +1,44 @@
+package mapa
+
+import (
+ "net/http"
+ "strconv"
+
+ "amadan.net/oficina/mapa/internal/mapa/markup"
+)
+
+// The block grammar's version (columns and icons spec D17, §1.10). Block
+// indices are counted by a grammar, and column layouts changed it: a
+// tab on an editor from before them counts a layout's lines as one
+// paragraph. So every route that posts a block or hunk index sends the
+// grammar it counted with, and one counted with another is refused, the
+// person's draft kept, with a sentence the old editor already shows
+// (it shows a reply's error).
+
+// staleGrammarSaid is the refusal's sentence.
+const staleGrammarSaid = "Mapa has been updated. Reload the page to " +
+ "keep editing."
+
+var grammarField = strconv.Itoa(markup.Grammar)
+
+// countedHere wraps a route that reads block or hunk indices: a post
+// whose grammar field is not this one's is refused with 409.
+func countedHere(next http.HandlerFunc) http.HandlerFunc {
+ return func(writer http.ResponseWriter, request *http.Request) {
+ if request.PostFormValue("grammar") == grammarField {
+ next(writer, request)
+ return
+ }
+ writer.Header().Set("Cache-Control", "no-store")
+ if wantsJSON(request) {
+ writer.Header().Set("Content-Type",
+ "application/json; charset=utf-8")
+ writer.WriteHeader(http.StatusConflict)
+ answer(writer, map[string]any{"error": staleGrammarSaid})
+ return
+ }
+ writer.Header().Set("Content-Type", "text/plain; charset=utf-8")
+ writer.WriteHeader(http.StatusConflict)
+ _, _ = writer.Write([]byte(staleGrammarSaid + "\n"))
+ }
+}
diff --git a/internal/mapa/handlers_edit.go b/internal/mapa/handlers_edit.go
index 922b5c0..e3b75be 100644
--- a/internal/mapa/handlers_edit.go
+++ b/internal/mapa/handlers_edit.go
@@ -16,8 +16,8 @@ func (app *app) editorRoutes(router chi.Router) {
router.Get("/p/{id}/edit", app.editPage)
router.Post("/p/{id}", app.savePage)
router.Get("/p/{id}/conflict", app.conflictPage)
- router.Post("/p/{id}/resolve", app.resolve)
- router.Post("/p/{id}/mentions", app.linkMention)
+ router.Post("/p/{id}/resolve", countedHere(app.resolve))
+ router.Post("/p/{id}/mentions", countedHere(app.linkMention))
app.draftRoutes(router)
app.historyRoutes(router)
}
diff --git a/internal/mapa/handlers_history.go b/internal/mapa/handlers_history.go
index 39a259b..765eaf0 100644
--- a/internal/mapa/handlers_history.go
+++ b/internal/mapa/handlers_history.go
@@ -18,7 +18,7 @@ func (app *app) historyRoutes(router chi.Router) {
router.Get("/p/{id}/history/{revision}", app.revision)
router.Post("/p/{id}/history/{revision}", app.revert)
router.Get("/p/{id}/blocks", app.blocks)
- router.Post("/p/{id}/blocks", app.markBlock)
+ router.Post("/p/{id}/blocks", countedHere(app.markBlock))
}
// history is the page with the History panel beside it; a fetch asking
diff --git a/internal/mapa/markers.go b/internal/mapa/markers.go
index d2854a8..2e34387 100644
--- a/internal/mapa/markers.go
+++ b/internal/mapa/markers.go
@@ -37,7 +37,8 @@ func (store *Store) MarkBlock(ctx context.Context, who string, pageID int64,
if marker = block.Marker; marker != "" {
return errNoChange
}
- if block.Kind == markup.Code || block.Kind == markup.Rule {
+ if block.Kind == markup.Code || block.Kind == markup.Rule ||
+ markup.IsFence(block.Kind) {
return ErrNotLinkable
}
if marker, err = newMarker(); err != nil {
diff --git a/internal/mapa/markup/merge_columns.go b/internal/mapa/markup/merge_columns.go
index e1ac130..4573f23 100644
--- a/internal/mapa/markup/merge_columns.go
+++ b/internal/mapa/markup/merge_columns.go
@@ -204,3 +204,39 @@ func wholeColumns(blocks []Block) bool {
}
return !inside
}
+
+// WholeOrInside reports whether the picked blocks cut no column layout:
+// each layout is picked whole, not at all, or only inside one column,
+// fences left alone (columns and icons spec §1.10, Make team page).
+func WholeOrInside(blocks []Block, picked map[int]bool) bool {
+ for start := 0; start < len(blocks); start++ {
+ if blocks[start].Kind != Columns {
+ continue
+ }
+ end := start
+ for end < len(blocks) && blocks[end].Kind != ColumnsEnd {
+ end++
+ }
+ if !layoutPick(blocks[start:end+1], picked, start) {
+ return false
+ }
+ start = end
+ }
+ return true
+}
+
+func layoutPick(layout []Block, picked map[int]bool, offset int) bool {
+ count, fences, columns := 0, 0, map[int]bool{}
+ for at, block := range layout {
+ if !picked[offset+at] {
+ continue
+ }
+ count++
+ if IsFence(block.Kind) {
+ fences++
+ }
+ columns[block.Column] = true
+ }
+ return count == 0 || count == len(layout) ||
+ fences == 0 && len(columns) == 1
+}
diff --git a/internal/mapa/markup/render.go b/internal/mapa/markup/render.go
index 2a3c6fa..043b00d 100644
--- a/internal/mapa/markup/render.go
+++ b/internal/mapa/markup/render.go
@@ -65,6 +65,12 @@ func Render(blocks []Block, resolver Resolver) template.HTML {
index = renderLayout(&out, blocks, index, resolver)
continue
}
+ if IsFence(blocks[index].Kind) {
+ // A fence drawn apart from its layout (History's diff draws
+ // runs of blocks) is no block of its own: it draws nothing.
+ index++
+ continue
+ }
renderBlock(&out, blocks[index], resolver)
index++
}
diff --git a/internal/mapa/markup/testdata/corpus/import.json b/internal/mapa/markup/testdata/corpus/import.json
index eb4f35d..4665ccd 100644
--- a/internal/mapa/markup/testdata/corpus/import.json
+++ b/internal/mapa/markup/testdata/corpus/import.json
@@ -17,7 +17,12 @@
{"name":"import/equation","body":"```math\ne^{i\\pi} + 1 = 0\n```"},
{"name":"import/table","body":"| Name | Role |\n| --- | --- |\n| Ana | Lead/Ops |\n| Bo | Two lines |"},
{"name":"import/table-plain","body":"| a | b | c |\n| d | | |"},
-{"name":"import/columns","body":"Left.\n\nRight."},
+{"name":"import/columns","body":":::: columns\n\n::: column\nLeft.\n\n:::\n\n::: column\nRight.\n\n:::\n\n::::"},
+{"name":"import/columns-one","body":"Alone."},
+{"name":"import/columns-five","body":"A\n\nB\n\nC\n\nD\n\nE"},
+{"name":"import/columns-nested","body":":::: columns\n\n::: column\nIn.\n\nSide.\n\n:::\n\n::: column\nRight.\n\n:::\n\n::::"},
+{"name":"import/columns-fence-text","body":":::: columns\n\n::: column\n​:::\n\n:::\n\n::: column\n​:::: columns\n\n:::\n\n::::"},
+{"name":"import/columns-empty","body":":::: columns\n\n::: column\n:::\n\n::: column\nB.\n\n:::\n\n::::"},
{"name":"import/tabs","body":"**First tab**\n\nIn it."},
{"name":"import/synced","body":"Synced text.\n\nMirrored."},
{"name":"import/synced-unshared","body":"> From Notion: a synced block whose original wasn't shared with the import."},
diff --git a/internal/mapa/markup/testdata/editor.json b/internal/mapa/markup/testdata/editor.json
index a41a4fc..9d41254 100644
--- a/internal/mapa/markup/testdata/editor.json
+++ b/internal/mapa/markup/testdata/editor.json
@@ -1,4 +1,4 @@
-{"clean":"2c083e26b47b5ab95890a0e322b1f2081f2f268c254704a356105c4d2bbf7b44","bodies":[
+{"clean":"b0d984ce1f956c774f79a321085144ac52a390607557172fc2428e00675f1e4e","bodies":[
{"name":"edge/crlf","body":"# [[Acme]]Titl\n\n- # b\n\n![[fichas:c1]][[Acme#^b1|that]]","blocks":["heading:1","item:bullet_list:0:true","paragraph"]},
{"name":"edge/lone-cr","body":"a\n\n*a\nb*\n\n- ![éééééééééééééééééééé](/i/a1)cword![](/i/a1) [[Acme]]\n- ---d~1. ~~|c\n\na","blocks":["paragraph","paragraph","item:bullet_list:0:true","item:bullet_list:0:false","paragraph"]},
{"name":"edge/mixed-line-endings","body":" ^ab\n\n*word","blocks":["paragraph","paragraph"]},
@@ -158,7 +158,12 @@
{"name":"import/equation","body":"```math\n1 =-0\n```\n\n\n![[fichas:c1]]","blocks":["code","paragraph"]},
{"name":"import/table","body":"| Name | Role |\n| --- | --- |\n[[Acme]]| Ana | Lead/Ops |\n| Bo **|1. Two lines |","blocks":["paragraph"]},
{"name":"import/table-plain","body":"word | a [x](https://x.y)| b|` |`\n\n`| c |`\n\n` | d | ||`","blocks":["paragraph","paragraph","paragraph"]},
-{"name":"import/columns","body":"[[2026-11-12]][[Halden Robotics]]Le*ft.R*\n\n- **ight.\n\n-[ ]","blocks":["paragraph","item:bullet_list:0:true","paragraph"]},
+{"name":"import/columns","body":":::: columns\n\n::: column\nLe*ft.*\n\n:::\n\n::: column\n[[2026-11-12]][[Halden Robotics]]- Right.\n\n:::\n\n::::\n\n**\n\n-[ ]","blocks":["columns","column","paragraph","column_end","column","paragraph","column_end","columns_end","paragraph","paragraph"]},
+{"name":"import/columns-one","body":"l[[Acme#^b1|that]]l[[Acme#^b1|that]]o\n\n* **\n\n[[Acme]]","blocks":["paragraph","rule","paragraph"]},
+{"name":"import/columns-five","body":"\n|Aa\n\n**Bé`**![a whiteboard](/i/z13)**``**\n\n[[2026-11-12]]E`Aa\n\n- **Bé`*`\n\nE`Aa\n\n**Bé`**![a whiteboard](/i```","blocks":["paragraph","paragraph","paragraph","item:bullet_list:0:true","paragraph","paragraph"]},
+{"name":"import/columns-nested","body":":::: columns\n\n::: column\nIn.- \n\nword Side.\n\n:::\n\n::: column\nR[[2026-11-12]]ig[ [ ] ] ht.\n\n:::\n\n::::\n\n#` `","blocks":["columns","column","paragraph","paragraph","column_end","column","paragraph","column_end","columns_end","paragraph"]},
+{"name":"import/columns-fence-text","body":":::: columns\n\n::: column\n# :::\n\n:::\n\n::: column\n​:::: - co\n\n:::\n\n::: column\n:::\n\n::: column\n:::\n\n::::","blocks":["columns","column","heading:1","column_end","column","paragraph","column_end","column","column_end","column","column_end","columns_end"]},
+{"name":"import/columns-empty","body":":::: columns\n\n::: column\n[ od a\n\n:::\n\n::: column\n![[fichas:c1]]\n\n:::\n\n::::","blocks":["columns","column","paragraph","column_end","column","paragraph","column_end","columns_end"]},
{"name":"import/tabs","body":".**Firs**\n**t ta```b**\n\n.**Firs**\n**t tab**.**Firs**\n**t tab**\n\n![[fichas:c1]]```![[fichas:c1]]","blocks":["paragraph","paragraph","paragraph"]},
{"name":"import/synced","body":"ced word word text.\n\nrrrroor*ed~~~*.","blocks":["paragraph","paragraph"]},
{"name":"import/synced-unshared","body":"From Notion: a synced block whose or~~~iginal wasn't shared with **th**e import.From Notion: a synced block whose original wasn","blocks":["paragraph"]},
diff --git a/internal/mapa/markup/testdata/golden.json b/internal/mapa/markup/testdata/golden.json
index 8ecaace..153c9fc 100644
--- a/internal/mapa/markup/testdata/golden.json
+++ b/internal/mapa/markup/testdata/golden.json
@@ -158,7 +158,12 @@
{"name":"import/equation","body":"```math\ne^{i\\pi} + 1 = 0\n```","blocks":[{"kind":"code","level":0,"ordered":false,"marker":"","start":0,"end":28,"source":"```math\ne^{i\\pi} + 1 = 0\n```","plain":"e^{i\\pi} + 1 = 0","spans":[]}],"links":[],"images":[],"html":"<pre><code>e^{i\\pi} + 1 = 0</code></pre><p><br class=\"ProseMirror-trailingBreak\"></p>"},
{"name":"import/table","body":"| Name | Role |\n| --- | --- |\n| Ana | Lead/Ops |\n| Bo | Two lines |","blocks":[{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":0,"end":67,"source":"| Name | Role |\n| --- | --- |\n| Ana | Lead/Ops |\n| Bo | Two lines |","plain":"| Name | Role |\n| --- | --- |\n| Ana | Lead/Ops |\n| Bo | Two lines |","spans":[{"kind":"text","text":"| Name | Role |\n| --- | --- |\n| Ana | Lead/Ops |\n| Bo | Two lines |","target":"","anchor":"","url":"","source":"| Name | Role |\n| --- | --- |\n| Ana | Lead/Ops |\n| Bo | Two lines |"}]}],"links":[],"images":[],"html":"<p>| Name | Role |<br>| --- | --- |<br>| Ana | Lead/Ops |<br>| Bo | Two lines |</p>"},
{"name":"import/table-plain","body":"| a | b | c |\n| d | | |","blocks":[{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":0,"end":25,"source":"| a | b | c |\n| d | | |","plain":"| a | b | c |\n| d | | |","spans":[{"kind":"text","text":"| a | b | c |\n| d | | |","target":"","anchor":"","url":"","source":"| a | b | c |\n| d | | |"}]}],"links":[],"images":[],"html":"<p>| a | b | c |<br>| d | | |</p>"},
-{"name":"import/columns","body":"Left.\n\nRight.","blocks":[{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":0,"end":5,"source":"Left.","plain":"Left.","spans":[{"kind":"text","text":"Left.","target":"","anchor":"","url":"","source":"Left."}]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":7,"end":13,"source":"Right.","plain":"Right.","spans":[{"kind":"text","text":"Right.","target":"","anchor":"","url":"","source":"Right."}]}],"links":[],"images":[],"html":"<p>Left.</p><p>Right.</p>"},
+{"name":"import/columns","body":":::: columns\n\n::: column\nLeft.\n\n:::\n\n::: column\nRight.\n\n:::\n\n::::","blocks":[{"kind":"columns","level":2,"ordered":false,"marker":"","start":0,"end":12,"source":":::: columns","plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":14,"end":24,"source":"::: column","column":1,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":25,"end":30,"source":"Left.","column":1,"plain":"Left.","spans":[{"kind":"text","text":"Left.","target":"","anchor":"","url":"","source":"Left."}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":32,"end":35,"source":":::","column":1,"plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":37,"end":47,"source":"::: column","column":2,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":48,"end":54,"source":"Right.","column":2,"plain":"Right.","spans":[{"kind":"text","text":"Right.","target":"","anchor":"","url":"","source":"Right."}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":56,"end":59,"source":":::","column":2,"plain":"","spans":[]},{"kind":"columns_end","level":0,"ordered":false,"marker":"","start":61,"end":65,"source":"::::","plain":"","spans":[]}],"links":[],"images":[],"html":"<div mapa-columns=\"2\"><div mapa-column><p>Left.</p></div><div mapa-column><p>Right.</p></div></div><p><br class=\"ProseMirror-trailingBreak\"></p>"},
+{"name":"import/columns-one","body":"Alone.","blocks":[{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":0,"end":6,"source":"Alone.","plain":"Alone.","spans":[{"kind":"text","text":"Alone.","target":"","anchor":"","url":"","source":"Alone."}]}],"links":[],"images":[],"html":"<p>Alone.</p>"},
+{"name":"import/columns-five","body":"A\n\nB\n\nC\n\nD\n\nE","blocks":[{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":0,"end":1,"source":"A","plain":"A","spans":[{"kind":"text","text":"A","target":"","anchor":"","url":"","source":"A"}]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":3,"end":4,"source":"B","plain":"B","spans":[{"kind":"text","text":"B","target":"","anchor":"","url":"","source":"B"}]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":6,"end":7,"source":"C","plain":"C","spans":[{"kind":"text","text":"C","target":"","anchor":"","url":"","source":"C"}]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":9,"end":10,"source":"D","plain":"D","spans":[{"kind":"text","text":"D","target":"","anchor":"","url":"","source":"D"}]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":12,"end":13,"source":"E","plain":"E","spans":[{"kind":"text","text":"E","target":"","anchor":"","url":"","source":"E"}]}],"links":[],"images":[],"html":"<p>A</p><p>B</p><p>C</p><p>D</p><p>E</p>"},
+{"name":"import/columns-nested","body":":::: columns\n\n::: column\nIn.\n\nSide.\n\n:::\n\n::: column\nRight.\n\n:::\n\n::::","blocks":[{"kind":"columns","level":2,"ordered":false,"marker":"","start":0,"end":12,"source":":::: columns","plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":14,"end":24,"source":"::: column","column":1,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":25,"end":28,"source":"In.","column":1,"plain":"In.","spans":[{"kind":"text","text":"In.","target":"","anchor":"","url":"","source":"In."}]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":30,"end":35,"source":"Side.","column":1,"plain":"Side.","spans":[{"kind":"text","text":"Side.","target":"","anchor":"","url":"","source":"Side."}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":37,"end":40,"source":":::","column":1,"plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":42,"end":52,"source":"::: column","column":2,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":53,"end":59,"source":"Right.","column":2,"plain":"Right.","spans":[{"kind":"text","text":"Right.","target":"","anchor":"","url":"","source":"Right."}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":61,"end":64,"source":":::","column":2,"plain":"","spans":[]},{"kind":"columns_end","level":0,"ordered":false,"marker":"","start":66,"end":70,"source":"::::","plain":"","spans":[]}],"links":[],"images":[],"html":"<div mapa-columns=\"2\"><div mapa-column><p>In.</p><p>Side.</p></div><div mapa-column><p>Right.</p></div></div><p><br class=\"ProseMirror-trailingBreak\"></p>"},
+{"name":"import/columns-fence-text","body":":::: columns\n\n::: column\n​:::\n\n:::\n\n::: column\n​:::: columns\n\n:::\n\n::::","blocks":[{"kind":"columns","level":2,"ordered":false,"marker":"","start":0,"end":12,"source":":::: columns","plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":14,"end":24,"source":"::: column","column":1,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":25,"end":31,"source":"​:::","column":1,"plain":"​:::","spans":[{"kind":"text","text":"​:::","target":"","anchor":"","url":"","source":"​:::"}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":33,"end":36,"source":":::","column":1,"plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":38,"end":48,"source":"::: column","column":2,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":49,"end":64,"source":"​:::: columns","column":2,"plain":"​:::: columns","spans":[{"kind":"text","text":"​:::: columns","target":"","anchor":"","url":"","source":"​:::: columns"}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":66,"end":69,"source":":::","column":2,"plain":"","spans":[]},{"kind":"columns_end","level":0,"ordered":false,"marker":"","start":71,"end":75,"source":"::::","plain":"","spans":[]}],"links":[],"images":[],"html":"<div mapa-columns=\"2\"><div mapa-column><p>​:::</p></div><div mapa-column><p>​:::: columns</p></div></div><p><br class=\"ProseMirror-trailingBreak\"></p>"},
+{"name":"import/columns-empty","body":":::: columns\n\n::: column\n:::\n\n::: column\nB.\n\n:::\n\n::::","blocks":[{"kind":"columns","level":2,"ordered":false,"marker":"","start":0,"end":12,"source":":::: columns","plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":14,"end":24,"source":"::: column","column":1,"plain":"","spans":[]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":25,"end":28,"source":":::","column":1,"plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":30,"end":40,"source":"::: column","column":2,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":41,"end":43,"source":"B.","column":2,"plain":"B.","spans":[{"kind":"text","text":"B.","target":"","anchor":"","url":"","source":"B."}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":45,"end":48,"source":":::","column":2,"plain":"","spans":[]},{"kind":"columns_end","level":0,"ordered":false,"marker":"","start":50,"end":54,"source":"::::","plain":"","spans":[]}],"links":[],"images":[],"html":"<div mapa-columns=\"2\"><div mapa-column><p><br class=\"ProseMirror-trailingBreak\"></p></div><div mapa-column><p>B.</p></div></div><p><br class=\"ProseMirror-trailingBreak\"></p>"},
{"name":"import/tabs","body":"**First tab**\n\nIn it.","blocks":[{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":0,"end":13,"source":"**First tab**","plain":"**First tab**","spans":[{"kind":"text","text":"**First tab**","target":"","anchor":"","url":"","source":"**First tab**"}]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":15,"end":21,"source":"In it.","plain":"In it.","spans":[{"kind":"text","text":"In it.","target":"","anchor":"","url":"","source":"In it."}]}],"links":[],"images":[],"html":"<p><strong>First tab</strong></p><p>In it.</p>"},
{"name":"import/synced","body":"Synced text.\n\nMirrored.","blocks":[{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":0,"end":12,"source":"Synced text.","plain":"Synced text.","spans":[{"kind":"text","text":"Synced text.","target":"","anchor":"","url":"","source":"Synced text."}]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":14,"end":23,"source":"Mirrored.","plain":"Mirrored.","spans":[{"kind":"text","text":"Mirrored.","target":"","anchor":"","url":"","source":"Mirrored."}]}],"links":[],"images":[],"html":"<p>Synced text.</p><p>Mirrored.</p>"},
{"name":"import/synced-unshared","body":"> From Notion: a synced block whose original wasn't shared with the import.","blocks":[{"kind":"quote","level":0,"ordered":false,"marker":"","start":0,"end":75,"source":"> From Notion: a synced block whose original wasn't shared with the import.","plain":"From Notion: a synced block whose original wasn't shared with the import.","spans":[{"kind":"text","text":"From Notion: a synced block whose original wasn't shared with the import.","target":"","anchor":"","url":"","source":"From Notion: a synced block whose original wasn't shared with the import."}]}],"links":[],"images":[],"html":"<blockquote><p>From Notion: a synced block whose original wasn&#39;t shared with the import.</p></blockquote><p><br class=\"ProseMirror-trailingBreak\"></p>"},
diff --git a/internal/mapa/mentions.go b/internal/mapa/mentions.go
index 7037997..b9b0138 100644
--- a/internal/mapa/mentions.go
+++ b/internal/mapa/mentions.go
@@ -176,8 +176,9 @@ func (store *Store) LinkMention(ctx context.Context, who string, sourceID,
func linkFirstMention(body string, number int, title string,
aliases []AliasView) (string, bool) {
blocks := markup.Parse(body)
- if number < 0 || number >= len(blocks) || blocks[number].Kind ==
- markup.Code {
+ if number < 0 || number >= len(blocks) ||
+ blocks[number].Kind == markup.Code ||
+ markup.IsFence(blocks[number].Kind) {
return body, false
}
phrases := phrasesOf(title, aliases)
diff --git a/internal/mapa/menus.go b/internal/mapa/menus.go
index 304122b..d74fce4 100644
--- a/internal/mapa/menus.go
+++ b/internal/mapa/menus.go
@@ -155,6 +155,7 @@ func insertMenu(picker bool) []menuEntry {
if picker {
items = append(items, command("Date…", "insert-date-pick", ""),
command("Image…", "insert-image", ""))
+ items = append(items, columnEntries()...)
}
return items
}
@@ -217,3 +218,17 @@ func pinEntry(page *PageView, pinned bool) menuEntry {
}
return entry
}
+
+// columnEntries are Insert's column layout entries (columns and icons
+// spec §1.7), the page editor's only: two to four columns, and, with the
+// caret in a layout, adding, removing and undoing columns. Outside a
+// layout those three do nothing.
+func columnEntries() []menuEntry {
+ return []menuEntry{divider,
+ command("Two columns", "insert-columns-2", ""),
+ command("Three columns", "insert-columns-3", ""),
+ command("Four columns", "insert-columns-4", ""),
+ command("Add a column", "add-column", ""),
+ command("Remove this column", "remove-column", ""),
+ command("Undo columns", "undo-columns", "")}
+}
diff --git a/internal/mapa/notionmd/blocks.go b/internal/mapa/notionmd/blocks.go
index f8ca58f..d2a22d8 100644
--- a/internal/mapa/notionmd/blocks.go
+++ b/internal/mapa/notionmd/blocks.go
@@ -132,12 +132,36 @@ func (mapper *mapper) divider(Block, int) {
mapper.emit(written{kind: markup.Rule})
}
-// columns writes each column's blocks in order, left to right.
+// columns writes a column list of two to four columns as a column
+// layout (columns and icons spec §6.2): ":::: columns", each column as
+// "::: column" … ":::", then "::::". One column is its blocks in place;
+// five or more, or a list inside a column, at any depth, each column's
+// blocks in order, counted.
func (mapper *mapper) columns(block Block, _ int) {
- mapper.loss(LossColumns)
+ count := len(block.Children)
+ if mapper.inColumn || count < 2 || count > 4 {
+ if count != 1 {
+ mapper.loss(LossColumns)
+ }
+ for _, column := range block.Children {
+ mapper.blocks(column.Children)
+ }
+ return
+ }
+ mapper.fence(markup.Columns, ":::: columns")
+ mapper.inColumn = true
for _, column := range block.Children {
+ mapper.fence(markup.Column, "::: column")
mapper.blocks(column.Children)
+ mapper.fence(markup.ColumnEnd, ":::")
}
+ mapper.inColumn = false
+ mapper.fence(markup.ColumnsEnd, "::::")
+}
+
+// fence adds one of a layout's fence lines.
+func (mapper *mapper) fence(kind, line string) {
+ mapper.out = append(mapper.out, written{kind: kind, literal: line})
}
// container writes a block's children in place, and nothing of its own.
diff --git a/internal/mapa/notionmd/fixtures_blocks_test.go b/internal/mapa/notionmd/fixtures_blocks_test.go
index cbf53c2..ea164cc 100644
--- a/internal/mapa/notionmd/fixtures_blocks_test.go
+++ b/internal/mapa/notionmd/fixtures_blocks_test.go
@@ -67,6 +67,20 @@ func containerFixtures() []fixture {
page("columns", with(Block{Type: "column_list", Known: true},
with(Block{Type: "column", Known: true}, para(txt("Left."))),
with(Block{Type: "column", Known: true}, para(txt("Right."))))),
+ // COL11 (columns and icons spec §6.2): one column, five, a list
+ // inside a column, a typed fence line, and an empty column.
+ page("columns-one", columnList(para(txt("Alone.")))),
+ page("columns-five", columnList(para(txt("A")), para(txt("B")),
+ para(txt("C")), para(txt("D")), para(txt("E")))),
+ page("columns-nested", columnList(with(Block{Type: "column_list",
+ Known: true}, with(Block{Type: "column", Known: true},
+ para(txt("In."))), with(Block{Type: "column", Known: true},
+ para(txt("Side.")))), para(txt("Right.")))),
+ page("columns-fence-text", columnList(para(txt(":::")),
+ para(txt(":::: columns")))),
+ page("columns-empty", with(Block{Type: "column_list", Known: true},
+ Block{Type: "column", Known: true},
+ with(Block{Type: "column", Known: true}, para(txt("B."))))),
page("tabs", with(blk("tab", txt("First tab")), para(txt("In it.")))),
page("synced", with(Block{Type: "synced_block", Known: true},
para(txt("Synced text."))), with(Block{Type: "synced_block",
@@ -153,3 +167,13 @@ const (
hosted2 = "https://s3.us-west-2.amazonaws.com/secure.notion-static.com/" +
"b/report%20final.pdf?X-Amz-Expires=3600"
)
+
+// columnList is a column list, one column per block.
+func columnList(blocks ...Block) Block {
+ list := Block{Type: "column_list", Known: true}
+ for _, block := range blocks {
+ list.Children = append(list.Children,
+ with(Block{Type: "column", Known: true}, block))
+ }
+ return list
+}
diff --git a/internal/mapa/notionmd/mapper.go b/internal/mapa/notionmd/mapper.go
index acbf943..ba9a765 100644
--- a/internal/mapa/notionmd/mapper.go
+++ b/internal/mapa/notionmd/mapper.go
@@ -12,6 +12,9 @@ type mapper struct {
options Options
result Result
out []written
+ // inColumn is set while a column layout's columns are written: a
+ // layout inside one is written flat (columns and icons spec §6.2).
+ inColumn bool
}
// render maps a page: the parent line, the date line, then its blocks,
@@ -69,6 +72,12 @@ func (mapper *mapper) finish() (Result, error) {
if err := mapper.stopped(); err != nil {
return Result{}, err
}
+ if markup.IsFence(block.kind) {
+ // A fence line is the mapper's own, never Notion's text: the
+ // whole body's parse in join holds the layout to it.
+ final = append(final, block)
+ continue
+ }
plain := plainText(block)
mapper.neutralise(&block)
if err := mapper.stopped(); err != nil {
@@ -112,7 +121,10 @@ func join(blocks []written) (string, bool) {
return "", false
}
for index := range again {
- if again[index].Source != parsed[index].Source {
+ if again[index].Source != parsed[index].Source ||
+ again[index].Kind != parsed[index].Kind &&
+ (markup.IsFence(again[index].Kind) ||
+ markup.IsFence(parsed[index].Kind)) {
return "", false
}
}
diff --git a/internal/mapa/notionmd/neutral.go b/internal/mapa/notionmd/neutral.go
index 0743230..4837ec2 100644
--- a/internal/mapa/notionmd/neutral.go
+++ b/internal/mapa/notionmd/neutral.go
@@ -222,7 +222,9 @@ func (mapper *mapper) lineStarts(block *written) {
}
case block.kind == markup.Paragraph ||
(block.kind == markup.Item && index > 0):
- if markup.StartsBlock(text) {
+ // A line that looks like a column fence is broken the same
+ // way (columns and icons spec §6.6, §11.4's new row).
+ if markup.StartsBlock(text) || markup.FenceLike(text) {
first := len(text) - len(strings.TrimLeft(text, " \t"))
block.lines[index] = mapper.inserted(each, first)
}
diff --git a/internal/mapa/notionmd/parts.go b/internal/mapa/notionmd/parts.go
index 3d273f6..875a0a4 100644
--- a/internal/mapa/notionmd/parts.go
+++ b/internal/mapa/notionmd/parts.go
@@ -97,6 +97,8 @@ type written struct {
fence, info, code string
// plain is the block's text for the fallback (§11.4).
plain string
+ // literal is a column layout's fence line, as written.
+ literal string
}
// inline is the block's inline text: its lines, joined.
@@ -110,6 +112,9 @@ func (block written) inline() string {
// source is the block as written: its syntax around its inline text.
func (block written) source() string {
+ if markup.IsFence(block.kind) {
+ return block.literal
+ }
switch block.kind {
case markup.Code:
return codeSource(block)
diff --git a/internal/mapa/notionmd/testdata/fixtures/columns-empty.json b/internal/mapa/notionmd/testdata/fixtures/columns-empty.json
new file mode 100644
index 0000000..e74b4ef
--- /dev/null
+++ b/internal/mapa/notionmd/testdata/fixtures/columns-empty.json
@@ -0,0 +1,39 @@
+{
+ "name": "columns-empty",
+ "page": {
+ "id": "page-columns-empty",
+ "seq": 0,
+ "blocks": [
+ {
+ "id": "",
+ "type": "column_list",
+ "known": true,
+ "children": [
+ {
+ "id": "",
+ "type": "column",
+ "known": true
+ },
+ {
+ "id": "",
+ "type": "column",
+ "known": true,
+ "children": [
+ {
+ "id": "",
+ "type": "paragraph",
+ "known": true,
+ "text": [
+ {
+ "type": "text",
+ "text": "B."
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+}
diff --git a/internal/mapa/notionmd/testdata/fixtures/columns-fence-text.json b/internal/mapa/notionmd/testdata/fixtures/columns-fence-text.json
new file mode 100644
index 0000000..d02fa75
--- /dev/null
+++ b/internal/mapa/notionmd/testdata/fixtures/columns-fence-text.json
@@ -0,0 +1,52 @@
+{
+ "name": "columns-fence-text",
+ "page": {
+ "id": "page-columns-fence-text",
+ "seq": 0,
+ "blocks": [
+ {
+ "id": "",
+ "type": "column_list",
+ "known": true,
+ "children": [
+ {
+ "id": "",
+ "type": "column",
+ "known": true,
+ "children": [
+ {
+ "id": "",
+ "type": "paragraph",
+ "known": true,
+ "text": [
+ {
+ "type": "text",
+ "text": ":::"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "id": "",
+ "type": "column",
+ "known": true,
+ "children": [
+ {
+ "id": "",
+ "type": "paragraph",
+ "known": true,
+ "text": [
+ {
+ "type": "text",
+ "text": ":::: columns"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+}
diff --git a/internal/mapa/notionmd/testdata/fixtures/columns-five.json b/internal/mapa/notionmd/testdata/fixtures/columns-five.json
new file mode 100644
index 0000000..096710d
--- /dev/null
+++ b/internal/mapa/notionmd/testdata/fixtures/columns-five.json
@@ -0,0 +1,106 @@
+{
+ "name": "columns-five",
+ "page": {
+ "id": "page-columns-five",
+ "seq": 0,
+ "blocks": [
+ {
+ "id": "",
+ "type": "column_list",
+ "known": true,
+ "children": [
+ {
+ "id": "",
+ "type": "column",
+ "known": true,
+ "children": [
+ {
+ "id": "",
+ "type": "paragraph",
+ "known": true,
+ "text": [
+ {
+ "type": "text",
+ "text": "A"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "id": "",
+ "type": "column",
+ "known": true,
+ "children": [
+ {
+ "id": "",
+ "type": "paragraph",
+ "known": true,
+ "text": [
+ {
+ "type": "text",
+ "text": "B"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "id": "",
+ "type": "column",
+ "known": true,
+ "children": [
+ {
+ "id": "",
+ "type": "paragraph",
+ "known": true,
+ "text": [
+ {
+ "type": "text",
+ "text": "C"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "id": "",
+ "type": "column",
+ "known": true,
+ "children": [
+ {
+ "id": "",
+ "type": "paragraph",
+ "known": true,
+ "text": [
+ {
+ "type": "text",
+ "text": "D"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "id": "",
+ "type": "column",
+ "known": true,
+ "children": [
+ {
+ "id": "",
+ "type": "paragraph",
+ "known": true,
+ "text": [
+ {
+ "type": "text",
+ "text": "E"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+}
diff --git a/internal/mapa/notionmd/testdata/fixtures/columns-nested.json b/internal/mapa/notionmd/testdata/fixtures/columns-nested.json
new file mode 100644
index 0000000..ee50e97
--- /dev/null
+++ b/internal/mapa/notionmd/testdata/fixtures/columns-nested.json
@@ -0,0 +1,84 @@
+{
+ "name": "columns-nested",
+ "page": {
+ "id": "page-columns-nested",
+ "seq": 0,
+ "blocks": [
+ {
+ "id": "",
+ "type": "column_list",
+ "known": true,
+ "children": [
+ {
+ "id": "",
+ "type": "column",
+ "known": true,
+ "children": [
+ {
+ "id": "",
+ "type": "column_list",
+ "known": true,
+ "children": [
+ {
+ "id": "",
+ "type": "column",
+ "known": true,
+ "children": [
+ {
+ "id": "",
+ "type": "paragraph",
+ "known": true,
+ "text": [
+ {
+ "type": "text",
+ "text": "In."
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "id": "",
+ "type": "column",
+ "known": true,
+ "children": [
+ {
+ "id": "",
+ "type": "paragraph",
+ "known": true,
+ "text": [
+ {
+ "type": "text",
+ "text": "Side."
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "id": "",
+ "type": "column",
+ "known": true,
+ "children": [
+ {
+ "id": "",
+ "type": "paragraph",
+ "known": true,
+ "text": [
+ {
+ "type": "text",
+ "text": "Right."
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+}
diff --git a/internal/mapa/notionmd/testdata/fixtures/columns-one.json b/internal/mapa/notionmd/testdata/fixtures/columns-one.json
new file mode 100644
index 0000000..545e969
--- /dev/null
+++ b/internal/mapa/notionmd/testdata/fixtures/columns-one.json
@@ -0,0 +1,34 @@
+{
+ "name": "columns-one",
+ "page": {
+ "id": "page-columns-one",
+ "seq": 0,
+ "blocks": [
+ {
+ "id": "",
+ "type": "column_list",
+ "known": true,
+ "children": [
+ {
+ "id": "",
+ "type": "column",
+ "known": true,
+ "children": [
+ {
+ "id": "",
+ "type": "paragraph",
+ "known": true,
+ "text": [
+ {
+ "type": "text",
+ "text": "Alone."
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+}
diff --git a/internal/mapa/notionmd/testdata/golden/columns-empty.json b/internal/mapa/notionmd/testdata/golden/columns-empty.json
new file mode 100644
index 0000000..6337d24
--- /dev/null
+++ b/internal/mapa/notionmd/testdata/golden/columns-empty.json
@@ -0,0 +1,5 @@
+{
+ "result": {
+ "Body": ""
+ }
+}
diff --git a/internal/mapa/notionmd/testdata/golden/columns-empty.md b/internal/mapa/notionmd/testdata/golden/columns-empty.md
new file mode 100644
index 0000000..1a128c0
--- /dev/null
+++ b/internal/mapa/notionmd/testdata/golden/columns-empty.md
@@ -0,0 +1,11 @@
+:::: columns
+
+::: column
+:::
+
+::: column
+B.
+
+:::
+
+::::
diff --git a/internal/mapa/notionmd/testdata/golden/columns-fence-text.json b/internal/mapa/notionmd/testdata/golden/columns-fence-text.json
new file mode 100644
index 0000000..2900421
--- /dev/null
+++ b/internal/mapa/notionmd/testdata/golden/columns-fence-text.json
@@ -0,0 +1,6 @@
+{
+ "result": {
+ "Body": "",
+ "neutralised": 2
+ }
+}
diff --git a/internal/mapa/notionmd/testdata/golden/columns-fence-text.md b/internal/mapa/notionmd/testdata/golden/columns-fence-text.md
new file mode 100644
index 0000000..1bbc8fc
--- /dev/null
+++ b/internal/mapa/notionmd/testdata/golden/columns-fence-text.md
@@ -0,0 +1,13 @@
+:::: columns
+
+::: column
+​:::
+
+:::
+
+::: column
+​:::: columns
+
+:::
+
+::::
diff --git a/internal/mapa/notionmd/testdata/golden/columns-five.json b/internal/mapa/notionmd/testdata/golden/columns-five.json
new file mode 100644
index 0000000..74da9cb
--- /dev/null
+++ b/internal/mapa/notionmd/testdata/golden/columns-five.json
@@ -0,0 +1,8 @@
+{
+ "result": {
+ "Body": "",
+ "losses": {
+ "columns": 1
+ }
+ }
+}
diff --git a/internal/mapa/notionmd/testdata/golden/columns-five.md b/internal/mapa/notionmd/testdata/golden/columns-five.md
new file mode 100644
index 0000000..a071035
--- /dev/null
+++ b/internal/mapa/notionmd/testdata/golden/columns-five.md
@@ -0,0 +1,9 @@
+A
+
+B
+
+C
+
+D
+
+E
diff --git a/internal/mapa/notionmd/testdata/golden/columns-nested.json b/internal/mapa/notionmd/testdata/golden/columns-nested.json
new file mode 100644
index 0000000..74da9cb
--- /dev/null
+++ b/internal/mapa/notionmd/testdata/golden/columns-nested.json
@@ -0,0 +1,8 @@
+{
+ "result": {
+ "Body": "",
+ "losses": {
+ "columns": 1
+ }
+ }
+}
diff --git a/internal/mapa/notionmd/testdata/golden/columns-nested.md b/internal/mapa/notionmd/testdata/golden/columns-nested.md
new file mode 100644
index 0000000..940f36a
--- /dev/null
+++ b/internal/mapa/notionmd/testdata/golden/columns-nested.md
@@ -0,0 +1,15 @@
+:::: columns
+
+::: column
+In.
+
+Side.
+
+:::
+
+::: column
+Right.
+
+:::
+
+::::
diff --git a/internal/mapa/notionmd/testdata/golden/columns-one.json b/internal/mapa/notionmd/testdata/golden/columns-one.json
new file mode 100644
index 0000000..6337d24
--- /dev/null
+++ b/internal/mapa/notionmd/testdata/golden/columns-one.json
@@ -0,0 +1,5 @@
+{
+ "result": {
+ "Body": ""
+ }
+}
diff --git a/internal/mapa/notionmd/testdata/golden/columns-one.md b/internal/mapa/notionmd/testdata/golden/columns-one.md
new file mode 100644
index 0000000..75c6da1
--- /dev/null
+++ b/internal/mapa/notionmd/testdata/golden/columns-one.md
@@ -0,0 +1 @@
+Alone.
diff --git a/internal/mapa/notionmd/testdata/golden/columns.json b/internal/mapa/notionmd/testdata/golden/columns.json
index 74da9cb..6337d24 100644
--- a/internal/mapa/notionmd/testdata/golden/columns.json
+++ b/internal/mapa/notionmd/testdata/golden/columns.json
@@ -1,8 +1,5 @@
{
"result": {
- "Body": "",
- "losses": {
- "columns": 1
- }
+ "Body": ""
}
}
diff --git a/internal/mapa/notionmd/testdata/golden/columns.md b/internal/mapa/notionmd/testdata/golden/columns.md
index 385dfe7..2c4bef7 100644
--- a/internal/mapa/notionmd/testdata/golden/columns.md
+++ b/internal/mapa/notionmd/testdata/golden/columns.md
@@ -1,3 +1,13 @@
+:::: columns
+
+::: column
Left.
+:::
+
+::: column
Right.
+
+:::
+
+::::
diff --git a/internal/mapa/private.go b/internal/mapa/private.go
index 335c646..4f02244 100644
--- a/internal/mapa/private.go
+++ b/internal/mapa/private.go
@@ -19,7 +19,7 @@ func (app *app) privateRoutes(router chi.Router) {
router.Get("/scratch/new", app.newScratch)
router.Post("/scratch", app.createScratch)
router.Get("/p/{id}/share", app.shareForm)
- router.Post("/p/{id}/share", app.share)
+ router.Post("/p/{id}/share", countedHere(app.share))
router.Get("/settings", app.settings)
router.Post("/settings", app.saveSettings)
router.Post("/settings/locale", app.saveLocale)
@@ -146,7 +146,7 @@ func (app *app) share(writer http.ResponseWriter, request *http.Request) {
shared, err := app.store.MakeTeamPage(request.Context(), address,
ref.ID, formInt(request, "revision"), chosen, data.Title)
if sayable(err) || errors.Is(err, ErrNothingChosen) ||
- errors.Is(err, ErrNoteChanged) {
+ errors.Is(err, ErrNoteChanged) || errors.Is(err, ErrCutsLayout) {
data.Error = err.Error()
data.Taken = app.index.TitleHref(request.Context(), data.Title)
app.refuseShare(writer, request, data)
diff --git a/internal/mapa/share.go b/internal/mapa/share.go
index a95f102..37f304a 100644
--- a/internal/mapa/share.go
+++ b/internal/mapa/share.go
@@ -12,6 +12,11 @@ import (
// ErrNothingChosen is "Make team page" with no blocks selected.
var ErrNothingChosen = errors.New("Choose at least one block to share.")
+// ErrCutsLayout is a choice that would cut a column layout: blocks must
+// be whole layouts or lie inside one column (columns and icons §1.10).
+var ErrCutsLayout = errors.New("Choose whole columns, or blocks inside " +
+ "one column.")
+
// ErrNoteChanged is "Make team page" over a revision that is no longer
// the note's: the chosen block numbers named that revision's blocks, so
// they are not used (level-up §6.7).
@@ -105,6 +110,9 @@ func splitBlocks(body string, chosen []int,
if len(picked) == 0 {
return "", "", ErrNothingChosen
}
+ if !markup.WholeOrInside(blocks, picked) {
+ return "", "", ErrCutsLayout
+ }
order := make([]int, 0, len(picked))
for number := range picked {
order = append(order, number)
diff --git a/internal/mapa/static/prose.css b/internal/mapa/static/prose.css
index e274648..6a5c064 100644
--- a/internal/mapa/static/prose.css
+++ b/internal/mapa/static/prose.css
@@ -326,3 +326,33 @@ a[mapa-chip] > [mapa-icon] {
vertical-align: -0.12em;
margin-inline-end: var(--rst-sp-1);
}
+
+/* ---- Column layouts (columns and icons spec §1.5): equal tracks,
+ top-aligned, a gap from the spacing scale, no rule, border or fill.
+ They stack below 36rem of the page column, measured on the column,
+ not the window: the sidebar and the Links panel change its width. */
+[mapa-doc] { container-type: inline-size; container-name: mapa-doc; }
+[mapa-columns] {
+ display: grid;
+ grid-template-columns: repeat(var(--mapa-columns, 2), minmax(0, 1fr));
+ column-gap: var(--rst-sp-5);
+ align-items: start;
+ /* The layout sits in the body's rhythm as a paragraph does. */
+ margin: 0 0 0.85em;
+}
+[mapa-columns="3"] { --mapa-columns: 3; }
+[mapa-columns="4"] { --mapa-columns: 4; }
+[mapa-column] { min-inline-size: 0; }
+[mapa-column] > :first-child { margin-block-start: 0; }
+[mapa-column] > :last-child { margin-block-end: 0; }
+@container mapa-doc (max-width: 36rem) {
+ /* Stacked, the columns read as consecutive blocks: the body's own
+ gap between them. */
+ [mapa-columns] { grid-template-columns: minmax(0, 1fr); row-gap: 0.85em; }
+}
+/* While editing, the layout the caret is in shows where its columns are,
+ as an outline, which moves nothing. */
+[mapa-body].ProseMirror [mapa-columns]:focus-within > [mapa-column] {
+ outline: 1px dashed color-mix(in oklab, var(--rst-line) 80%, transparent);
+ outline-offset: var(--rst-sp-1);
+}
diff --git a/internal/mapa/templates/blocks.html b/internal/mapa/templates/blocks.html
index 0ef6460..a68453f 100644
--- a/internal/mapa/templates/blocks.html
+++ b/internal/mapa/templates/blocks.html
@@ -4,6 +4,6 @@
{{template "notice" $d.Notice}}
{{with $d.Marker}}<p mapa-copy>Link: <code>[[{{$page.Title}}#^{{.}}]]</code></p>{{end}}
<ul mapa-list>
-{{range $d.Blocks}}<li><div mapa-choice-body>{{.HTML}}</div><form method="post" action="/p/{{$page.Public}}/blocks"><input type="hidden" name="block" value="{{.Block}}"><button rst-btn type="submit">Link to this block</button></form></li>
+{{range $d.Blocks}}<li><div mapa-choice-body>{{.HTML}}</div><form method="post" action="/p/{{$page.Public}}/blocks"><input type="hidden" name="grammar" value="{{grammar}}"><input type="hidden" name="block" value="{{.Block}}"><button rst-btn type="submit">Link to this block</button></form></li>
{{end}}</ul>
{{end}}
diff --git a/internal/mapa/templates/conflict.html b/internal/mapa/templates/conflict.html
index 0c7a4ce..c1ca8ac 100644
--- a/internal/mapa/templates/conflict.html
+++ b/internal/mapa/templates/conflict.html
@@ -1,7 +1,7 @@
{{define "content"}}{{$d := .Data}}{{$page := $d.Page}}
{{template "back-nav" dict "Href" $page.Href "Label" $page.Label}}
{{template "page-header" dict "Title" "Choose what to keep" "Sub" "Someone saved this page while you were editing. Nothing of yours is lost: your text is kept until you choose."}}
-<form rst-form method="post" action="/p/{{$page.Public}}/resolve" mapa-conflict>
+<form rst-form method="post" action="/p/{{$page.Public}}/resolve" mapa-conflict><input type="hidden" name="grammar" value="{{grammar}}">
<input type="hidden" name="current" value="{{$d.Conflict.Current}}">
<input type="hidden" name="version" value="{{$d.Conflict.Version}}">
{{if $d.Conflict.NoBase}}
diff --git a/internal/mapa/templates/frame.html b/internal/mapa/templates/frame.html
index 74a7a87..fac0377 100644
--- a/internal/mapa/templates/frame.html
+++ b/internal/mapa/templates/frame.html
@@ -95,7 +95,7 @@
{{if .Items}}{{$target := .Target}}<ul mapa-refs>
{{range .Items}}<li><a mapa-ref-src href="{{.Href}}">{{if eq .Kind "daily"}}{{icon "calendar"}}{{else if eq .Kind "scratch"}}{{icon "file"}}{{else}}{{pageIcon .Look "file-text"}}{{end}}<span>{{.Label}}</span>{{if ne .Kind "page"}}<span mapa-only-you>{{icon "lock"}}Only you</span>{{end}}</a>
{{$source := .Public}}{{range .Contexts}}<div mapa-ref-ctx>{{.HTML}}
-{{if $target}}<form method="post" action="/p/{{$target}}/mentions"><input type="hidden" name="source" value="{{$source}}"><input type="hidden" name="block" value="{{.Block}}"><button rst-btn="sm" type="submit">{{icon "link"}}Link it</button></form>{{end}}
+{{if $target}}<form method="post" action="/p/{{$target}}/mentions"><input type="hidden" name="grammar" value="{{grammar}}"><input type="hidden" name="source" value="{{$source}}"><input type="hidden" name="block" value="{{.Block}}"><button rst-btn="sm" type="submit">{{icon "link"}}Link it</button></form>{{end}}
</div>{{end}}</li>
{{end}}</ul>
{{else}}<p mapa-meta>{{.Empty}}</p>{{end}}
@@ -211,6 +211,7 @@
<dt><kbd mapa-kbd>⌥F10</kbd></dt><dd>Move to the selection's toolbar, Make team page included</dd>
<dt><kbd mapa-kbd>Tab</kbd> <kbd mapa-kbd>⇧Tab</kbd></dt><dd>In a list, indent or outdent the item</dd>
<dt><kbd mapa-kbd>Esc</kbd>, then <kbd mapa-kbd>Tab</kbd></dt><dd>Leave the page's text, even inside a list</dd>
+ <dt><kbd mapa-kbd>⌥⌘→</kbd> <kbd mapa-kbd>⌥⌘←</kbd></dt><dd>In columns, the next or previous column</dd>
<dt><kbd mapa-kbd>⌘Z</kbd> <kbd mapa-kbd>⇧⌘Z</kbd></dt><dd>Undo, redo</dd>
<dt><kbd mapa-kbd>Esc</kbd></dt><dd>Close a menu, a list or this dialog</dd>
</dl>
diff --git a/internal/mapa/templates/partials.html b/internal/mapa/templates/partials.html
index 3399ae3..0c62a67 100644
--- a/internal/mapa/templates/partials.html
+++ b/internal/mapa/templates/partials.html
@@ -10,7 +10,7 @@
<ul mapa-sources>
{{range .Items}}<li><a href="{{.Href}}" mapa-source>{{if .Look}}{{pageIcon .Look ""}}{{end}}{{.Label}}</a>
{{$source := .Public}}{{range .Contexts}}<div mapa-context>{{.HTML}}
-{{if $target}}<form method="post" action="/p/{{$target}}/mentions" mapa-link-it><input type="hidden" name="source" value="{{$source}}"><input type="hidden" name="block" value="{{.Block}}"><button rst-btn type="submit">Link it</button></form>{{end}}
+{{if $target}}<form method="post" action="/p/{{$target}}/mentions" mapa-link-it><input type="hidden" name="grammar" value="{{grammar}}"><input type="hidden" name="source" value="{{$source}}"><input type="hidden" name="block" value="{{.Block}}"><button rst-btn type="submit">Link it</button></form>{{end}}
</div>{{end}}</li>
{{end}}</ul>
{{else}}<p mapa-meta>{{.Empty}}</p>{{end}}
diff --git a/internal/mapa/templates/share.html b/internal/mapa/templates/share.html
index 744366e..2d6bb34 100644
--- a/internal/mapa/templates/share.html
+++ b/internal/mapa/templates/share.html
@@ -1,7 +1,7 @@
{{define "content"}}{{$d := .Data}}
{{template "back-nav" dict "Href" $d.Page.Href "Label" $d.Page.Label}}
{{template "page-header" dict "Title" "Make team page" "Sub" "The blocks you choose become a new team page that everyone in the team can open. Your note keeps a link to it in their place, and stays yours."}}
-<form rst-form method="post" action="{{$d.Action}}">
+<form rst-form method="post" action="{{$d.Action}}"><input type="hidden" name="grammar" value="{{grammar}}">
<input type="hidden" name="revision" value="{{$d.Page.Revision}}">
{{template "field-text" dict "Name" "title" "Label" "Title of the new page" "Value" $d.Title "Error" $d.Error "Required" true}}
{{with $d.Taken}}<p mapa-meta><a href="{{.}}">Open the page with that title</a></p>{{end}}
diff --git a/internal/mapa/versions.go b/internal/mapa/versions.go
index 674763f..8b452a1 100644
--- a/internal/mapa/versions.go
+++ b/internal/mapa/versions.go
@@ -339,6 +339,10 @@ func (history *pageHistory) blocks(index int) ([]markup.Block, error) {
// editSummary is one line for an edit: "Added 2 blocks", "Removed a
// block", or "Edited" and the nearest heading above the first change.
func editSummary(dates *locale.Locale, from, to []markup.Block) string {
+ if said := layoutSummary(from, to); said != "" {
+ return said
+ }
+ from, to = withoutFences(from), withoutFences(to)
counts := map[string]int{}
var first *blockChange
for _, change := range diffBlocks(from, to) {
diff --git a/internal/mapa/versions_columns.go b/internal/mapa/versions_columns.go
new file mode 100644
index 0000000..87c557d
--- /dev/null
+++ b/internal/mapa/versions_columns.go
@@ -0,0 +1,45 @@
+package mapa
+
+import "amadan.net/oficina/mapa/internal/mapa/markup"
+
+// History's words for column layouts (columns and icons spec §1.9): a
+// layout added or removed, a column added or removed. Every other edit
+// is counted and named as before, over the blocks, never the fences.
+
+func layoutSummary(from, to []markup.Block) string {
+ layouts := count(to, markup.Columns) - count(from, markup.Columns)
+ columns := count(to, markup.Column) - count(from, markup.Column)
+ switch {
+ case layouts > 0:
+ return "Added columns"
+ case layouts < 0:
+ return "Removed columns"
+ case columns > 0:
+ return "Added a column"
+ case columns < 0:
+ return "Removed a column"
+ }
+ return ""
+}
+
+func count(blocks []markup.Block, kind string) int {
+ found := 0
+ for _, block := range blocks {
+ if block.Kind == kind {
+ found++
+ }
+ }
+ return found
+}
+
+// withoutFences is blocks less a layout's fence lines: what an edit's
+// summary counts and names.
+func withoutFences(blocks []markup.Block) []markup.Block {
+ out := make([]markup.Block, 0, len(blocks))
+ for _, block := range blocks {
+ if !markup.IsFence(block.Kind) {
+ out = append(out, block)
+ }
+ }
+ return out
+}
diff --git a/internal/mapatest/columns_test.go b/internal/mapatest/columns_test.go
new file mode 100644
index 0000000..01bb3c9
--- /dev/null
+++ b/internal/mapatest/columns_test.go
@@ -0,0 +1,107 @@
+package mapatest
+
+import (
+ "encoding/json"
+ "net/http"
+ "net/url"
+ "strings"
+ "testing"
+)
+
+// COL7's server half, COL8 and COL13 (columns and icons spec §1.9,
+// §1.10, §9): a layout drawn as columns with script off; History's
+// words for a layout; the block routes refusing fences, a cut layout,
+// and a post counted by another grammar.
+
+const twoColumns = ":::: columns\n\n::: column\nLeft.\n\n:::\n\n" +
+ "::: column\nRight.\n\n:::\n\n::::"
+
+func TestCOL7ALayoutIsDrawnAsColumns(t *testing.T) {
+ rig := newRig(t)
+ acme := rig.createPage(t, Ana, "Acme", "Top.\n\n"+twoColumns)
+ page := rig.page(t, Bo, acme)
+ if !strings.Contains(page, `<div mapa-columns="2"><div mapa-column>`+
+ `<p>Left.</p></div><div mapa-column><p>Right.</p></div></div>`) {
+ t.Fatal("the layout is not drawn as columns")
+ }
+ if !strings.Contains(rig.page(t, Bo, acme+"/edit"), "::: column") {
+ t.Fatal("Edit as Markdown does not show the fences")
+ }
+}
+
+func TestCOL8HistorySaysWhatHappenedToTheColumns(t *testing.T) {
+ rig := newRig(t)
+ acme := rig.createPage(t, Ana, "Acme", "Left.\n\nRight.")
+ steps := []struct{ body, said string }{
+ {twoColumns, "Added columns"},
+ {strings.TrimSuffix(twoColumns, "::::") + "::: column\nMore.\n\n" +
+ ":::\n\n::::", "Added a column"},
+ {"Left.\n\nRight.", "Removed columns"},
+ }
+ for _, step := range steps {
+ rig.post(t, Ana, acme, url.Values{"body": {step.body},
+ "revision": {revisionAs(t, rig, Ana, acme)}})
+ if history := rig.page(t, Ana, acme+"/history"); !strings.Contains(
+ history, step.said) {
+ t.Errorf("History does not say %q", step.said)
+ }
+ }
+}
+
+func TestCOL13FencesAreNoBlockToMarkOrLink(t *testing.T) {
+ rig := newRig(t)
+ acme := rig.createPage(t, Ana, "Acme", twoColumns)
+ before := rig.count(t, "revisions")
+ for _, block := range []string{"0", "1", "3"} {
+ rig.post(t, Bo, acme+"/blocks", url.Values{"block": {block}})
+ }
+ if rig.count(t, "revisions") != before {
+ t.Fatal("a fence line took a marker")
+ }
+ column := rig.createPage(t, Bo, "Column", "A column.")
+ rig.post(t, Bo, column+"/mentions", url.Values{
+ "source": {strings.TrimPrefix(acme, "/p/")}, "block": {"1"}})
+ if rig.count(t, "revisions") != before+1 {
+ t.Fatal("Link it linked a fence line")
+ }
+}
+
+func TestCOL13MakeTeamPageNeverCutsALayout(t *testing.T) {
+ rig := newRig(t)
+ created := rig.post(t, Ana, "/scratch", url.Values{"body": {twoColumns}})
+ note := created.Header().Get("Location")
+ revision := revisionAs(t, rig, Ana, note)
+ status, reply := rig.postJSON(Ana, note+"/share", url.Values{
+ "title": {"Half"}, "revision": {revision}, "block": {"0", "1", "2"}})
+ if status == http.StatusOK || !strings.Contains(reply["error"].(string),
+ "inside one column") {
+ t.Fatalf("a cut layout was shared: %d %v", status, reply)
+ }
+ status, _ = rig.postJSON(Ana, note+"/share", url.Values{
+ "title": {"Inside"}, "revision": {revision}, "block": {"2"}})
+ if status != http.StatusOK {
+ t.Fatalf("a block inside one column: %d", status)
+ }
+}
+
+func TestCOL13AnotherGrammarIsRefusedAndTheDraftKept(t *testing.T) {
+ rig := newRig(t)
+ acme := rig.createPage(t, Ana, "Acme", "One.\n\nTwo.")
+ for _, grammar := range []url.Values{{"grammar": {""}},
+ {"grammar": {"1"}}} {
+ for _, route := range []string{"/blocks", "/mentions", "/resolve"} {
+ form := url.Values{"block": {"0"}, "source": {"x"}}
+ for key, value := range grammar {
+ form[key] = value
+ }
+ status, reply := rig.postJSON(Bo, acme+route, form)
+ said, _ := reply["error"].(string)
+ if status != http.StatusConflict ||
+ !strings.Contains(said, "Reload the page") {
+ body, _ := json.Marshal(reply)
+ t.Errorf("%s with grammar %q: %d %s", route,
+ grammar.Get("grammar"), status, body)
+ }
+ }
+ }
+}
diff --git a/internal/mapatest/gate8_test.go b/internal/mapatest/gate8_test.go
index b18b293..ebcb9a8 100644
--- a/internal/mapatest/gate8_test.go
+++ b/internal/mapatest/gate8_test.go
@@ -81,6 +81,7 @@ func TestGate8EveryWriteLogsAnEvent(t *testing.T) {
func (rig *rig) send(who, method, target string,
form url.Values) *http.Response {
+ form = counted(target, form)
request, _ := http.NewRequest(method, target,
strings.NewReader(form.Encode()))
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
diff --git a/internal/mapatest/harness_test.go b/internal/mapatest/harness_test.go
index 2033746..c650c2d 100644
--- a/internal/mapatest/harness_test.go
+++ b/internal/mapatest/harness_test.go
@@ -10,6 +10,8 @@ import (
"net/http/httptest"
"net/url"
"path/filepath"
+ "regexp"
+ "strconv"
"strings"
"testing"
@@ -17,6 +19,7 @@ import (
"amadan.net/rastrillo/rastrillo/db"
"amadan.net/oficina/mapa/internal/mapa"
+ "amadan.net/oficina/mapa/internal/mapa/markup"
)
// The two people every gate needs: Ana writes private notes, Bo must
@@ -113,6 +116,7 @@ func (rig *rig) get(t *testing.T,
func (rig *rig) post(t *testing.T, who, target string,
form url.Values) *httptest.ResponseRecorder {
t.Helper()
+ form = counted(target, form)
request := httptest.NewRequest(http.MethodPost, target,
strings.NewReader(form.Encode()))
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
@@ -132,3 +136,22 @@ func (rig *rig) count(t *testing.T, table string) int64 {
}
return rows
}
+
+// countedRoute is a route that posts block or hunk indices (columns and
+// icons spec D17): its forms and the editor send the grammar.
+var countedRoute = regexp.MustCompile(`/(share|blocks|mentions|resolve)$`)
+
+// counted adds the grammar field the app's own forms carry, unless the
+// test names one itself (COL13 sends none, or an old one).
+func counted(target string, form url.Values) url.Values {
+ path, _, _ := strings.Cut(target, "?")
+ if !countedRoute.MatchString(path) || form.Has("grammar") {
+ return form
+ }
+ out := url.Values{}
+ for key, values := range form {
+ out[key] = values
+ }
+ out.Set("grammar", strconv.Itoa(markup.Grammar))
+ return out
+}
diff --git a/internal/mapatest/saving_test.go b/internal/mapatest/saving_test.go
index fd1f112..45d9bec 100644
--- a/internal/mapatest/saving_test.go
+++ b/internal/mapatest/saving_test.go
@@ -19,6 +19,7 @@ import (
// postJSON is a POST whose answer the script reads.
func (rig *rig) postJSON(who, target string,
form url.Values) (int, map[string]any) {
+ form = counted(target, form)
request := httptest.NewRequest(http.MethodPost, target,
strings.NewReader(form.Encode()))
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")