oficina / mapa Public

Clone
git clone https://amadan.net/oficina/mapa

Plain git — no account needed to clone.

Download

Download this file

1package mapa
2
3import "amadan.net/oficina/mapa/internal/mapa/markup"
4
5// History's words for column layouts (columns and icons spec §1.9): a
6// layout added or removed, a column added or removed. Every other edit
7// is counted and named as before, over the blocks, never the fences.
8
9func layoutSummary(from, to []markup.Block) string {
10 layouts := count(to, markup.Columns) - count(from, markup.Columns)
11 columns := count(to, markup.Column) - count(from, markup.Column)
12 switch {
13 case layouts > 0:
14 return "Added columns"
15 case layouts < 0:
16 return "Removed columns"
17 case columns > 0:
18 return "Added a column"
19 case columns < 0:
20 return "Removed a column"
21 }
22 return ""
23}
24
25func count(blocks []markup.Block, kind string) int {
26 found := 0
27 for _, block := range blocks {
28 if block.Kind == kind {
29 found++
30 }
31 }
32 return found
33}
34
35// withoutFences is blocks less a layout's fence lines: what an edit's
36// summary counts and names.
37func withoutFences(blocks []markup.Block) []markup.Block {
38 out := make([]markup.Block, 0, len(blocks))
39 for _, block := range blocks {
40 if !markup.IsFence(block.Kind) {
41 out = append(out, block)
42 }
43 }
44 return out
45}
46