Zettelstore

Check-in Differences
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Difference From trunk To v0.7.0

2022-09-25
12:40
Update to yuin/goldmark v1.5.1 ... (Leaf check-in: ce74eb3a8d user: stern tags: trunk)
2022-09-23
08:58
API: make GET /z an alias for GET /q. Redundant code and documentation is removed. ... (check-in: 7cde054317 user: stern tags: trunk)
2022-09-18
12:52
Increase version to 0.7.1-dev to begin release update development cycle ... (check-in: f005505248 user: stern tags: release-0.7)
2022-09-17
15:10
Increase version to 0.8.0-dev to begin next development cycle ... (check-in: 97bb0f0d93 user: t73fde tags: trunk)
12:28
Version 0.7.0 ... (check-in: f2b8d470c7 user: stern tags: trunk, release, v0.7.0)
11:54
Update to newest go/x/crypto, go/x/sys ... (check-in: 61528d5462 user: stern tags: trunk)

Changes to VERSION.

1
0.8.0-dev
|
1
0.7.0

Changes to ast/inline.go.

50
51
52
53
54
55
56












57
58
59
60
61
62
63
	Text string // The text itself.
}

func (*TextNode) inlineNode() { /* Just a marker */ }

// WalkChildren does nothing.
func (*TextNode) WalkChildren(Visitor) { /* No children*/ }













// --------------------------------------------------------------------------

// SpaceNode tracks inter-word space characters.
type SpaceNode struct {
	Lexeme string
}







>
>
>
>
>
>
>
>
>
>
>
>







50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
	Text string // The text itself.
}

func (*TextNode) inlineNode() { /* Just a marker */ }

// WalkChildren does nothing.
func (*TextNode) WalkChildren(Visitor) { /* No children*/ }

// --------------------------------------------------------------------------

// TagNode contains a tag.
type TagNode struct {
	Tag string // The text itself.
}

func (*TagNode) inlineNode() { /* Just a marker */ }

// WalkChildren does nothing.
func (*TagNode) WalkChildren(Visitor) { /* No children*/ }

// --------------------------------------------------------------------------

// SpaceNode tracks inter-word space characters.
type SpaceNode struct {
	Lexeme string
}

Changes to box/manager/collect.go.

19
20
21
22
23
24
25

26
27
28
29
30
31

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49



50
51
52
53
54
55
56
	"zettelstore.de/z/strfun"
)

type collectData struct {
	refs  id.Set
	words store.WordSet
	urls  store.WordSet

}

func (data *collectData) initialize() {
	data.refs = id.NewSet()
	data.words = store.NewWordSet()
	data.urls = store.NewWordSet()

}

func collectZettelIndexData(zn *ast.ZettelNode, data *collectData) {
	ast.Walk(data, &zn.Ast)
}

func collectInlineIndexData(is *ast.InlineSlice, data *collectData) {
	ast.Walk(data, is)
}

func (data *collectData) Visit(node ast.Node) ast.Visitor {
	switch n := node.(type) {
	case *ast.VerbatimNode:
		data.addText(string(n.Content))
	case *ast.TranscludeNode:
		data.addRef(n.Ref)
	case *ast.TextNode:
		data.addText(n.Text)



	case *ast.LinkNode:
		data.addRef(n.Ref)
	case *ast.EmbedRefNode:
		data.addRef(n.Ref)
	case *ast.CiteNode:
		data.addText(n.Key)
	case *ast.LiteralNode:







>






>


















>
>
>







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
	"zettelstore.de/z/strfun"
)

type collectData struct {
	refs  id.Set
	words store.WordSet
	urls  store.WordSet
	itags store.WordSet
}

func (data *collectData) initialize() {
	data.refs = id.NewSet()
	data.words = store.NewWordSet()
	data.urls = store.NewWordSet()
	data.itags = store.NewWordSet()
}

func collectZettelIndexData(zn *ast.ZettelNode, data *collectData) {
	ast.Walk(data, &zn.Ast)
}

func collectInlineIndexData(is *ast.InlineSlice, data *collectData) {
	ast.Walk(data, is)
}

func (data *collectData) Visit(node ast.Node) ast.Visitor {
	switch n := node.(type) {
	case *ast.VerbatimNode:
		data.addText(string(n.Content))
	case *ast.TranscludeNode:
		data.addRef(n.Ref)
	case *ast.TextNode:
		data.addText(n.Text)
	case *ast.TagNode:
		data.addText(n.Tag)
		data.itags.Add("#" + strings.ToLower(n.Tag))
	case *ast.LinkNode:
		data.addRef(n.Ref)
	case *ast.EmbedRefNode:
		data.addRef(n.Ref)
	case *ast.CiteNode:
		data.addText(n.Key)
	case *ast.LiteralNode:

Changes to box/manager/indexer.go.

204
205
206
207
208
209
210

211
212
213
214
215
216
217
			zi.AddBackRef(ref)
		} else {
			zi.AddDeadRef(ref)
		}
	}
	zi.SetWords(cData.words)
	zi.SetUrls(cData.urls)

}

func (mgr *Manager) idxUpdateValue(ctx context.Context, inverseKey, value string, zi *store.ZettelIndex) {
	zid, err := id.Parse(value)
	if err != nil {
		return
	}







>







204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
			zi.AddBackRef(ref)
		} else {
			zi.AddDeadRef(ref)
		}
	}
	zi.SetWords(cData.words)
	zi.SetUrls(cData.urls)
	zi.SetITags(cData.itags)
}

func (mgr *Manager) idxUpdateValue(ctx context.Context, inverseKey, value string, zi *store.ZettelIndex) {
	zid, err := id.Parse(value)
	if err != nil {
		return
	}

Changes to box/manager/memstore/memstore.go.

34
35
36
37
38
39
40

41
42
43
44
45
46
47
type zettelIndex struct {
	dead     id.Slice
	forward  id.Slice
	backward id.Slice
	meta     map[string]metaRefs
	words    []string
	urls     []string

}

func (zi *zettelIndex) isEmpty() bool {
	if len(zi.forward) > 0 || len(zi.backward) > 0 || len(zi.dead) > 0 || len(zi.words) > 0 {
		return false
	}
	return len(zi.meta) == 0







>







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
type zettelIndex struct {
	dead     id.Slice
	forward  id.Slice
	backward id.Slice
	meta     map[string]metaRefs
	words    []string
	urls     []string
	itags    string // Inline tags
}

func (zi *zettelIndex) isEmpty() bool {
	if len(zi.forward) > 0 || len(zi.backward) > 0 || len(zi.dead) > 0 || len(zi.words) > 0 {
		return false
	}
	return len(zi.meta) == 0
107
108
109
110
111
112
113












114
115
116
117
118
119
120
			updated = true
		}
	}
	if len(back) > 0 {
		m.Set(api.KeyBack, back.String())
		updated = true
	}












	return updated
}

// SearchEqual returns all zettel that contains the given exact word.
// The word must be normalized through Unicode NKFD, trimmed and not empty.
func (ms *memStore) SearchEqual(word string) id.Set {
	ms.mx.RLock()







>
>
>
>
>
>
>
>
>
>
>
>







108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
			updated = true
		}
	}
	if len(back) > 0 {
		m.Set(api.KeyBack, back.String())
		updated = true
	}
	if itags := zi.itags; itags != "" {
		m.Set(api.KeyContentTags, itags)
		if tags, ok2 := m.Get(api.KeyTags); ok2 {
			m.Set(api.KeyAllTags, tags+" "+itags)
		} else {
			m.Set(api.KeyAllTags, itags)
		}
		updated = true
	} else if tags, ok2 := m.Get(api.KeyTags); ok2 {
		m.Set(api.KeyAllTags, tags)
		updated = true
	}
	return updated
}

// SearchEqual returns all zettel that contains the given exact word.
// The word must be normalized through Unicode NKFD, trimmed and not empty.
func (ms *memStore) SearchEqual(word string) id.Set {
	ms.mx.RLock()
144
145
146
147
148
149
150




151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
func (ms *memStore) SearchPrefix(prefix string) id.Set {
	ms.mx.RLock()
	defer ms.mx.RUnlock()
	result := ms.selectWithPred(prefix, strings.HasPrefix)
	l := len(prefix)
	if l > 14 {
		return result




	}
	maxZid, err := id.Parse(prefix + "99999999999999"[:14-l])
	if err != nil {
		return result
	}
	var minZid id.Zid
	if l < 14 && prefix == "0000000000000"[:l] {
		minZid = id.Zid(1)
	} else {
		minZid, err = id.Parse(prefix + "00000000000000"[:14-l])
		if err != nil {
			return result
		}
	}
	for zid, zi := range ms.idx {
		if minZid <= zid && zid <= maxZid {
			addBackwardZids(result, zid, zi)
		}
	}
	return result
}







>
>
>
>





<
<
<
<
<
<
<
<
<







157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172









173
174
175
176
177
178
179
func (ms *memStore) SearchPrefix(prefix string) id.Set {
	ms.mx.RLock()
	defer ms.mx.RUnlock()
	result := ms.selectWithPred(prefix, strings.HasPrefix)
	l := len(prefix)
	if l > 14 {
		return result
	}
	minZid, err := id.Parse(prefix + "00000000000000"[:13-l] + "1")
	if err != nil {
		return result
	}
	maxZid, err := id.Parse(prefix + "99999999999999"[:14-l])
	if err != nil {
		return result
	}









	for zid, zi := range ms.idx {
		if minZid <= zid && zid <= maxZid {
			addBackwardZids(result, zid, zi)
		}
	}
	return result
}
279
280
281
282
283
284
285

286
287
288
289
290
291
292
	}

	ms.updateDeadReferences(zidx, zi)
	ms.updateForwardBackwardReferences(zidx, zi)
	ms.updateMetadataReferences(zidx, zi)
	zi.words = updateWordSet(zidx.Zid, ms.words, zi.words, zidx.GetWords())
	zi.urls = updateWordSet(zidx.Zid, ms.urls, zi.urls, zidx.GetUrls())


	// Check if zi must be inserted into ms.idx
	if !ziExist && !zi.isEmpty() {
		ms.idx[zidx.Zid] = zi
	}

	return toCheck







>







287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
	}

	ms.updateDeadReferences(zidx, zi)
	ms.updateForwardBackwardReferences(zidx, zi)
	ms.updateMetadataReferences(zidx, zi)
	zi.words = updateWordSet(zidx.Zid, ms.words, zi.words, zidx.GetWords())
	zi.urls = updateWordSet(zidx.Zid, ms.urls, zi.urls, zidx.GetUrls())
	zi.itags = setITags(zidx.GetITags())

	// Check if zi must be inserted into ms.idx
	if !ziExist && !zi.isEmpty() {
		ms.idx[zidx.Zid] = zi
	}

	return toCheck
371
372
373
374
375
376
377









378
379
380
381
382
383
384
			delete(srefs, word)
			continue
		}
		srefs[word] = refs2
	}
	return next.Words()
}










func (ms *memStore) getEntry(zid id.Zid) *zettelIndex {
	// Must only be called if ms.mx is write-locked!
	if zi, ok := ms.idx[zid]; ok {
		return zi
	}
	zi := &zettelIndex{}







>
>
>
>
>
>
>
>
>







380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
			delete(srefs, word)
			continue
		}
		srefs[word] = refs2
	}
	return next.Words()
}

func setITags(next store.WordSet) string {
	itags := next.Words()
	if len(itags) == 0 {
		return ""
	}
	sort.Strings(itags)
	return strings.Join(itags, " ")
}

func (ms *memStore) getEntry(zid id.Zid) *zettelIndex {
	// Must only be called if ms.mx is write-locked!
	if zi, ok := ms.idx[zid]; ok {
		return zi
	}
	zi := &zettelIndex{}

Changes to box/manager/store/zettel.go.

16
17
18
19
20
21
22

23
24
25
26
27
28
29
type ZettelIndex struct {
	Zid      id.Zid            // zid of the indexed zettel
	backrefs id.Set            // set of back references
	metarefs map[string]id.Set // references to inverse keys
	deadrefs id.Set            // set of dead references
	words    WordSet
	urls     WordSet

}

// NewZettelIndex creates a new zettel index.
func NewZettelIndex(zid id.Zid) *ZettelIndex {
	return &ZettelIndex{
		Zid:      zid,
		backrefs: id.NewSet(),







>







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
type ZettelIndex struct {
	Zid      id.Zid            // zid of the indexed zettel
	backrefs id.Set            // set of back references
	metarefs map[string]id.Set // references to inverse keys
	deadrefs id.Set            // set of dead references
	words    WordSet
	urls     WordSet
	itags    WordSet
}

// NewZettelIndex creates a new zettel index.
func NewZettelIndex(zid id.Zid) *ZettelIndex {
	return &ZettelIndex{
		Zid:      zid,
		backrefs: id.NewSet(),
55
56
57
58
59
60
61



62
63
64
65
66
67
68

// SetWords sets the words to the given value.
func (zi *ZettelIndex) SetWords(words WordSet) { zi.words = words }

// SetUrls sets the words to the given value.
func (zi *ZettelIndex) SetUrls(urls WordSet) { zi.urls = urls }




// GetDeadRefs returns all dead references as a sorted list.
func (zi *ZettelIndex) GetDeadRefs() id.Slice {
	return zi.deadrefs.Sorted()
}

// GetBackRefs returns all back references as a sorted list.
func (zi *ZettelIndex) GetBackRefs() id.Slice {







>
>
>







56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

// SetWords sets the words to the given value.
func (zi *ZettelIndex) SetWords(words WordSet) { zi.words = words }

// SetUrls sets the words to the given value.
func (zi *ZettelIndex) SetUrls(urls WordSet) { zi.urls = urls }

// SetITags sets the words to the given value.
func (zi *ZettelIndex) SetITags(itags WordSet) { zi.itags = itags }

// GetDeadRefs returns all dead references as a sorted list.
func (zi *ZettelIndex) GetDeadRefs() id.Slice {
	return zi.deadrefs.Sorted()
}

// GetBackRefs returns all back references as a sorted list.
func (zi *ZettelIndex) GetBackRefs() id.Slice {
82
83
84
85
86
87
88



}

// GetWords returns a reference to the set of words. It must not be modified.
func (zi *ZettelIndex) GetWords() WordSet { return zi.words }

// GetUrls returns a reference to the set of URLs. It must not be modified.
func (zi *ZettelIndex) GetUrls() WordSet { return zi.urls }










>
>
>
86
87
88
89
90
91
92
93
94
95
}

// GetWords returns a reference to the set of words. It must not be modified.
func (zi *ZettelIndex) GetWords() WordSet { return zi.words }

// GetUrls returns a reference to the set of URLs. It must not be modified.
func (zi *ZettelIndex) GetUrls() WordSet { return zi.urls }

// GetITags returns a reference to the set of internal tags. It must not be modified.
func (zi *ZettelIndex) GetITags() WordSet { return zi.itags }

Changes to cmd/cmd_run.go.

69
70
71
72
73
74
75

76
77
78
79
80
81
82
	ucGetAllMeta := usecase.NewGetAllMeta(protectedBoxManager)
	ucGetZettel := usecase.NewGetZettel(protectedBoxManager)
	ucParseZettel := usecase.NewParseZettel(rtConfig, ucGetZettel)
	ucListMeta := usecase.NewListMeta(protectedBoxManager)
	ucEvaluate := usecase.NewEvaluate(rtConfig, ucGetZettel, ucGetMeta, ucListMeta)
	ucListSyntax := usecase.NewListSyntax(protectedBoxManager)
	ucListRoles := usecase.NewListRoles(protectedBoxManager)

	ucZettelContext := usecase.NewZettelContext(protectedBoxManager, rtConfig)
	ucDelete := usecase.NewDeleteZettel(logUc, protectedBoxManager)
	ucUpdate := usecase.NewUpdateZettel(logUc, protectedBoxManager)
	ucRename := usecase.NewRenameZettel(logUc, protectedBoxManager)
	ucUnlinkedRefs := usecase.NewUnlinkedReferences(protectedBoxManager, rtConfig)
	ucRefresh := usecase.NewRefresh(logUc, protectedBoxManager)
	ucVersion := usecase.NewVersion(kernel.Main.GetConfig(kernel.CoreService, kernel.CoreVersion).(string))







>







69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
	ucGetAllMeta := usecase.NewGetAllMeta(protectedBoxManager)
	ucGetZettel := usecase.NewGetZettel(protectedBoxManager)
	ucParseZettel := usecase.NewParseZettel(rtConfig, ucGetZettel)
	ucListMeta := usecase.NewListMeta(protectedBoxManager)
	ucEvaluate := usecase.NewEvaluate(rtConfig, ucGetZettel, ucGetMeta, ucListMeta)
	ucListSyntax := usecase.NewListSyntax(protectedBoxManager)
	ucListRoles := usecase.NewListRoles(protectedBoxManager)
	ucListTags := usecase.NewListTags(protectedBoxManager)
	ucZettelContext := usecase.NewZettelContext(protectedBoxManager, rtConfig)
	ucDelete := usecase.NewDeleteZettel(logUc, protectedBoxManager)
	ucUpdate := usecase.NewUpdateZettel(logUc, protectedBoxManager)
	ucRename := usecase.NewRenameZettel(logUc, protectedBoxManager)
	ucUnlinkedRefs := usecase.NewUnlinkedReferences(protectedBoxManager, rtConfig)
	ucRefresh := usecase.NewRefresh(logUc, protectedBoxManager)
	ucVersion := usecase.NewVersion(kernel.Main.GetConfig(kernel.CoreService, kernel.CoreVersion).(string))
111
112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
		ucParseZettel, &ucEvaluate, ucGetMeta, ucGetAllMeta, ucUnlinkedRefs))
	webSrv.AddZettelRoute('k', server.MethodGet, wui.MakeZettelContextHandler(
		ucZettelContext, &ucEvaluate))

	// API
	webSrv.AddListRoute('a', server.MethodPost, a.MakePostLoginHandler(&ucAuthenticate))
	webSrv.AddListRoute('a', server.MethodPut, a.MakeRenewAuthHandler())
	webSrv.AddListRoute('j', server.MethodGet, a.MakeQueryHandler(ucListMeta))
	webSrv.AddZettelRoute('j', server.MethodGet, a.MakeGetZettelHandler(ucGetZettel))

	webSrv.AddZettelRoute('m', server.MethodGet, a.MakeGetMetaHandler(ucGetMeta))
	webSrv.AddZettelRoute('o', server.MethodGet, a.MakeGetOrderHandler(
		usecase.NewZettelOrder(protectedBoxManager, ucEvaluate)))
	webSrv.AddZettelRoute('p', server.MethodGet, a.MakeGetParsedZettelHandler(ucParseZettel))
	webSrv.AddListRoute('q', server.MethodGet, a.MakeQueryHandler(ucListMeta))
	webSrv.AddZettelRoute('u', server.MethodGet, a.MakeListUnlinkedMetaHandler(
		ucGetMeta, ucUnlinkedRefs, &ucEvaluate))







|

>







112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
		ucParseZettel, &ucEvaluate, ucGetMeta, ucGetAllMeta, ucUnlinkedRefs))
	webSrv.AddZettelRoute('k', server.MethodGet, wui.MakeZettelContextHandler(
		ucZettelContext, &ucEvaluate))

	// API
	webSrv.AddListRoute('a', server.MethodPost, a.MakePostLoginHandler(&ucAuthenticate))
	webSrv.AddListRoute('a', server.MethodPut, a.MakeRenewAuthHandler())
	webSrv.AddListRoute('j', server.MethodGet, a.MakeListMetaHandler(ucListMeta))
	webSrv.AddZettelRoute('j', server.MethodGet, a.MakeGetZettelHandler(ucGetZettel))
	webSrv.AddListRoute('m', server.MethodGet, a.MakeListMapMetaHandler(ucListRoles, ucListTags))
	webSrv.AddZettelRoute('m', server.MethodGet, a.MakeGetMetaHandler(ucGetMeta))
	webSrv.AddZettelRoute('o', server.MethodGet, a.MakeGetOrderHandler(
		usecase.NewZettelOrder(protectedBoxManager, ucEvaluate)))
	webSrv.AddZettelRoute('p', server.MethodGet, a.MakeGetParsedZettelHandler(ucParseZettel))
	webSrv.AddListRoute('q', server.MethodGet, a.MakeQueryHandler(ucListMeta))
	webSrv.AddZettelRoute('u', server.MethodGet, a.MakeListUnlinkedMetaHandler(
		ucGetMeta, ucUnlinkedRefs, &ucEvaluate))

Changes to docs/manual/00001006020000.zettel.

1
2
3
4
5
6
7
8
9
10
11
12
13


14
15
16
17
18
19
20
21
22
23
24
25


26
27
28
29
30
31
32
id: 00001006020000
title: Supported Metadata Keys
role: manual
tags: #manual #meta #reference #zettel #zettelstore
syntax: zmk
created: 20210126175322
modified: 20220917174634

Although you are free to define your own metadata, by using any key (according to the [[syntax|00001006010000]]), some keys have a special meaning that is enforced by Zettelstore.
See the [[computed list of supported metadata keys|00000000000090]] for details.

Most keys conform to a [[type|00001006030000]].



; [!author|''author'']
: A string value describing the author of a zettel.
  If given, it will be shown in the [[web user interface|00001014000000]] for the zettel.
; [!back|''back'']
: Is a property that contains the identifier of all zettel that reference the zettel of this metadata, that are not referenced by this zettel.
  Basically, it is the value of [[''backward''|#backward]], but without any zettel identifier that is contained in [[''forward''|#forward]].
; [!backward|''backward'']
: Is a property that contains the identifier of all zettel that reference the zettel of this metadata.
  References within invertible values are not included here, e.g. [[''precursor''|#precursor]].
; [!box-number|''box-number'']
: Is a computed value and contains the number of the box where the zettel was found.
  For all but the [[predefined zettel|00001005090000]], this number is equal to the number __X__ specified in startup configuration key [[''box-uri-__X__''|00001004010000#box-uri-x]].


; [!copyright|''copyright'']
: Defines a copyright string that will be encoded.
  If not given, the value ''default-copyright'' from the  [[configuration zettel|00001004020000#default-copyright]] will be used.
; [!created|''created'']
: Date and time when a zettel was created through Zettelstore.
  If you create a zettel with an editor software outside Zettelstore, you should set it manually to an appropriate value.







|






>
>












>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
id: 00001006020000
title: Supported Metadata Keys
role: manual
tags: #manual #meta #reference #zettel #zettelstore
syntax: zmk
created: 20210126175322
modified: 20220915181826

Although you are free to define your own metadata, by using any key (according to the [[syntax|00001006010000]]), some keys have a special meaning that is enforced by Zettelstore.
See the [[computed list of supported metadata keys|00000000000090]] for details.

Most keys conform to a [[type|00001006030000]].

; [!all-tags|''all-tags'']
: A property (a computed values that is not stored) that contains both the value of [[''tags''|#tags]] and the value of [[''content-tags''|#content-tags]].
; [!author|''author'']
: A string value describing the author of a zettel.
  If given, it will be shown in the [[web user interface|00001014000000]] for the zettel.
; [!back|''back'']
: Is a property that contains the identifier of all zettel that reference the zettel of this metadata, that are not referenced by this zettel.
  Basically, it is the value of [[''backward''|#backward]], but without any zettel identifier that is contained in [[''forward''|#forward]].
; [!backward|''backward'']
: Is a property that contains the identifier of all zettel that reference the zettel of this metadata.
  References within invertible values are not included here, e.g. [[''precursor''|#precursor]].
; [!box-number|''box-number'']
: Is a computed value and contains the number of the box where the zettel was found.
  For all but the [[predefined zettel|00001005090000]], this number is equal to the number __X__ specified in startup configuration key [[''box-uri-__X__''|00001004010000#box-uri-x]].
; [!content-tags|''content-tags'']
: A property that contains all [[inline tags|00001007040000#tag]] defined within the content.
; [!copyright|''copyright'']
: Defines a copyright string that will be encoded.
  If not given, the value ''default-copyright'' from the  [[configuration zettel|00001004020000#default-copyright]] will be used.
; [!created|''created'']
: Date and time when a zettel was created through Zettelstore.
  If you create a zettel with an editor software outside Zettelstore, you should set it manually to an appropriate value.

Changes to docs/manual/00001007031100.zettel.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
id: 00001007031100
title: Zettelmarkup: Transclusion
role: manual
tags: #manual #zettelmarkup #zettelstore
syntax: zmk
created: 20220131151022
modified: 20220922155031

A transclusion allows to include the content of other zettel into the current zettel.

The transclusion specification begins with three consecutive left curly bracket characters (""''{''"", U+007B) at the first position of a line and ends with three consecutive right curly bracket characters (""''}''"", U+007D).
The curly brackets delimit either a [[zettel identifier|00001006050000]] or a searched zettel list.
You can add some [[attributes|00001007050000]], although a transclusion does not support the default attribute.
Any other characters in this line will be ignored.

This leads to three variants of transclusions:
# Transclusion of the content of another zettel into the current zettel.
  This is done if you specify a zettel identifier, and is called __zettel transclusion__.
# Transclusion of the list of zettel references that satisfy a [[query expression|00001007700000]].
  This is called __query transclusion__.
# Transclusion of the content of an image, referenced by a [[hosted or based|00001007040310#link-specifications]] link / URL.

The first two variants are described on separate zettel:
* [[Zettel transclusion|00001007031110]]
* [[Query transclusion|00001007031140]]






|








|

|

|
<

|


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

21
22
23
24
id: 00001007031100
title: Zettelmarkup: Transclusion
role: manual
tags: #manual #zettelmarkup #zettelstore
syntax: zmk
created: 20220131151022
modified: 20220913135545

A transclusion allows to include the content of other zettel into the current zettel.

The transclusion specification begins with three consecutive left curly bracket characters (""''{''"", U+007B) at the first position of a line and ends with three consecutive right curly bracket characters (""''}''"", U+007D).
The curly brackets delimit either a [[zettel identifier|00001006050000]] or a searched zettel list.
You can add some [[attributes|00001007050000]], although a transclusion does not support the default attribute.
Any other characters in this line will be ignored.

This leads to two variants of transclusion:
# Transclusion of the content of another zettel into the current zettel.
  This is done if you specify a zettel identifier, and is called ""zettel transclusion"".
# Transclusion of the list of zettel references that satisfy a [[query expression|00001007700000]].
  This is called ""query transclusion"".


The variants are described on separate zettel:
* [[Zettel transclusion|00001007031110]]
* [[Query transclusion|00001007031140]]

Changes to docs/manual/00001007031140.zettel.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
id: 00001007031140
title: Zettelmarkup: Query Transclusion
role: manual
tags: #manual #search #zettelmarkup #zettelstore
syntax: zmk
created: 20220809132350
modified: 20220917174902

A query transclusion is specified by the following sequence, starting at the first position in a line: ''{{{query:query-expression}}}''.
The line must literally start with the sequence ''{{{query:''.
Everything after this prefix is interpreted as a [[query expression|00001007700000]].

When evaluated, the query expression is evaluated, often resulting in a list of [[links|00001007040310]] to zettel, matching the query expression.
The result replaces the query transclusion element.

For example, to include the list of all zettel with the [[tags|00001006020000#tags]] ""#search"", ordered by title specify the following query transclude element:
```zmk
{{{query:tags:#search ORDER title}}}
```
This will result in:
:::zs-example
{{{query:tags:#search ORDER title}}}
:::

For example, this allows to create a dynamic list of zettel inside a zettel, maybe to provide some introductory text followed by a list of child zettel.

The query will deliver only those zettel, which the current user is allowed to read.

In the above example, the action list is empty.






|








|

|



|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
id: 00001007031140
title: Zettelmarkup: Query Transclusion
role: manual
tags: #manual #search #zettelmarkup #zettelstore
syntax: zmk
created: 20220809132350
modified: 20220913145104

A query transclusion is specified by the following sequence, starting at the first position in a line: ''{{{query:query-expression}}}''.
The line must literally start with the sequence ''{{{query:''.
Everything after this prefix is interpreted as a [[query expression|00001007700000]].

When evaluated, the query expression is evaluated, often resulting in a list of [[links|00001007040310]] to zettel, matching the query expression.
The result replaces the query transclusion element.

For example, to include the list of all zettel with the [[all-tags|00001006020000#all-tags]] ""#search"", ordered by title specify the following query transclude element:
```zmk
{{{query:all-tags:#search ORDER title}}}
```
This will result in:
:::zs-example
{{{query:all-tags:#search ORDER title}}}
:::

For example, this allows to create a dynamic list of zettel inside a zettel, maybe to provide some introductory text followed by a list of child zettel.

The query will deliver only those zettel, which the current user is allowed to read.

In the above example, the action list is empty.
45
46
47
48
49
50
51
52
53
54
55
56
57
: Transform the zettel list into an [[RSS 2.0|https://www.rssboard.org/rss-specification]]-conformant document.
  The document is embedded into the referencing zettel.
; Any [[metadata key|00001006020000]] of type [[Word|00001006035500]], [[WordSet|00001006036000]], or [[TagSet|00001006034000]] (aggregates)
: Emit an aggregate of the given metadata key.
  The key can be given in any letter case.

```zmk
{{{query:tags:#search | tags}}}
```
This is a tag cloud of all tags that are used together with the tag #search:
:::zs-example
{{{query:tags:#search | tags}}}
:::







|

|

|

45
46
47
48
49
50
51
52
53
54
55
56
57
: Transform the zettel list into an [[RSS 2.0|https://www.rssboard.org/rss-specification]]-conformant document.
  The document is embedded into the referencing zettel.
; Any [[metadata key|00001006020000]] of type [[Word|00001006035500]], [[WordSet|00001006036000]], or [[TagSet|00001006034000]] (aggregates)
: Emit an aggregate of the given metadata key.
  The key can be given in any letter case.

```zmk
{{{query:all-tags:#search | all-tags}}}
```
This in a tag cloud of all tags that are used together with the tag #search:
:::zs-example
{{{query:all-tags:#search | all-tags}}}
:::

Changes to docs/manual/00001007040000.zettel.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
id: 00001007040000
title: Zettelmarkup: Inline-Structured Elements
role: manual
tags: #manual #zettelmarkup #zettelstore
syntax: zmk
created: 20210126175322
modified: 20220920143243

Most characters you type is concerned with inline-structured elements.
The content of a zettel contains is many cases just ordinary text, lightly formatted.
Inline-structured elements allow to format your text and add some helpful links or images.
Sometimes, you want to enter characters that have no representation on your keyboard.

; Text formatting






|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
id: 00001007040000
title: Zettelmarkup: Inline-Structured Elements
role: manual
tags: #manual #zettelmarkup #zettelstore
syntax: zmk
created: 20210126175322
modified: 20220913144717

Most characters you type is concerned with inline-structured elements.
The content of a zettel contains is many cases just ordinary text, lightly formatted.
Inline-structured elements allow to format your text and add some helpful links or images.
Sometimes, you want to enter characters that have no representation on your keyboard.

; Text formatting
36
37
38
39
40
41
42
























43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
==== Backslash
The backslash character (""''\\''"", U+005C) gives the next character another meaning.
* If a space character follows, it is converted in a non-breaking space (U+00A0).
* If a line ending follows the backslash character, the line break is converted from a __soft break__ into a __hard break__.
* Every other character is taken as itself, but without the interpretation of a Zettelmarkup element.
  For example, if you want to enter a ""'']''"" into a [[footnote text|00001007040330]], you should escape it with a backslash.

























==== Entities & more
Sometimes it is not easy to enter special characters.
If you know the Unicode code point of that character, or its name according to the [[HTML standard|https://html.spec.whatwg.org/multipage/named-characters.html]], you can enter it by number or by name.

Regardless which method you use, an entity always begins with an ampersand character (""''&''"", U+0026) and ends with a semicolon character (""'';''"", U+003B).
If you know the HTML name of the character you want to enter, put it between these two character.
Example: ``&amp;`` is rendered as ::&amp;::{=example}.

If you want to enter its numeric code point, a number sign character must follow the ampersand character, followed by digits to base 10.
Example: ``&#38;`` is rendered in HTML as ::&#38;::{=example}.

You also can enter its numeric code point as a hex number, if you put the letter ""x"" after the numeric sign character.
Example: ``&#x26;`` is rendered in HTML as ::&#x26;::{=example}.

According to the [[HTML Standard|https://html.spec.whatwg.org/multipage/syntax.html#character-references]], some numeric code points are not allowed.
These are all code point below the numeric value 32 (decimal) or 0x20 (hex) and all code points for [[noncharacter|https://infra.spec.whatwg.org/#noncharacter]] values.

Since some Unicode character are used quite often, a special notation is introduced for them:

* Two consecutive hyphen-minus characters result in an __en-dash__ character.
  It is typically used in numeric ranges.
  ``pages 4--7`` will be rendered in HTML as: ::pages 4--7::{=example}.
  Alternative specifications are: ``&ndash;``, ``&x8211``, and ``&#x2013``.







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>














<
<
<






36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80



81
82
83
84
85
86
==== Backslash
The backslash character (""''\\''"", U+005C) gives the next character another meaning.
* If a space character follows, it is converted in a non-breaking space (U+00A0).
* If a line ending follows the backslash character, the line break is converted from a __soft break__ into a __hard break__.
* Every other character is taken as itself, but without the interpretation of a Zettelmarkup element.
  For example, if you want to enter a ""'']''"" into a [[footnote text|00001007040330]], you should escape it with a backslash.

==== Tag
Any text that begins with a number sign character (""''#''"", U+0023), followed by a non-empty sequence of Unicode letters, Unicode digits, the hyphen-minus character (""''-''"", U+002D), or the low line character (""''_''"", U+005F) is interpreted as an __inline tag__.
They are be considered equivalent to tags in metadata.

**This element is deprecated in version 0.7 and will be removed in version 0.8!**

The use of inline tags is problematic, because:
* The number sign is often used as, well, a number sign, esp. in the English language.
  This introduces unintended tags.
* An inline tag is rendered in HTML as a link.
  However, an inline tag may be the contained in the text part of a [[link element|00001007040310]].
  This will produce a HTML link within a HTML link.
* Similar, an inline tag may be part of the title of a zettel.
  When a zettel list is rendered in HTML, this also produces a HTML link for each zettel, which contains the inline tag HTML link.
* The naming of metadata, [[''tags''|00001006020000#tags]] (names the tags within the metadata section of a zettel), [[''content-tags''|00001006020000#content-tags]] (all inline tags), and [[''all-tags''|00001006020000#all-tags]], is confusing for some users.
  For example, if you follow the link of a tag, it is converted into a [[query|00001007700000]] for the key ''all-tags''.
  A search for ''tags'' will most likely produce different results.

To find all zettel with inline tags, please use the query [[::query:content-tags?::|query:content-tags?]].
There are two, non-exclusive options for migration:
# Move inline tags into the metadata section of a zettel, under the key ''tags''.
  This will allow you to find the zettel via a search for tags in the future.
# Replace the inline tag with a link to a search for that tag: ``#TAG`` could be replace with ``[[#TAG|query:tags:TAG]]``, where ''TAG'' is the placeholder for the actual tag.

==== Entities & more
Sometimes it is not easy to enter special characters.
If you know the Unicode code point of that character, or its name according to the [[HTML standard|https://html.spec.whatwg.org/multipage/named-characters.html]], you can enter it by number or by name.

Regardless which method you use, an entity always begins with an ampersand character (""''&''"", U+0026) and ends with a semicolon character (""'';''"", U+003B).
If you know the HTML name of the character you want to enter, put it between these two character.
Example: ``&amp;`` is rendered as ::&amp;::{=example}.

If you want to enter its numeric code point, a number sign character must follow the ampersand character, followed by digits to base 10.
Example: ``&#38;`` is rendered in HTML as ::&#38;::{=example}.

You also can enter its numeric code point as a hex number, if you put the letter ""x"" after the numeric sign character.
Example: ``&#x26;`` is rendered in HTML as ::&#x26;::{=example}.




Since some Unicode character are used quite often, a special notation is introduced for them:

* Two consecutive hyphen-minus characters result in an __en-dash__ character.
  It is typically used in numeric ranges.
  ``pages 4--7`` will be rendered in HTML as: ::pages 4--7::{=example}.
  Alternative specifications are: ``&ndash;``, ``&x8211``, and ``&#x2013``.

Changes to docs/manual/00001007040310.zettel.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
id: 00001007040310
title: Zettelmarkup: Links
role: manual
tags: #manual #zettelmarkup #zettelstore
syntax: zmk
created: 20210810155955
modified: 20220922154843

There are two kinds of links, regardless of links to (internal) other zettel or to (external) material.
Both kinds begin with two consecutive left square bracket characters (""''[''"", U+005B) and ends with two consecutive right square bracket characters (""'']''"", U+005D).

The first form provides some text plus the link specification, delimited by a vertical bar character (""''|''"", U+007C): ``[[text|linkspecification]]``.
The text is a sequence of [[inline elements|00001007040000]].
However, it should not contain links itself.






|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
id: 00001007040310
title: Zettelmarkup: Links
role: manual
tags: #manual #zettelmarkup #zettelstore
syntax: zmk
created: 20210810155955
modified: 20220913144754

There are two kinds of links, regardless of links to (internal) other zettel or to (external) material.
Both kinds begin with two consecutive left square bracket characters (""''[''"", U+005B) and ends with two consecutive right square bracket characters (""'']''"", U+005D).

The first form provides some text plus the link specification, delimited by a vertical bar character (""''|''"", U+007C): ``[[text|linkspecification]]``.
The text is a sequence of [[inline elements|00001007040000]].
However, it should not contain links itself.
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
The resulting reference is called ""zettel reference"".

If the link specification begins with the string ''query:'', the text following this string will be interpreted as a [[query expression|00001007700000]].
The resulting reference is called ""query reference"".
When this type of references is rendered, it will typically reference a list of all zettel that fulfills the query expression.

A link specification starting with one slash character (""''/''"", U+002F), or one or two full stop characters (""''.''"", U+002E) followed by a slash character,
will be interpreted as a local reference, called __hosted reference__.
Such references will be interpreted relative to the web server hosting the Zettelstore.

If a link specification begins with two slash characters (called __based reference__), it will be interpreted relative to the value of [[''url-prefix''|00001004010000#url-prefix]].

To specify some material outside the Zettelstore, just use an normal Uniform Resource Identifier (URI) as defined by [[RFC\ 3986|https://tools.ietf.org/html/rfc3986]].

=== Other topics
If the link references another zettel, and this zettel is not readable for the current user, because of a missing access rights, then only the associated text is presented.







|


|





22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
The resulting reference is called ""zettel reference"".

If the link specification begins with the string ''query:'', the text following this string will be interpreted as a [[query expression|00001007700000]].
The resulting reference is called ""query reference"".
When this type of references is rendered, it will typically reference a list of all zettel that fulfills the query expression.

A link specification starting with one slash character (""''/''"", U+002F), or one or two full stop characters (""''.''"", U+002E) followed by a slash character,
will be interpreted as a local reference, called ""hosted reference"".
Such references will be interpreted relative to the web server hosting the Zettelstore.

If a link specification begins with two slash characters, it will be interpreted relative to the value of [[''url-prefix''|00001004010000#url-prefix]].

To specify some material outside the Zettelstore, just use an normal Uniform Resource Identifier (URI) as defined by [[RFC\ 3986|https://tools.ietf.org/html/rfc3986]].

=== Other topics
If the link references another zettel, and this zettel is not readable for the current user, because of a missing access rights, then only the associated text is presented.

Changes to docs/manual/00001007040324.zettel.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
id: 00001007040324
title: Zettelmarkup: Inline-mode Transclusion
role: manual
tags: #manual #zettelmarkup #zettelstore
syntax: zmk
created: 20210811154251
modified: 20220922160507

Inline-mode transclusion applies to all zettel that are parsed in a non-trivial way, e.g. as structured textual content.
For example, textual content is assumed if the [[syntax|00001006020000#syntax]] of a zettel is ""zmk"" ([[Zettelmarkup|00001007000000]]), or ""markdown"" / ""md"" ([[Markdown|00001008010000]]).

Since this type of transclusion is at the level of [[inline-structured elements|00001007040000]], the transclude specification must be replaced with some inline-structured elements.

First, the referenced zettel is read.
If it contains other transclusions, these will be expanded, recursively.
When an endless recursion is detected, expansion does not take place.
Instead an error message replaces the transclude specification.

The result of this (indirect) transclusion is searched for inline-structured elements.

* If only an [[zettel identifier|00001006050000]] was specified, the first top-level [[paragraph|00001007030000#paragraphs]] is used.
  Since a paragraph is basically a sequence of inline-structured elements, these elements will replace the transclude specification.

  Example: ``{{00010000000000}}`` (see [[00010000000000]]) is rendered as ::{{00010000000000}}::{=zs-example}.

* If a fragment identifier was additionally specified, the element with the given fragment is searched:
** If it specifies a [[heading|00001007030300]], the next top-level paragraph is used.

   Example: ``{{00010000000000#reporting-errors}}`` is rendered as ::{{00010000000000#reporting-errors}}::{=zs-example}.

** In case the fragment names a [[mark|00001007040350]], the inline-structured elements after the mark are used.
   Initial spaces and line breaks are ignored in this case.

   Example: ``{{00001007040322#spin}}`` is rendered as ::{{00001007040322#spin}}::{=zs-example}.

** Just specifying the fragment identifier will reference something in the current page.
   This is not allowed, to prevent a possible endless recursion.

* If the reference is a [[hosted or based|00001007040310#link-specifications]] link / URL to an image, that image will be rendered.

  Example: ``{{/z/00000000040001}}`` is rendered as ::{{/z/00000000040001}}::{=zs-example}

If no inline-structured elements are found, the transclude specification is replaced by an error message.

To avoid an exploding ""transclusion bomb"", a form of a [[billion laughs attack|https://en.wikipedia.org/wiki/Billion_laughs_attack]] (also known as ""XML bomb""), the total number of transclusions / expansions is limited.
The limit can be controlled by setting the value [[''max-transclusions''|00001004020000#max-transclusions]] of the runtime configuration zettel.

=== See also
[[Full transclusion|00001007031100]] does not work inside some text, but is used for [[block-structured elements|00001007030000]].





<
|
















|




|




|




<
<
<
<







1
2
3
4
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37




38
39
40
41
42
43
44
id: 00001007040324
title: Zettelmarkup: Inline-mode Transclusion
role: manual
tags: #manual #zettelmarkup #zettelstore
syntax: zmk

modified: 20220311110814

Inline-mode transclusion applies to all zettel that are parsed in a non-trivial way, e.g. as structured textual content.
For example, textual content is assumed if the [[syntax|00001006020000#syntax]] of a zettel is ""zmk"" ([[Zettelmarkup|00001007000000]]), or ""markdown"" / ""md"" ([[Markdown|00001008010000]]).

Since this type of transclusion is at the level of [[inline-structured elements|00001007040000]], the transclude specification must be replaced with some inline-structured elements.

First, the referenced zettel is read.
If it contains other transclusions, these will be expanded, recursively.
When an endless recursion is detected, expansion does not take place.
Instead an error message replaces the transclude specification.

The result of this (indirect) transclusion is searched for inline-structured elements.

* If only an [[zettel identifier|00001006050000]] was specified, the first top-level [[paragraph|00001007030000#paragraphs]] is used.
  Since a paragraph is basically a sequence of inline-structured elements, these elements will replace the transclude specification.

  Example: ``{{00010000000000}}`` (see [[00010000000000]]) is rendered as ::{{00010000000000}}::{=example}.

* If a fragment identifier was additionally specified, the element with the given fragment is searched:
** If it specifies a [[heading|00001007030300]], the next top-level paragraph is used.

   Example: ``{{00010000000000#reporting-errors}}`` is rendered as ::{{00010000000000#reporting-errors}}::{=example}.

** In case the fragment names a [[mark|00001007040350]], the inline-structured elements after the mark are used.
   Initial spaces and line breaks are ignored in this case.

   Example: ``{{00001007040322#spin}}`` is rendered as ::{{00001007040322#spin}}::{=example}.

** Just specifying the fragment identifier will reference something in the current page.
   This is not allowed, to prevent a possible endless recursion.





If no inline-structured elements are found, the transclude specification is replaced by an error message.

To avoid an exploding ""transclusion bomb"", a form of a [[billion laughs attack|https://en.wikipedia.org/wiki/Billion_laughs_attack]] (also known as ""XML bomb""), the total number of transclusions / expansions is limited.
The limit can be controlled by setting the value [[''max-transclusions''|00001004020000#max-transclusions]] of the runtime configuration zettel.

=== See also
[[Full transclusion|00001007031100]] does not work inside some text, but is used for [[block-structured elements|00001007030000]].

Changes to docs/manual/00001007790000.zettel.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

16

id: 00001007790000
title: Useful query expressions
role: manual
tags: #example #manual #search #zettelstore
syntax: zmk
created: 20220810144539
modified: 20220917174956

|= Query Expression |= Meaning
| [[query:role:configuration]] | Zettel that contains some configuration data for the Zettelstore
| [[query:ORDER REVERSE created LIMIT 40]] | 40 recently created zettel
| [[query:ORDER REVERSE published LIMIT 40]] | 40 recently updated zettel
| [[query:RANDOM LIMIT 40]] | 40 random zettel
| [[query:dead?]] | Zettel with invalid / dead links
| [[query:backward!? precursor!?]] | Zettel that are not referenced by other zettel

| [[query:tags!?]] | Zettel without tags







|








>
|
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
id: 00001007790000
title: Useful query expressions
role: manual
tags: #example #manual #search #zettelstore
syntax: zmk
created: 20220810144539
modified: 20220913144959

|= Query Expression |= Meaning
| [[query:role:configuration]] | Zettel that contains some configuration data for the Zettelstore
| [[query:ORDER REVERSE created LIMIT 40]] | 40 recently created zettel
| [[query:ORDER REVERSE published LIMIT 40]] | 40 recently updated zettel
| [[query:RANDOM LIMIT 40]] | 40 random zettel
| [[query:dead?]] | Zettel with invalid / dead links
| [[query:backward!? precursor!?]] | Zettel that are not referenced by other zettel
| [[query:all-tags!?]] | Zettel without any tags
| [[query:tags!?]] | Zettel without tags that are defined within metadata
| [[query:content-tags?]] | Zettel with tags within content

Changes to docs/manual/00001010070200.zettel.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
id: 00001010070200
title: Visibility rules for zettel
role: manual
tags: #authorization #configuration #manual #security #zettelstore
syntax: zmk
created: 20210126175322
modified: 20220923104643

For every zettel you can specify under which condition the zettel is visible to others.
This is controlled with the metadata key [[''visibility''|00001006020000#visibility]].
The following values are supported:

; [!public|""public""]
: The zettel is visible to everybody, even if the user is not authenticated.






|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
id: 00001010070200
title: Visibility rules for zettel
role: manual
tags: #authorization #configuration #manual #security #zettelstore
syntax: zmk
created: 20210126175322
modified: 20220913144845

For every zettel you can specify under which condition the zettel is visible to others.
This is controlled with the metadata key [[''visibility''|00001006020000#visibility]].
The following values are supported:

; [!public|""public""]
: The zettel is visible to everybody, even if the user is not authenticated.
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Please note: if [[authentication is not enabled|00001010040100]], every user has the same rights as the owner of a Zettelstore.
This is also true, if the Zettelstore runs additionally in [[read-only mode|00001004010000#read-only-mode]].
In this case, the [[runtime configuration zettel|00001004020000]] is shown (its visibility is ""owner"").
The [[startup configuration|00001004010000]] is not shown, because the associated computed zettel with identifier ''00000000000096'' is stored with the visibility ""expert"".
If you want to show such a zettel, you must set ''expert-mode'' to true.

=== Examples
By using a [[query expression|00001007700000]], you can easily create a zettel list based on the ''visibility'' metadata key:

| public  | [[query:visibility:public]]
| login   | [[query:visibility:login]]
| creator | [[query:visibility:creator]]
| owner   | [[query:visibility:owner]]
| expert  | [[query:visibility:expert]][^Only if [[''expert-mode''|00001004020000#expert-mode]] is enabled, this list will show some zettel.]







|






37
38
39
40
41
42
43
44
45
46
47
48
49
50
Please note: if [[authentication is not enabled|00001010040100]], every user has the same rights as the owner of a Zettelstore.
This is also true, if the Zettelstore runs additionally in [[read-only mode|00001004010000#read-only-mode]].
In this case, the [[runtime configuration zettel|00001004020000]] is shown (its visibility is ""owner"").
The [[startup configuration|00001004010000]] is not shown, because the associated computed zettel with identifier ''00000000000096'' is stored with the visibility ""expert"".
If you want to show such a zettel, you must set ''expert-mode'' to true.

=== Examples
Similar to the [[API|00001012051840]], you can easily create a zettel list based on the ''visibility'' metadata key:

| public  | [[query:visibility:public]]
| login   | [[query:visibility:login]]
| creator | [[query:visibility:creator]]
| owner   | [[query:visibility:owner]]
| expert  | [[query:visibility:expert]][^Only if [[''expert-mode''|00001004020000#expert-mode]] is enabled, this list will show some zettel.]

Changes to docs/manual/00001012000000.zettel.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24



25
26
27
28
29
30
31
32
33
id: 00001012000000
title: API
role: manual
tags: #api #manual #zettelstore
syntax: zmk
created: 20210126175322
modified: 20220923105117

The API (short for ""**A**pplication **P**rogramming **I**nterface"") is the primary way to communicate with a running Zettelstore.
Most integration with other systems and services is done through the API.
The [[web user interface|00001014000000]] is just an alternative, secondary way of interacting with a Zettelstore.

=== Background
The API is HTTP-based and uses plain text and JSON as its main encoding format for exchanging messages between a Zettelstore and its client software.

There is an [[overview zettel|00001012920000]] that shows the structure of the endpoints used by the API and gives an indication about its use.

=== Authentication
If [[authentication is enabled|00001010040100]], most API calls must include an [[access token|00001010040700]] that proves the identity of the caller.
* [[Authenticate an user|00001012050200]] to obtain an access token
* [[Renew an access token|00001012050400]] without costly re-authentication
* [[Provide an access token|00001012050600]] when doing an API call

=== Zettel lists



* [[Query the list of all zettel|00001012051400]]
* [[List plain text titles of all zettel|00001012051200]]

=== Working with zettel
* [[Create a new zettel|00001012053200]]
* [[Retrieve metadata and content of an existing zettel|00001012053300]]
* [[Retrieve metadata of an existing zettel|00001012053400]]
* [[Retrieve evaluated metadata and content of an existing zettel in various encodings|00001012053500]]
* [[Retrieve parsed metadata and content of an existing zettel in various encodings|00001012053600]]






|

















>
>
>

<







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
id: 00001012000000
title: API
role: manual
tags: #api #manual #zettelstore
syntax: zmk
created: 20210126175322
modified: 20220913141632

The API (short for ""**A**pplication **P**rogramming **I**nterface"") is the primary way to communicate with a running Zettelstore.
Most integration with other systems and services is done through the API.
The [[web user interface|00001014000000]] is just an alternative, secondary way of interacting with a Zettelstore.

=== Background
The API is HTTP-based and uses plain text and JSON as its main encoding format for exchanging messages between a Zettelstore and its client software.

There is an [[overview zettel|00001012920000]] that shows the structure of the endpoints used by the API and gives an indication about its use.

=== Authentication
If [[authentication is enabled|00001010040100]], most API calls must include an [[access token|00001010040700]] that proves the identity of the caller.
* [[Authenticate an user|00001012050200]] to obtain an access token
* [[Renew an access token|00001012050400]] without costly re-authentication
* [[Provide an access token|00001012050600]] when doing an API call

=== Zettel lists
* [[List metadata of all zettel|00001012051200]]
** [[Query expressions|00001012051840]] (includes content search)
* [[Map metadata values to lists of zettel identifier|00001012052400]]
* [[Query the list of all zettel|00001012051400]]


=== Working with zettel
* [[Create a new zettel|00001012053200]]
* [[Retrieve metadata and content of an existing zettel|00001012053300]]
* [[Retrieve metadata of an existing zettel|00001012053400]]
* [[Retrieve evaluated metadata and content of an existing zettel in various encodings|00001012053500]]
* [[Retrieve parsed metadata and content of an existing zettel in various encodings|00001012053600]]

Changes to docs/manual/00001012051200.zettel.

1
2
3
4
5
6
7
8
9

10













































































11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
id: 00001012051200
title: API: List plain text titles of all or some zettel
role: manual
tags: #api #manual #zettelstore
syntax: zmk
created: 20210126175322
modified: 20220923105412

To list the plain text titles of all zettel just send a HTTP GET request to the [[endpoint|00001012920000]] ''/z''[^If [[authentication is enabled|00001010040100]], you must include the a valid [[access token|00001012050200]] in the ''Authorization'' header].















































































A plain text document is returned, with one line per zettel.
Each line contains in the first 14 characters the [[zettel identifier|00001006050000]].
Separated by a space character, the title of the zettel follows:

```sh
# curl http://127.0.0.1:23123/z
00001012051200 API: Renew an access token
00001012050600 API: Provide an access token
00001012050400 API: Renew an access token
00001012050200 API: Authenticate a client
00001012000000 API
```

The query parameter ""''q''"" allows you to specify [[query expressions|00001007700000]] for a full-text search of all zettel content and/or restricting the search according to specific metadata, similar to endpoint ''/q'' to [[query zettel|00001012051400]].

You are allowed to specify this query parameter more than once.

This parameter loosely resembles the search form of the [[web user interface|00001014000000]].

For example, if you want to retrieve all zettel that contain the string ""API"" in its title, your request will be:
```sh
# curl 'http://127.0.0.1:23123/z?q=title%3AAPI'
00001012921000 API: JSON structure of an access token
00001012920500 Formats available by the API
00001012920000 Endpoints used by the API
...
```

An implicit precondition is that the zettel must contain the given metadata key.
For a metadata key like [[''title''|00001006020000#title]], which has a default value, this precondition should always be true.
But the situation is different for a key like [[''url''|00001006020000#url]].
Both ``curl 'http://localhost:23123/z?q=url%3A'`` and ``curl 'http://localhost:23123/z?q=url%3A!'`` may result in an empty list.

Alternatively, you also can use the [[endpoint|00001012920000]] ''/z'' for a simpler result format.
The first example translates to:
```sh
# curl 'http://127.0.0.1:23123/z?q=title%3AAPI'
00001012921000 API: JSON structure of an access token
00001012920500 Formats available by the API
00001012920000 Endpoints used by the API
...
```

=== Other output formats
If you want to get the list of metadata of all or some zettel in JSON format, use endpoint ''/q'' to [[query the list of zettel|00001012051400]].

=== HTTP Status codes
; ''200''
: Retrieval was successful, the body contains an [[appropriate JSON object|00001012921000]].
; ''400''
: Request was not valid. 
  There are several reasons for this.
  Maybe the access bearer token was not valid.

|




|

|
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|












<
|
<
|
<
|
<
<
<
<
<
<
<
<
|
<
<
<
<

<
<
<
<
<
<
<
<
<
|
<
<








1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

102

103

104








105




106









107


108
109
110
111
112
113
114
115
id: 00001012051200
title: API: List metadata of all zettel
role: manual
tags: #api #manual #zettelstore
syntax: zmk
created: 20210126175322
modified: 20220913151852

To list the metadata of all zettel just send a HTTP GET request to the [[endpoint|00001012920000]] ''/j''[^If [[authentication is enabled|00001010040100]], you must include the a valid [[access token|00001012050200]] in the ''Authorization'' header].
If successful, the output is a JSON object:

```sh
# curl http://127.0.0.1:23123/j
{"query":"","list":[{"id":"00001012051200","meta":{"title":"API: Renew an access token","tags":"#api #manual #zettelstore","syntax":"zmk","role":"manual"},"rights":62},{"id":"00001012050600","meta":{"title":"API: Provide an access token","tags":"#api #manual #zettelstore","syntax":"zmk","role":"manual"},"rights":62},{"id":"00001012050400","meta":{"title":"API: Renew an access token","tags":"#api #manual #zettelstore","syntax":"zmk","role":"manual"},"rights":62},{"id":"00001012050200","meta":{"title":"API: Authenticate a client","tags":"#api #manual #zettelstore","syntax":"zmk","role":"manual"},"rights":62},{"id":"00001012000000","meta":{"title":"API","tags":"#api #manual #zettelstore","syntax":"zmk","role":"manual"},"rights":62}]}
```

The JSON object contains a key ''"list"'' where its value is a list of zettel JSON objects.
These zettel JSON objects themselves contains the keys ''"id"'' (value is a string containing the [[zettel identifier|00001006050000]]), ''"meta"'' (value as a JSON object), and ''"rights"'' (encodes the [[access rights|00001012921200]] for the given zettel).
The value of key ''"meta"'' effectively contains all metadata of the identified zettel, where metadata keys are encoded as JSON object keys and metadata values encoded as JSON strings.

Additionally, the JSON object contains the keys ''"query"'' and ''"human"'' with a string value.
Both will contain a textual description of the underlying query if you select only some zettel with a [[query expression|00001012051840]].
Without a selection, the values are the empty string.
''"query"'' returns the normalized query expression itself, while ''"human"'' is the normalized query expression to be read by humans.

If you reformat the JSON output from the ''GET /j'' call, you'll see its structure better:

```json
{
  "query": "",
  "human": "",
  "list": [
    {
      "id": "00001012051200",
      "meta": {
        "title": "API: List for all zettel some data",
        "tags": "#api #manual #zettelstore",
        "syntax": "zmk",
        "role": "manual"
      },
      "rights":62
    },
    {
      "id": "00001012050600",
      "meta": {
        "title": "API: Provide an access token",
        "tags": "#api #manual #zettelstore",
        "syntax": "zmk",
        "role": "manual"
      },
      "rights":62
    },
    {
      "id": "00001012050400",
      "meta": {
        "title": "API: Renew an access token",
        "tags": "#api #manual #zettelstore",
        "syntax": "zmk",
        "role": "manual"
      },
      "rights":62
    },
    {
      "id": "00001012050200",
      "meta": {
        "title": "API: Authenticate a client",
        "tags": "#api #manual #zettelstore",
        "syntax": "zmk",
        "role": "manual"
      },
      "rights":62
    },
    {
      "id": "00001012000000",
      "meta": {
        "title": "API",
        "tags": "#api #manual #zettelstore",
        "syntax": "zmk",
        "role": "manual"
      },
      "rights":62
    }
  ]
}
```
In this special case, the metadata of each zettel just contains the four default keys ''title'', ''tags'', ''syntax'', and ''role''.

[!plain]Alternatively, you can retrieve the list of zettel in a simple, plain format using the [[endpoint|00001012920000]] ''/z''.
In this case, a plain text document is returned, with one line per zettel.
Each line contains in the first 14 characters the [[zettel identifier|00001006050000]].
Separated by a space character, the title of the zettel follows:

```sh
# curl http://127.0.0.1:23123/z
00001012051200 API: Renew an access token
00001012050600 API: Provide an access token
00001012050400 API: Renew an access token
00001012050200 API: Authenticate a client
00001012000000 API
```


=== Note

This request will always return a list of metadata, provided the request was syntactically correct.

There will never be a HTTP status code 403 (Forbidden), even if [[authentication was enabled|00001010040100]] and you did not provide a valid access token.








In this case, the resulting list might be quite short (some zettel will have [[public visibility|00001010070200]]) or the list might be empty.














With this call, you cannot differentiate between an empty result list (e.g because your [[content search|00001012051840]] did not found a zettel with the specified term) and an empty list because of missing authorization (e.g. an invalid access token).



=== HTTP Status codes
; ''200''
: Retrieval was successful, the body contains an [[appropriate JSON object|00001012921000]].
; ''400''
: Request was not valid. 
  There are several reasons for this.
  Maybe the access bearer token was not valid.

Changes to docs/manual/00001012051400.zettel.

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
id: 00001012051400
title: API: Query the list of all zettel
role: manual
tags: #api #manual #zettelstore
syntax: zmk
created: 20220912111111
modified: 20220923105405

The [[endpoint|00001012920000]] ''/q'' allows to query the list of all zettel[^If [[authentication is enabled|00001010040100]], you must include the a valid [[access token|00001012050200]] in the ''Authorization'' header].

A [[query|00001007700000]] is an optional [[search expression|00001007700000#search-expression]], together with an optional [[list of actions|00001007700000#action-list]] (described below).
An empty search expression will select all zettel.
An empty list of action, or no valid action, returns the list of all selected zettel metadata.


Search expression and action list are separated by a vertical bar character (""''|''"", U+007C), and must be given with the query parameter ''q''.

For example, to list all roles used in the Zettelstore, send a HTTP GET request to the endpoint ''/q?q=|role''.
If successful, the output is a JSON object:

```sh






|

|



|
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
id: 00001012051400
title: API: Query the list of all zettel
role: manual
tags: #api #manual #zettelstore
syntax: zmk
created: 20220912111111
modified: 20220913150204

The [[endpoint|00001012920000]] ''/q'' allows to query the list of all zettel.

A [[query|00001007700000]] is an optional [[search expression|00001007700000#search-expression]], together with an optional [[list of actions|00001007700000#action-list]] (described below).
An empty search expression will select all zettel.
An empty list of action will return nothing.
It is an error, if both are empty.

Search expression and action list are separated by a vertical bar character (""''|''"", U+007C), and must be given with the query parameter ''q''.

For example, to list all roles used in the Zettelstore, send a HTTP GET request to the endpoint ''/q?q=|role''.
If successful, the output is a JSON object:

```sh
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
  __n__ must be a positive integer, ''MAX'' must be given in upper-case letters.
; Any [[metadata key|00001006020000]] of type [[Word|00001006035500]], [[WordSet|00001006036000]], or [[TagSet|00001006034000]] (aggregates)
: Emit an aggregate of the given metadata key.
  The key can be given in any letter case.

Only the first aggregate action will be executed.

If no valid aggregate action is given, the metadata of all selected zettel are returned.[^For this reason, a HTTP GET to the endpoint ''/j'' is an alias for the endpoint ''/q''.]

```sh
# curl http://127.0.0.1:23123/q
{"query":"","list":[{"id":"00001012051200","meta":{"title":"API: Renew an access token","tags":"#api #manual #zettelstore","syntax":"zmk","role":"manual"},"rights":62},{"id":"00001012050600","meta":{"title":"API: Provide an access token","tags":"#api #manual #zettelstore","syntax":"zmk","role":"manual"},"rights":62},{"id":"00001012050400","meta":{"title":"API: Renew an access token","tags":"#api #manual #zettelstore","syntax":"zmk","role":"manual"},"rights":62},{"id":"00001012050200","meta":{"title":"API: Authenticate a client","tags":"#api #manual #zettelstore","syntax":"zmk","role":"manual"},"rights":62},{"id":"00001012000000","meta":{"title":"API","tags":"#api #manual #zettelstore","syntax":"zmk","role":"manual"},"rights":62}]}
```

The JSON object contains a key ''"list"'' where its value is a list of zettel JSON objects.
These zettel JSON objects themselves contains the keys ''"id"'' (value is a string containing the [[zettel identifier|00001006050000]]), ''"meta"'' (value as a JSON object), and ''"rights"'' (encodes the [[access rights|00001012921200]] for the given zettel).
The value of key ''"meta"'' effectively contains all metadata of the identified zettel, where metadata keys are encoded as JSON object keys and metadata values encoded as JSON strings.

Additionally, the JSON object contains the keys ''"query"'' and ''"human"'' with a string value.
Both will contain a textual description of the underlying query if you select only some zettel with a [[query expression|00001007700000]].
Without a selection, the values are the empty string.
''"query"'' returns the normalized query expression itself, while ''"human"'' is the normalized query expression to be read by humans.

If you reformat the JSON output from the ''GET /q'' call, you'll see its structure better:

```json
{
  "query": "",
  "human": "",
  "list": [
    {
      "id": "00001012051200",
      "meta": {
        "title": "API: List for all zettel some data",
        "tags": "#api #manual #zettelstore",
        "syntax": "zmk",
        "role": "manual"
      },
      "rights":62
    },
    {
      "id": "00001012050600",
      "meta": {
        "title": "API: Provide an access token",
        "tags": "#api #manual #zettelstore",
        "syntax": "zmk",
        "role": "manual"
      },
      "rights":62
    },
    {
      "id": "00001012050400",
      "meta": {
        "title": "API: Renew an access token",
        "tags": "#api #manual #zettelstore",
        "syntax": "zmk",
        "role": "manual"
      },
      "rights":62
    },
    {
      "id": "00001012050200",
      "meta": {
        "title": "API: Authenticate a client",
        "tags": "#api #manual #zettelstore",
        "syntax": "zmk",
        "role": "manual"
      },
      "rights":62
    },
    {
      "id": "00001012000000",
      "meta": {
        "title": "API",
        "tags": "#api #manual #zettelstore",
        "syntax": "zmk",
        "role": "manual"
      },
      "rights":62
    }
  ]
}
```
In this special case, the metadata of each zettel just contains the four default keys ''title'', ''tags'', ''syntax'', and ''role''.

=== Note
This request (and similar others) will always return a list of metadata, provided the request was syntactically correct.
There will never be a HTTP status code 403 (Forbidden), even if [[authentication was enabled|00001010040100]] and you did not provide a valid access token.
In this case, the resulting list might be quite short (some zettel will have [[public visibility|00001010070200]]) or the list might be empty.

With this call, you cannot differentiate between an empty result list (e.g because your search did not found a zettel with the specified term) and an empty list because of missing authorization (e.g. an invalid access token).

=== HTTP Status codes
; ''200''
: Query was successful.
; ''204''
: Query was successful, but results in no content.
  Most likely, you specified no appropriate aggregator.
; ''400''
: Request was not valid. 
  There are several reasons for this.
  Maybe the access bearer token was not valid, or you forgot to specify a valid query.







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<










50
51
52
53
54
55
56





















































































57
58
59
60
61
62
63
64
65
66
  __n__ must be a positive integer, ''MAX'' must be given in upper-case letters.
; Any [[metadata key|00001006020000]] of type [[Word|00001006035500]], [[WordSet|00001006036000]], or [[TagSet|00001006034000]] (aggregates)
: Emit an aggregate of the given metadata key.
  The key can be given in any letter case.

Only the first aggregate action will be executed.






















































































=== HTTP Status codes
; ''200''
: Query was successful.
; ''204''
: Query was successful, but results in no content.
  Most likely, you specified no appropriate aggregator.
; ''400''
: Request was not valid. 
  There are several reasons for this.
  Maybe the access bearer token was not valid, or you forgot to specify a valid query.

Added docs/manual/00001012051840.zettel.























































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
id: 00001012051840
title: API: Shape the list of zettel metadata by specifying a query expression
role: manual
tags: #api #manual #search #zettelstore
syntax: zmk
created: 20210709143714
modified: 20220913150355

The query parameter ""''q''"" allows you to specify [[query expressions|00001007700000]] for a full-text search of all zettel content and/or restricting the search according to specific metadata.

You are allowed to specify this query parameter more than once, as well as the other query parameters.
All results will be intersected, i.e. a zettel will be included into the list if all of the provided values match.

This parameter loosely resembles the search form of the [[web user interface|00001014000000]].

For example, if you want to retrieve all zettel that contain the string ""API"" in its title, your request will be:
```sh
# curl 'http://127.0.0.1:23123/j?q=title%3AAPI'
{"query":"title MATCH API","list":[{"id":"00001012921000","meta":{"title":"API: JSON structure of an access token","tags":"#api #manual #reference #zettelstore","syntax":"zmk","role":"manual"}},{"id":"00001012920500","meta":{"title":"Formats available by the API","tags":"#api #manual #reference #zettelstore","syntax":"zmk","role":"manual"}},{"id":"00001012920000","meta":{"title":"Endpoints used by the API","tags":"#api #manual #reference #zettelstore","syntax":"zmk","role":"manual"}}, ...
```

However, if you want all zettel that does not match a given value, you must prefix the value with the exclamation mark character (""!"", U+0021).
For example, if you want to retrieve all zettel that do not contain the string ""API"" in their title, your request will be:
```sh
# curl 'http://127.0.0.1:23123/j?q=title!%3AAPI'
{"query":"title NOT MATCH API","list":[{"id":"00010000000000","meta":{"back":"00001003000000 00001005090000","backward":"00001003000000 00001005090000","copyright":"(c) 2020-2021 by Detlef Stern <ds@zettelstore.de>","forward":"00000000000001 00000000000003 00000000000096 00000000000100","lang":"en","license":"EUPL-1.2-or-later","role":"zettel","syntax":"zmk","title":"Home"}},{"id":"00001014000000","meta":{"back":"00001000000000 00001004020000 00001012920510","backward":"00001000000000 00001004020000 00001012000000 00001012920510","copyright":"(c) 2020-2021 by Detlef Stern <ds@zettelstore.de>","forward":"00001012000000","lang":"en","license":"EUPL-1.2-or-later","published":"00001014000000","role":"manual","syntax":"zmk","tags":"#manual #webui #zettelstore","title":"Web user interface"}},
...
```

In both cases, an implicit precondition is that the zettel must contain the given metadata key.
For a metadata key like [[''title''|00001006020000#title]], which has a default value, this precondition should always be true.
But the situation is different for a key like [[''url''|00001006020000#url]].
Both ``curl 'http://localhost:23123/j?q=url%3A'`` and ``curl 'http://localhost:23123/j?q=url%3A!'`` may result in an empty list.

Alternatively, you also can use the [[endpoint|00001012920000]] ''/z'' for a simpler result format.
The first example translates to:
```sh
# curl 'http://127.0.0.1:23123/z?q=title%3AAPI'
00001012921000 API: JSON structure of an access token
00001012920500 Formats available by the API
00001012920000 Endpoints used by the API
...
```

Added docs/manual/00001012052400.zettel.



















































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
id: 00001012052400
title: API: Map metadata values to list of zettel identifier
role: manual
tags: #api #manual #zettelstore
syntax: zmk
created: 20210216172944

modified: 20220912112253

**Note**: this endpoint is deprecated since v0.7 and will be removed in v0.8.
Please use a [[query|00001012051400]] instead.
---
The [[endpoint|00001012920000]] ''/m'' allows to retrieve a map of metadata values (of a specific key) to the list of zettel identifier, which reference zettel containing this value under the given metadata key.

Currently, two keys are supported:
* [[''role''|00001006020100]]
* [[''tags''|00001006020000#tags]]

To list all roles used in the Zettelstore, send a HTTP GET request to the endpoint ''/m?key=role''.
If successful, the output is a JSON object:

```sh
# curl http://127.0.0.1:23123/m?key=role
{"map":{"configuration":["00000000090002","00000000090000", ... ,"00000000000001"],"manual":["00001014000000", ... ,"00001000000000"],"zettel":["00010000000000", ... ,"00001012070500","00000000090001"]}}
```

The JSON object only contains the key ''"map"'' with the value of another object.
This second object contains all role names as keys and the list of identifier of those zettel with this specific role as a value.

Similar, to list all tags used in the Zettelstore, send a HTTP GET request to the endpoint ''/m?key=tags''.
If successful, the output is a JSON object:

```sh
# curl http://127.0.0.1:23123/m?key=tags
{"map":{"#api":[:["00001012921000","00001012920800","00001012920522",...],"#authorization":["00001010040700","00001010040400",...],...,"#zettelstore":["00010000000000","00001014000000",...,"00001001000000"]}}
```

The JSON object only contains the key ''"map"'' with the value of another object.
This second object contains all tags as keys and the list of identifier of those zettel with this tag as a value.

Please note that this structure will likely change in the future to be more compliant with other API calls.

Changes to docs/manual/00001012053400.zettel.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

22
23
24
25
26
27
28
id: 00001012053400
title: API: Retrieve metadata of an existing zettel
role: manual
tags: #api #manual #zettelstore
syntax: zmk
created: 20210726174524
modified: 20220917175233

The [[endpoint|00001012920000]] to work with metadata of a specific zettel is ''/m/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000]].

For example, to retrieve some data about this zettel you are currently viewing, just send a HTTP GET request to the endpoint ''/j/00001012053400''[^If [[authentication is enabled|00001010040100]], you must include the a valid [[access token|00001012050200]] in the ''Authorization'' header].
If successful, the output is a JSON object:
```sh
# curl http://127.0.0.1:23123/m/00001012053400
{"meta":{"back":"00001012000000 00001012053300","backward":"00001012000000 00001012053300 00001012920000","box-number":"1","forward":"00001010040100 00001012050200 00001012920000 00001012920800","modified":"20211004111240","published":"20211004111240","role":"manual","syntax":"zmk","tags":"#api #manual #zettelstore","title":"API: Retrieve metadata of an existing zettel"},"rights":62}
```

Pretty-printed, this results in:
```
{
  "meta": {

    "back": "00001012000000 00001012053300",
    "backward": "00001012000000 00001012053300 00001012920000",
    "box-number": "1",
    "forward": "00001010040100 00001012050200 00001012920000 00001012920800",
    "modified": "20211004111240",
    "published": "20211004111240",
    "role": "manual",






|







|






>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
id: 00001012053400
title: API: Retrieve metadata of an existing zettel
role: manual
tags: #api #manual #zettelstore
syntax: zmk
created: 20210726174524
modified: 20220908162635

The [[endpoint|00001012920000]] to work with metadata of a specific zettel is ''/m/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000]].

For example, to retrieve some data about this zettel you are currently viewing, just send a HTTP GET request to the endpoint ''/j/00001012053400''[^If [[authentication is enabled|00001010040100]], you must include the a valid [[access token|00001012050200]] in the ''Authorization'' header].
If successful, the output is a JSON object:
```sh
# curl http://127.0.0.1:23123/m/00001012053400
{"meta":{"all-tags":"#api #manual #zettelstore","back":"00001012000000 00001012053300","backward":"00001012000000 00001012053300 00001012920000","box-number":"1","forward":"00001010040100 00001012050200 00001012920000 00001012920800","modified":"20211004111240","published":"20211004111240","role":"manual","syntax":"zmk","tags":"#api #manual #zettelstore","title":"API: Retrieve metadata of an existing zettel"},"rights":62}
```

Pretty-printed, this results in:
```
{
  "meta": {
    "all-tags": "#api #manual #zettelstore",
    "back": "00001012000000 00001012053300",
    "backward": "00001012000000 00001012053300 00001012920000",
    "box-number": "1",
    "forward": "00001010040100 00001012050200 00001012920000 00001012920800",
    "modified": "20211004111240",
    "published": "20211004111240",
    "role": "manual",

Changes to docs/manual/00001012080500.zettel.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
id: 00001012080500
title: API: Refresh internal data
role: manual
tags: #api #manual #zettelstore
syntax: zmk
created: 20211230230441
modified: 20220923104836

Zettelstore maintains some internal data to allow faster operations.

One example is the [[content search|00001012051400]] for a term: Zettelstore does not need to scan all zettel to find all occurrences for the term.
Instead, all word are stored internally, with a list of zettel where they occur.

Another example is the way to determine which zettel are stored in a [[ZIP file|00001004011200]].
Scanning a ZIP file is a lengthy operation, therefore Zettelstore maintains a directory of zettel for each ZIP file.

All these internal data may become stale.
This should not happen, but when it comes e.g. to file handling, every operating systems behaves differently in very subtle ways.






|



|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
id: 00001012080500
title: API: Refresh internal data
role: manual
tags: #api #manual #zettelstore
syntax: zmk
created: 20211230230441
modified: 20220908163223

Zettelstore maintains some internal data to allow faster operations.

One example is the [[content search|00001012051840]] for a term: Zettelstore does not need to scan all zettel to find all occurrences for the term.
Instead, all word are stored internally, with a list of zettel where they occur.

Another example is the way to determine which zettel are stored in a [[ZIP file|00001004011200]].
Scanning a ZIP file is a lengthy operation, therefore Zettelstore maintains a directory of zettel for each ZIP file.

All these internal data may become stale.
This should not happen, but when it comes e.g. to file handling, every operating systems behaves differently in very subtle ways.

Changes to docs/manual/00001012920000.zettel.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
id: 00001012920000
title: Endpoints used by the API
role: manual
tags: #api #manual #reference #zettelstore
syntax: zmk
created: 20210126175322
modified: 20220923101703

All API endpoints conform to the pattern ''[PREFIX]LETTER[/ZETTEL-ID]'', where:
; ''PREFIX''
: is the URL prefix (default: ""/""), configured via the ''url-prefix'' [[startup configuration|00001004010000]],
; ''LETTER''
: is a single letter that specifies the resource type,
; ''ZETTEL-ID''
: is an optional 14 digits string that uniquely [[identify a zettel|00001006050000]].

The following letters are currently in use:

|= Letter:| Without zettel identifier | With [[zettel identifier|00001006050000]] | Mnemonic
| ''a'' | POST: [[client authentication|00001012050200]] | | **A**uthenticate
|       | PUT: [[renew access token|00001012050400]] |
| ''j'' | GET: [[query zettel list|00001012051400]] (alias of ''/q'') | GET: [[retrieve zettel AS JSON|00001012053300]] | **J**SON
|       | POST: [[create new zettel|00001012053200]] | PUT: [[update a zettel|00001012054200]]
|       |  | DELETE: [[delete the zettel|00001012054600]]
|       |  | MOVE: [[rename the zettel|00001012054400]]
| ''m'' |  | GET: [[retrieve metadata|00001012053400]] | **M**etadata
| ''o'' |  | GET: [[list zettel order|00001012054000]] | **O**rder
| ''p'' |  | GET: [[retrieve parsed zettel|00001012053600]]| **P**arsed
| ''q'' | GET: [[query zettel list|00001012051400]] |  | **Q**uery
| ''u'' |  | GET [[unlinked references|00001012053900]] | **U**nlinked
| ''v'' |  | GET: [[retrieve evaluated zettel|00001012053500]] | E**v**aluated
| ''x'' | GET: [[retrieve administrative data|00001012070500]] | GET: [[list zettel context|00001012053800]] | Conte**x**t
|       | POST: [[execute command|00001012080100]]






|














|



|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
id: 00001012920000
title: Endpoints used by the API
role: manual
tags: #api #manual #reference #zettelstore
syntax: zmk
created: 20210126175322
modified: 20220912115218

All API endpoints conform to the pattern ''[PREFIX]LETTER[/ZETTEL-ID]'', where:
; ''PREFIX''
: is the URL prefix (default: ""/""), configured via the ''url-prefix'' [[startup configuration|00001004010000]],
; ''LETTER''
: is a single letter that specifies the resource type,
; ''ZETTEL-ID''
: is an optional 14 digits string that uniquely [[identify a zettel|00001006050000]].

The following letters are currently in use:

|= Letter:| Without zettel identifier | With [[zettel identifier|00001006050000]] | Mnemonic
| ''a'' | POST: [[client authentication|00001012050200]] | | **A**uthenticate
|       | PUT: [[renew access token|00001012050400]] |
| ''j'' | GET: [[list zettel AS JSON|00001012051200]] | GET: [[retrieve zettel AS JSON|00001012053300]] | **J**SON
|       | POST: [[create new zettel|00001012053200]] | PUT: [[update a zettel|00001012054200]]
|       |  | DELETE: [[delete the zettel|00001012054600]]
|       |  | MOVE: [[rename the zettel|00001012054400]]
| ''m'' | GET: [[map metadata values|00001012052400]] (deprecated) | GET: [[retrieve metadata|00001012053400]] | **M**etadata
| ''o'' |  | GET: [[list zettel order|00001012054000]] | **O**rder
| ''p'' |  | GET: [[retrieve parsed zettel|00001012053600]]| **P**arsed
| ''q'' | GET: [[query zettel list|00001012051400]] |  | **Q**uery
| ''u'' |  | GET [[unlinked references|00001012053900]] | **U**nlinked
| ''v'' |  | GET: [[retrieve evaluated zettel|00001012053500]] | E**v**aluated
| ''x'' | GET: [[retrieve administrative data|00001012070500]] | GET: [[list zettel context|00001012053800]] | Conte**x**t
|       | POST: [[execute command|00001012080100]]

Changes to domain/meta/meta.go.

130
131
132
133
134
135
136

137
138
139
140

141
142
143
144
145
146
147
func init() {
	registerKey(api.KeyID, TypeID, usageComputed, "")
	registerKey(api.KeyTitle, TypeZettelmarkup, usageUser, "")
	registerKey(api.KeyRole, TypeWord, usageUser, "")
	registerKey(api.KeyTags, TypeTagSet, usageUser, "")
	registerKey(api.KeySyntax, TypeWord, usageUser, "")


	registerKey(api.KeyAuthor, TypeString, usageUser, "")
	registerKey(api.KeyBack, TypeIDSet, usageProperty, "")
	registerKey(api.KeyBackward, TypeIDSet, usageProperty, "")
	registerKey(api.KeyBoxNumber, TypeNumber, usageProperty, "")

	registerKey(api.KeyCopyright, TypeString, usageUser, "")
	registerKey(api.KeyCreated, TypeTimestamp, usageComputed, "")
	registerKey(api.KeyCredential, TypeCredential, usageUser, "")
	registerKey(api.KeyDead, TypeIDSet, usageProperty, "")
	registerKey(api.KeyFolge, TypeIDSet, usageProperty, "")
	registerKey(api.KeyForward, TypeIDSet, usageProperty, "")
	registerKey(api.KeyLang, TypeWord, usageUser, "")







>




>







130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
func init() {
	registerKey(api.KeyID, TypeID, usageComputed, "")
	registerKey(api.KeyTitle, TypeZettelmarkup, usageUser, "")
	registerKey(api.KeyRole, TypeWord, usageUser, "")
	registerKey(api.KeyTags, TypeTagSet, usageUser, "")
	registerKey(api.KeySyntax, TypeWord, usageUser, "")

	registerKey(api.KeyAllTags, TypeTagSet, usageProperty, "")
	registerKey(api.KeyAuthor, TypeString, usageUser, "")
	registerKey(api.KeyBack, TypeIDSet, usageProperty, "")
	registerKey(api.KeyBackward, TypeIDSet, usageProperty, "")
	registerKey(api.KeyBoxNumber, TypeNumber, usageProperty, "")
	registerKey(api.KeyContentTags, TypeTagSet, usageProperty, "")
	registerKey(api.KeyCopyright, TypeString, usageUser, "")
	registerKey(api.KeyCreated, TypeTimestamp, usageComputed, "")
	registerKey(api.KeyCredential, TypeCredential, usageUser, "")
	registerKey(api.KeyDead, TypeIDSet, usageProperty, "")
	registerKey(api.KeyFolge, TypeIDSet, usageProperty, "")
	registerKey(api.KeyForward, TypeIDSet, usageProperty, "")
	registerKey(api.KeyLang, TypeWord, usageUser, "")

Changes to encoder/sexprenc/transform.go.

79
80
81
82
83
84
85


86
87
88
89
90
91
92
		return t.getTable(n)
	case *ast.TranscludeNode:
		return sxpf.NewPairFromValues(sexpr.SymTransclude, getAttributes(n.Attrs), getReference(n.Ref))
	case *ast.BLOBNode:
		return getBLOB(n)
	case *ast.TextNode:
		return sxpf.NewPairFromValues(sexpr.SymText, sxpf.NewString(n.Text))


	case *ast.SpaceNode:
		if t.inVerse {
			return sxpf.NewPairFromValues(sexpr.SymSpace, sxpf.NewString(n.Lexeme))
		}
		return sxpf.NewPairFromValues(sexpr.SymSpace)
	case *ast.BreakNode:
		if n.Hard {







>
>







79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
		return t.getTable(n)
	case *ast.TranscludeNode:
		return sxpf.NewPairFromValues(sexpr.SymTransclude, getAttributes(n.Attrs), getReference(n.Ref))
	case *ast.BLOBNode:
		return getBLOB(n)
	case *ast.TextNode:
		return sxpf.NewPairFromValues(sexpr.SymText, sxpf.NewString(n.Text))
	case *ast.TagNode:
		return sxpf.NewPairFromValues(sexpr.SymTag, sxpf.NewString(n.Tag))
	case *ast.SpaceNode:
		if t.inVerse {
			return sxpf.NewPairFromValues(sexpr.SymSpace, sxpf.NewString(n.Lexeme))
		}
		return sxpf.NewPairFromValues(sexpr.SymSpace)
	case *ast.BreakNode:
		if n.Hard {

Changes to encoder/textenc/textenc.go.

127
128
129
130
131
132
133



134
135
136
137
138
139
140
		v.visitTable(n)
		return nil
	case *ast.TranscludeNode, *ast.BLOBNode:
		return nil
	case *ast.TextNode:
		v.b.WriteString(n.Text)
		return nil



	case *ast.SpaceNode:
		v.b.WriteByte(' ')
		return nil
	case *ast.BreakNode:
		if n.Hard {
			v.b.WriteByte('\n')
		} else {







>
>
>







127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
		v.visitTable(n)
		return nil
	case *ast.TranscludeNode, *ast.BLOBNode:
		return nil
	case *ast.TextNode:
		v.b.WriteString(n.Text)
		return nil
	case *ast.TagNode:
		v.b.WriteString(n.Tag)
		return nil
	case *ast.SpaceNode:
		v.b.WriteByte(' ')
		return nil
	case *ast.BreakNode:
		if n.Hard {
			v.b.WriteByte('\n')
		} else {

Changes to encoder/zjsonenc/zjsonenc.go.

120
121
122
123
124
125
126




127
128
129
130
131
132
133
		writeEscaped(&v.b, n.Ref.String())
	case *ast.BLOBNode:
		v.visitBLOB(n)
	case *ast.TextNode:
		v.writeNodeStart(zjson.TypeText)
		v.writeContentStart(zjson.NameString)
		writeEscaped(&v.b, n.Text)




	case *ast.SpaceNode:
		v.writeNodeStart(zjson.TypeSpace)
		if v.inVerse {
			v.writeContentStart(zjson.NameString)
			writeEscaped(&v.b, n.Lexeme)
		}
	case *ast.BreakNode:







>
>
>
>







120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
		writeEscaped(&v.b, n.Ref.String())
	case *ast.BLOBNode:
		v.visitBLOB(n)
	case *ast.TextNode:
		v.writeNodeStart(zjson.TypeText)
		v.writeContentStart(zjson.NameString)
		writeEscaped(&v.b, n.Text)
	case *ast.TagNode:
		v.writeNodeStart(zjson.TypeTag)
		v.writeContentStart(zjson.NameString)
		writeEscaped(&v.b, n.Tag)
	case *ast.SpaceNode:
		v.writeNodeStart(zjson.TypeSpace)
		if v.inVerse {
			v.writeContentStart(zjson.NameString)
			writeEscaped(&v.b, n.Lexeme)
		}
	case *ast.BreakNode:

Changes to encoder/zmkenc/zmkenc.go.

127
128
129
130
131
132
133


134
135
136
137
138
139
140
	case *ast.TranscludeNode:
		v.b.WriteStrings("{{{", n.Ref.String(), "}}}")
		v.visitAttributes(n.Attrs)
	case *ast.BLOBNode:
		v.visitBLOB(n)
	case *ast.TextNode:
		v.visitText(n)


	case *ast.SpaceNode:
		v.b.WriteString(n.Lexeme)
	case *ast.BreakNode:
		v.visitBreak(n)
	case *ast.LinkNode:
		v.visitLink(n)
	case *ast.EmbedRefNode:







>
>







127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
	case *ast.TranscludeNode:
		v.b.WriteStrings("{{{", n.Ref.String(), "}}}")
		v.visitAttributes(n.Attrs)
	case *ast.BLOBNode:
		v.visitBLOB(n)
	case *ast.TextNode:
		v.visitText(n)
	case *ast.TagNode:
		v.b.WriteStrings("#", n.Tag)
	case *ast.SpaceNode:
		v.b.WriteString(n.Lexeme)
	case *ast.BreakNode:
		v.visitBreak(n)
	case *ast.LinkNode:
		v.visitLink(n)
	case *ast.EmbedRefNode:

Changes to encoding/rss/rss.go.

68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
				itemPublished = published.UTC().Format(time.RFC1123Z)
				if maxPublished.Before(published) {
					maxPublished = published
				}
			}
		}

		link := c.NewURLBuilderAbs().SetZid(api.ZettelID(m.Zid.String())).String()
		rssItems = append(rssItems, &RssItem{
			Title:   title.String(),
			Link:    link,
			GUID:    link,
			PubDate: itemPublished,
		})
	}

	rssPublished := ""
	if maxPublished.Year() > 1 {
		rssPublished = maxPublished.UTC().Format(time.RFC1123Z)







<


<
|







68
69
70
71
72
73
74

75
76

77
78
79
80
81
82
83
84
				itemPublished = published.UTC().Format(time.RFC1123Z)
				if maxPublished.Before(published) {
					maxPublished = published
				}
			}
		}


		rssItems = append(rssItems, &RssItem{
			Title:   title.String(),

			GUID:    c.NewURLBuilderAbs().SetZid(api.ZettelID(m.Zid.String())).String(),
			PubDate: itemPublished,
		})
	}

	rssPublished := ""
	if maxPublished.Year() > 1 {
		rssPublished = maxPublished.UTC().Format(time.RFC1123Z)
138
139
140
141
142
143
144
145
146
147
148
149
		Href    string   `xml:"href,attr"`
		Rel     string   `xml:"rel,attr"`
		Type    string   `xml:"type,attr"`
	}
	RssItem struct {
		XMLName xml.Name `xml:"item"`
		Title   string   `xml:"title"`
		Link    string   `xml:"link"` // Needed, b/c Miniflux does not use GUID for URL
		GUID    string   `xml:"guid"`
		PubDate string   `xml:"pubDate,omitempty"` // RFC822
	}
)







<




136
137
138
139
140
141
142

143
144
145
146
		Href    string   `xml:"href,attr"`
		Rel     string   `xml:"rel,attr"`
		Type    string   `xml:"type,attr"`
	}
	RssItem struct {
		XMLName xml.Name `xml:"item"`
		Title   string   `xml:"title"`

		GUID    string   `xml:"guid"`
		PubDate string   `xml:"pubDate,omitempty"` // RFC822
	}
)

Changes to evaluator/evaluator.go.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Package evaluator interprets and evaluates the AST.
package evaluator

import (
	"context"
	"errors"
	"fmt"
	"path"
	"strconv"
	"strings"

	"zettelstore.de/c/api"
	"zettelstore.de/c/attrs"
	"zettelstore.de/z/ast"
	"zettelstore.de/z/box"







<







11
12
13
14
15
16
17

18
19
20
21
22
23
24
// Package evaluator interprets and evaluates the AST.
package evaluator

import (
	"context"
	"errors"
	"fmt"

	"strconv"
	"strings"

	"zettelstore.de/c/api"
	"zettelstore.de/c/attrs"
	"zettelstore.de/z/ast"
	"zettelstore.de/z/box"
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
		// Only zettel references will be evaluated.
	case ast.RefStateInvalid, ast.RefStateBroken:
		e.transcludeCount++
		return makeBlockNode(createInlineErrorText(ref, "Invalid", "or", "broken", "transclusion", "reference"))
	case ast.RefStateSelf:
		e.transcludeCount++
		return makeBlockNode(createInlineErrorText(ref, "Self", "transclusion", "reference"))
	case ast.RefStateFound, ast.RefStateExternal:
		return tn
	case ast.RefStateHosted, ast.RefStateBased:
		if n := createEmbeddedNodeLocal(ref); n != nil {
			n.Attrs = tn.Attrs
			return makeBlockNode(n)
		}
		return tn
	case ast.RefStateQuery:
		e.transcludeCount++
		return e.evalQueryTransclusion(tn.Ref.Value)
	default:
		return makeBlockNode(createInlineErrorText(ref, "Illegal", "block", "state", strconv.Itoa(int(ref.State))))
	}







|
<
<
<
<
<
<







199
200
201
202
203
204
205
206






207
208
209
210
211
212
213
		// Only zettel references will be evaluated.
	case ast.RefStateInvalid, ast.RefStateBroken:
		e.transcludeCount++
		return makeBlockNode(createInlineErrorText(ref, "Invalid", "or", "broken", "transclusion", "reference"))
	case ast.RefStateSelf:
		e.transcludeCount++
		return makeBlockNode(createInlineErrorText(ref, "Self", "transclusion", "reference"))
	case ast.RefStateFound, ast.RefStateHosted, ast.RefStateBased, ast.RefStateExternal:






		return tn
	case ast.RefStateQuery:
		e.transcludeCount++
		return e.evalQueryTransclusion(tn.Ref.Value)
	default:
		return makeBlockNode(createInlineErrorText(ref, "Illegal", "block", "state", strconv.Itoa(int(ref.State))))
	}
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
		// Only zettel references will be evaluated.
	case ast.RefStateInvalid, ast.RefStateBroken:
		e.transcludeCount++
		return createInlineErrorImage(en)
	case ast.RefStateSelf:
		e.transcludeCount++
		return createInlineErrorText(ref, "Self", "embed", "reference")
	case ast.RefStateFound, ast.RefStateExternal:
		return en
	case ast.RefStateHosted, ast.RefStateBased:
		if n := createEmbeddedNodeLocal(ref); n != nil {
			n.Attrs = en.Attrs
			n.Inlines = en.Inlines
			return n
		}
		return en
	default:
		return createInlineErrorText(ref, "Illegal", "inline", "state", strconv.Itoa(int(ref.State)))
	}

	zid := mustParseZid(ref)
	zettel, err := e.port.GetZettel(box.NoEnrichContext(e.ctx), zid)







|
<
<
<
<
<
<
<







374
375
376
377
378
379
380
381







382
383
384
385
386
387
388
		// Only zettel references will be evaluated.
	case ast.RefStateInvalid, ast.RefStateBroken:
		e.transcludeCount++
		return createInlineErrorImage(en)
	case ast.RefStateSelf:
		e.transcludeCount++
		return createInlineErrorText(ref, "Self", "embed", "reference")
	case ast.RefStateFound, ast.RefStateHosted, ast.RefStateBased, ast.RefStateExternal:







		return en
	default:
		return createInlineErrorText(ref, "Illegal", "inline", "state", strconv.Itoa(int(ref.State)))
	}

	zid := mustParseZid(ref)
	zettel, err := e.port.GetZettel(box.NoEnrichContext(e.ctx), zid)
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
		Kind:    ast.FormatStrong,
		Inlines: ast.InlineSlice{ln},
	}
	fn.Attrs = fn.Attrs.AddClass("error")
	return fn
}

func createEmbeddedNodeLocal(ref *ast.Reference) *ast.EmbedRefNode {
	ext := path.Ext(ref.Value)
	if ext != "" && ext[0] == '.' {
		ext = ext[1:]
	}
	pinfo := parser.Get(ext)
	if pinfo == nil || !pinfo.IsImageFormat {
		return nil
	}
	return &ast.EmbedRefNode{
		Ref:    ref,
		Syntax: ext,
	}
}

func (e *evaluator) evaluateEmbeddedInline(content []byte, syntax string) ast.InlineSlice {
	is := parser.ParseInlines(input.NewInput(content), syntax)
	ast.Walk(e, &is)
	return is
}

func (e *evaluator) evaluateEmbeddedZettel(zettel domain.Zettel) *ast.ZettelNode {







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







484
485
486
487
488
489
490















491
492
493
494
495
496
497
		Kind:    ast.FormatStrong,
		Inlines: ast.InlineSlice{ln},
	}
	fn.Attrs = fn.Attrs.AddClass("error")
	return fn
}
















func (e *evaluator) evaluateEmbeddedInline(content []byte, syntax string) ast.InlineSlice {
	is := parser.ParseInlines(input.NewInput(content), syntax)
	ast.Walk(e, &is)
	return is
}

func (e *evaluator) evaluateEmbeddedZettel(zettel domain.Zettel) *ast.ZettelNode {

Changes to go.mod.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
module zettelstore.de/z

go 1.19

require (
	codeberg.org/t73fde/sxpf v0.0.0-20220719090054-749a39d0a7a0
	github.com/fsnotify/fsnotify v1.5.4
	github.com/pascaldekloe/jwt v1.12.0
	github.com/yuin/goldmark v1.5.1
	golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90
	golang.org/x/term v0.0.0-20220722155259-a9ba230a4035
	golang.org/x/text v0.3.7
	zettelstore.de/c v0.7.1-0.20220917171338-230ea91fc34d
)

require golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 // indirect








|



|



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
module zettelstore.de/z

go 1.19

require (
	codeberg.org/t73fde/sxpf v0.0.0-20220719090054-749a39d0a7a0
	github.com/fsnotify/fsnotify v1.5.4
	github.com/pascaldekloe/jwt v1.12.0
	github.com/yuin/goldmark v1.4.14
	golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90
	golang.org/x/term v0.0.0-20220722155259-a9ba230a4035
	golang.org/x/text v0.3.7
	zettelstore.de/c v0.7.0
)

require golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 // indirect

Changes to go.sum.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
codeberg.org/t73fde/sxpf v0.0.0-20220719090054-749a39d0a7a0 h1:viya/OgeF16+i8caBPJmcLQhGpZodPh+/nxtJzSSO1s=
codeberg.org/t73fde/sxpf v0.0.0-20220719090054-749a39d0a7a0/go.mod h1:4fAHEF3VH+ofbZkF6NzqiItTNy2X11tVCnZX99jXouA=
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/pascaldekloe/jwt v1.12.0 h1:imQSkPOtAIBAXoKKjL9ZVJuF/rVqJ+ntiLGpLyeqMUQ=
github.com/pascaldekloe/jwt v1.12.0/go.mod h1:LiIl7EwaglmH1hWThd/AmydNCnHf/mmfluBlNqHbk8U=
github.com/yuin/goldmark v1.5.1 h1:u+ry9U7p4EE0QhDhdOQi7rzmAakZlrMg1B7VbLbhW0Y=
github.com/yuin/goldmark v1.5.1/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 h1:Y/gsMcFOcR+6S6f3YeMKl5g+dZMEWqcz5Czj/GWYbkM=
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 h1:ohgcoMbSofXygzo6AD2I1kz3BFmW1QArPYTtwEM3UXc=
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 h1:Q5284mrmYTpACcm+eAKjKJH48BBwSyfJqmmGDTtT8Vc=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
zettelstore.de/c v0.7.1-0.20220917171338-230ea91fc34d h1:fi9KbrizJdSUdnLIj8E+St0gagJcAO/rzeopZ6UEg6Y=
zettelstore.de/c v0.7.1-0.20220917171338-230ea91fc34d/go.mod h1:+SoneUhKQ81A2Id/bC6FdDYYQAHYfVryh7wHFnnklew=






|
|









|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
codeberg.org/t73fde/sxpf v0.0.0-20220719090054-749a39d0a7a0 h1:viya/OgeF16+i8caBPJmcLQhGpZodPh+/nxtJzSSO1s=
codeberg.org/t73fde/sxpf v0.0.0-20220719090054-749a39d0a7a0/go.mod h1:4fAHEF3VH+ofbZkF6NzqiItTNy2X11tVCnZX99jXouA=
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/pascaldekloe/jwt v1.12.0 h1:imQSkPOtAIBAXoKKjL9ZVJuF/rVqJ+ntiLGpLyeqMUQ=
github.com/pascaldekloe/jwt v1.12.0/go.mod h1:LiIl7EwaglmH1hWThd/AmydNCnHf/mmfluBlNqHbk8U=
github.com/yuin/goldmark v1.4.14 h1:jwww1XQfhJN7Zm+/a1ZA/3WUiEBEroYFNTiV3dKwM8U=
github.com/yuin/goldmark v1.4.14/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 h1:Y/gsMcFOcR+6S6f3YeMKl5g+dZMEWqcz5Czj/GWYbkM=
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 h1:ohgcoMbSofXygzo6AD2I1kz3BFmW1QArPYTtwEM3UXc=
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 h1:Q5284mrmYTpACcm+eAKjKJH48BBwSyfJqmmGDTtT8Vc=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
zettelstore.de/c v0.7.0 h1:+DmAB81uVLtgf5xFKy4HqFqja+6itFyuk45S9QZeP+k=
zettelstore.de/c v0.7.0/go.mod h1:+SoneUhKQ81A2Id/bC6FdDYYQAHYfVryh7wHFnnklew=

Deleted input/entity.go.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//-----------------------------------------------------------------------------
// Copyright (c) 2022 Detlef Stern
//
// This file is part of Zettelstore.
//
// Zettelstore is licensed under the latest version of the EUPL (European Union
// Public License). Please see file LICENSE.txt for your rights and obligations
// under this license.
//-----------------------------------------------------------------------------

package input

import (
	"html"
	"unicode"
)

// ScanEntity scans either a named or a numbered entity and returns it as a string.
//
// For numbered entities (like &#123; or &#x123;) html.UnescapeString returns
// sometimes other values as expected, if the number is not well-formed. This
// may happen because of some strange HTML parsing rules. But these do not
// apply to Zettelmarkup. Therefore, I parse the number here in the code.
func (inp *Input) ScanEntity() (res string, success bool) {
	if inp.Ch != '&' {
		return "", false
	}
	pos := inp.Pos
	inp.Next()
	if inp.Ch == '#' {
		inp.Next()
		if inp.Ch == 'x' || inp.Ch == 'X' {
			return inp.scanEntityBase16()
		}
		return inp.scanEntityBase10()
	}
	return inp.scanEntityNamed(pos)
}

func (inp *Input) scanEntityBase16() (string, bool) {
	inp.Next()
	if inp.Ch == ';' {
		return "", false
	}
	code := 0
	for {
		switch ch := inp.Ch; ch {
		case ';':
			inp.Next()
			if r := rune(code); isValidEntity(r) {
				return string(r), true
			}
			return "", false
		case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
			code = 16*code + int(ch-'0')
		case 'a', 'b', 'c', 'd', 'e', 'f':
			code = 16*code + int(ch-'a'+10)
		case 'A', 'B', 'C', 'D', 'E', 'F':
			code = 16*code + int(ch-'A'+10)
		default:
			return "", false
		}
		if code > unicode.MaxRune {
			return "", false
		}
		inp.Next()
	}
}

func (inp *Input) scanEntityBase10() (string, bool) {
	// Base 10 code
	if inp.Ch == ';' {
		return "", false
	}
	code := 0
	for {
		switch ch := inp.Ch; ch {
		case ';':
			inp.Next()
			if r := rune(code); isValidEntity(r) {
				return string(r), true
			}
			return "", false
		case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
			code = 10*code + int(ch-'0')
		default:
			return "", false
		}
		if code > unicode.MaxRune {
			return "", false
		}
		inp.Next()
	}
}
func (inp *Input) scanEntityNamed(pos int) (string, bool) {
	for {
		switch inp.Ch {
		case EOS, '\n', '\r', '&':
			return "", false
		case ';':
			inp.Next()
			es := string(inp.Src[pos:inp.Pos])
			ues := html.UnescapeString(es)
			if es == ues {
				return "", false
			}
			return ues, true
		default:
			inp.Next()
		}
	}
}

// isValidEntity checks if the given code is valid for an entity.
//
// According to https://html.spec.whatwg.org/multipage/syntax.html#character-references
// ""The numeric character reference forms described above are allowed to reference any code point
// excluding U+000D CR, noncharacters, and controls other than ASCII whitespace.""
func isValidEntity(r rune) bool {
	// No C0 control and no "code point in the range U+007F DELETE to U+009F APPLICATION PROGRAM COMMAND, inclusive."
	if r < ' ' || ('\u007f' <= r && r <= '\u009f') {
		return false
	}

	// If below any noncharacter code point, return true
	//
	// See: https://infra.spec.whatwg.org/#noncharacter
	if r < '\ufdd0' {
		return true
	}

	// First range of noncharacter code points: "(...) in the range U+FDD0 to U+FDEF, inclusive"
	if r <= '\ufdef' {
		return false
	}

	// Other noncharacter code points:
	switch r {
	case '\uFFFE', '\uFFFF',
		'\U0001FFFE', '\U0001FFFF',
		'\U0002FFFE', '\U0002FFFF',
		'\U0003FFFE', '\U0003FFFF',
		'\U0004FFFE', '\U0004FFFF',
		'\U0005FFFE', '\U0005FFFF',
		'\U0006FFFE', '\U0006FFFF',
		'\U0007FFFE', '\U0007FFFF',
		'\U0008FFFE', '\U0008FFFF',
		'\U0009FFFE', '\U0009FFFF',
		'\U000AFFFE', '\U000AFFFF',
		'\U000BFFFE', '\U000BFFFF',
		'\U000CFFFE', '\U000CFFFF',
		'\U000DFFFE', '\U000DFFFF',
		'\U000EFFFE', '\U000EFFFF',
		'\U000FFFFE', '\U000FFFFF',
		'\U0010FFFE', '\U0010FFFF':
		return false
	}
	return true
}
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<






























































































































































































































































































































Deleted input/entity_test.go.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//-----------------------------------------------------------------------------
// Copyright (c) 2020-2022 Detlef Stern
//
// This file is part of Zettelstore.
//
// Zettelstore is licensed under the latest version of the EUPL (European Union
// Public License). Please see file LICENSE.txt for your rights and obligations
// under this license.
//-----------------------------------------------------------------------------

package input_test

import (
	"testing"

	"zettelstore.de/z/input"
)

func TestScanEntity(t *testing.T) {
	t.Parallel()
	var testcases = []struct {
		text string
		exp  string
	}{
		{"", ""},
		{"a", ""},
		{"&amp;", "&"},
		{"&#33;", "!"},
		{"&#x33;", "3"},
		{"&quot;", "\""},
	}
	for id, tc := range testcases {
		inp := input.NewInput([]byte(tc.text))
		got, ok := inp.ScanEntity()
		if !ok {
			if tc.exp != "" {
				t.Errorf("ID=%d, text=%q: expected error, but got %q", id, tc.text, got)
			}
			if inp.Pos != 0 {
				t.Errorf("ID=%d, text=%q: input position advances to %d", id, tc.text, inp.Pos)
			}
			continue
		}
		if tc.exp != got {
			t.Errorf("ID=%d, text=%q: expected %q, but got %q", id, tc.text, tc.exp, got)
		}
	}
}

func TestScanIllegalEntity(t *testing.T) {
	t.Parallel()
	testcases := []string{"", "a", "& Input &rarr;", "&#9;", "&#x1f;"}
	for i, tc := range testcases {
		inp := input.NewInput([]byte(tc))
		got, ok := inp.ScanEntity()
		if ok {
			t.Errorf("%d: scanning %q was unexpected successful, got %q", i, tc, got)
			continue
		}
	}
}
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


























































































































Changes to input/input.go.

8
9
10
11
12
13
14


15
16
17
18
19
20
21
// under this license.
//-----------------------------------------------------------------------------

// Package input provides an abstraction for data to be read.
package input

import (


	"unicode/utf8"
)

// Input is an abstract input source
type Input struct {
	// Read-only, will never change
	Src []byte // The source string







>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// under this license.
//-----------------------------------------------------------------------------

// Package input provides an abstraction for data to be read.
package input

import (
	"html"
	"unicode"
	"unicode/utf8"
)

// Input is an abstract input source
type Input struct {
	// Read-only, will never change
	Src []byte // The source string
132
133
134
135
136
137
138


























































































139
140
141
142
143
144
145
		switch inp.Ch {
		case EOS, '\n', '\r':
			return
		}
		inp.Next()
	}
}



























































































// ScanLineContent reads the reaining input stream and interprets it as lines of text.
func (inp *Input) ScanLineContent() []byte {
	result := make([]byte, 0, len(inp.Src)-inp.Pos+1)
	for {
		inp.EatEOL()
		posL := inp.Pos







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
		switch inp.Ch {
		case EOS, '\n', '\r':
			return
		}
		inp.Next()
	}
}

// ScanEntity scans either a named or a numbered entity and returns it as a string.
//
// For numbered entities (like &#123; or &#x123;) html.UnescapeString returns
// sometimes other values as expected, if the number is not well-formed. This
// may happen because of some strange HTML parsing rules. But these do not
// apply to Zettelmarkup. Therefore, I parse the number here in the code.
func (inp *Input) ScanEntity() (res string, success bool) {
	if inp.Ch != '&' {
		return "", false
	}
	pos := inp.Pos
	inp.Next()
	if inp.Ch == '#' {
		inp.Next()
		if inp.Ch == 'x' || inp.Ch == 'X' {
			return inp.scanEntityBase16()
		}
		return inp.scanEntityBase10()
	}
	return inp.scanEntityNamed(pos)
}

func (inp *Input) scanEntityBase16() (string, bool) {
	inp.Next()
	if inp.Ch == ';' {
		return "", false
	}
	code := 0
	for {
		switch ch := inp.Ch; ch {
		case ';':
			inp.Next()
			return string(rune(code)), true
		case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
			code = 16*code + int(ch-'0')
		case 'a', 'b', 'c', 'd', 'e', 'f':
			code = 16*code + int(ch-'a'+10)
		case 'A', 'B', 'C', 'D', 'E', 'F':
			code = 16*code + int(ch-'A'+10)
		default:
			return "", false
		}
		if code > unicode.MaxRune {
			return "", false
		}
		inp.Next()
	}
}

func (inp *Input) scanEntityBase10() (string, bool) {
	// Base 10 code
	if inp.Ch == ';' {
		return "", false
	}
	code := 0
	for {
		switch ch := inp.Ch; ch {
		case ';':
			inp.Next()
			return string(rune(code)), true
		case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
			code = 10*code + int(ch-'0')
		default:
			return "", false
		}
		if code > unicode.MaxRune {
			return "", false
		}
		inp.Next()
	}
}
func (inp *Input) scanEntityNamed(pos int) (string, bool) {
	for {
		switch inp.Ch {
		case EOS, '\n', '\r', '&':
			return "", false
		case ';':
			inp.Next()
			es := string(inp.Src[pos:inp.Pos])
			ues := html.UnescapeString(es)
			if es == ues {
				return "", false
			}
			return ues, true
		default:
			inp.Next()
		}
	}
}

// ScanLineContent reads the reaining input stream and interprets it as lines of text.
func (inp *Input) ScanLineContent() []byte {
	result := make([]byte, 0, len(inp.Src)-inp.Pos+1)
	for {
		inp.EatEOL()
		posL := inp.Pos

Changes to input/input_test.go.

33
34
35
36
37
38
39











































40
41
42
43
44
45
46
		t.Errorf("First ch != 'A', got %q", inp.Ch)
	}
	inp.EatEOL()
	if inp.Ch != 'A' {
		t.Errorf("First ch != 'A', got %q", inp.Ch)
	}
}












































func TestAccept(t *testing.T) {
	t.Parallel()
	testcases := []struct {
		accept string
		src    string
		acc    bool







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
		t.Errorf("First ch != 'A', got %q", inp.Ch)
	}
	inp.EatEOL()
	if inp.Ch != 'A' {
		t.Errorf("First ch != 'A', got %q", inp.Ch)
	}
}

func TestScanEntity(t *testing.T) {
	t.Parallel()
	var testcases = []struct {
		text string
		exp  string
	}{
		{"", ""},
		{"a", ""},
		{"&amp;", "&"},
		{"&#9;", "\t"},
		{"&quot;", "\""},
	}
	for id, tc := range testcases {
		inp := input.NewInput([]byte(tc.text))
		got, ok := inp.ScanEntity()
		if !ok {
			if tc.exp != "" {
				t.Errorf("ID=%d, text=%q: expected error, but got %q", id, tc.text, got)
			}
			if inp.Pos != 0 {
				t.Errorf("ID=%d, text=%q: input position advances to %d", id, tc.text, inp.Pos)
			}
			continue
		}
		if tc.exp != got {
			t.Errorf("ID=%d, text=%q: expected %q, but got %q", id, tc.text, tc.exp, got)
		}
	}
}

func TestScanIllegalEntity(t *testing.T) {
	t.Parallel()
	testcases := []string{"", "a", "& Input &rarr;"}
	for i, tc := range testcases {
		inp := input.NewInput([]byte(tc))
		got, ok := inp.ScanEntity()
		if ok {
			t.Errorf("%d: scanning %q was unexpected successful, got %q", i, tc, got)
			continue
		}
	}
}

func TestAccept(t *testing.T) {
	t.Parallel()
	testcases := []struct {
		accept string
		src    string
		acc    bool

Changes to parser/pikchr/internal/pikchr.go.

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
	"math"
	"os"
	"regexp"
	"strconv"
	"strings"
)

// Limit the number of tokens in a single script to avoid run-away macro expansion attacks.
// See forum post https://pikchr.org/home/forumpost/ef8684c6955a411a
const PIKCHR_TOKEN_LIMIT = 100000

// Numeric value
type PNum = float64

// Compass points
const (
	CP_N uint8 = iota + 1
	CP_NE







<
<
<
<







128
129
130
131
132
133
134




135
136
137
138
139
140
141
	"math"
	"os"
	"regexp"
	"strconv"
	"strings"
)





// Numeric value
type PNum = float64

// Compass points
const (
	CP_N uint8 = iota + 1
	CP_NE
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
}

/* Each call to the pikchr() subroutine uses an instance of the following
** object to pass around context to all of its subroutines.
 */
type Pik struct {
	nErr      int          /* Number of errors seen */
	nToken    int          // Number of tokens parsed
	sIn       PToken       /* Input Pikchr-language text */
	zOut      bytes.Buffer /* Result accumulates here */
	nOut      uint         /* Bytes written to zOut[] so far */
	nOutAlloc uint         /* Space allocated to zOut[] */
	eDir      uint8        /* Current direction */
	mFlags    uint         /* Flags passed to pikchr() */
	cur       *PObj        /* Object under construction */







<







360
361
362
363
364
365
366

367
368
369
370
371
372
373
}

/* Each call to the pikchr() subroutine uses an instance of the following
** object to pass around context to all of its subroutines.
 */
type Pik struct {
	nErr      int          /* Number of errors seen */

	sIn       PToken       /* Input Pikchr-language text */
	zOut      bytes.Buffer /* Result accumulates here */
	nOut      uint         /* Bytes written to zOut[] so far */
	nOutAlloc uint         /* Space allocated to zOut[] */
	eDir      uint8        /* Current direction */
	mFlags    uint         /* Flags passed to pikchr() */
	cur       *PObj        /* Object under construction */
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
	xOffset  func(*Pik, *PObj, uint8) PPoint            /* Offset from .c to edge point */
	xFit     func(pik *Pik, pobj *PObj, w PNum, h PNum) /* Size to fit text */
	xRender  func(*Pik, *PObj)                          /* Render */
}

func yytestcase(condition bool) {}

//line 480 "pikchr.go"

/**************** End of %include directives **********************************/
/* These constants specify the various numeric values for terminal symbols.
***************** Begin token definitions *************************************/

const (
	T_ID        = 1







|







433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
	xOffset  func(*Pik, *PObj, uint8) PPoint            /* Offset from .c to edge point */
	xFit     func(pik *Pik, pobj *PObj, w PNum, h PNum) /* Size to fit text */
	xRender  func(*Pik, *PObj)                          /* Render */
}

func yytestcase(condition bool) {}

//line 475 "pikchr.go"

/**************** End of %include directives **********************************/
/* These constants specify the various numeric values for terminal symbols.
***************** Begin token definitions *************************************/

const (
	T_ID        = 1
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
	 ** Note: during a reduce, the only symbols destroyed are those
	 ** which appear on the RHS of the rule, but which are *not* used
	 ** inside the C code.
	 */
	/********* Begin destructor definitions ***************************************/
	case 99: /* statement_list */
		{
//line 460 "pikchr.y"
			p.pik_elist_free(&(yypminor.yy186))
//line 1656 "pikchr.go"
		}
		break
	case 100: /* statement */
	case 101: /* unnamed_statement */
	case 102: /* basetype */
		{
//line 462 "pikchr.y"
			p.pik_elem_free((yypminor.yy104))
//line 1665 "pikchr.go"
		}
		break
	/********* End destructor definitions *****************************************/
	default:
		break /* If no destructor action specified: do nothing */
	}
}







|

|






|

|







1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
	 ** Note: during a reduce, the only symbols destroyed are those
	 ** which appear on the RHS of the rule, but which are *not* used
	 ** inside the C code.
	 */
	/********* Begin destructor definitions ***************************************/
	case 99: /* statement_list */
		{
//line 455 "pikchr.y"
			p.pik_elist_free(&(yypminor.yy186))
//line 1651 "pikchr.go"
		}
		break
	case 100: /* statement */
	case 101: /* unnamed_statement */
	case 102: /* basetype */
		{
//line 457 "pikchr.y"
			p.pik_elem_free((yypminor.yy104))
//line 1660 "pikchr.go"
		}
		break
	/********* End destructor definitions *****************************************/
	default:
		break /* If no destructor action specified: do nothing */
	}
}
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
	}
	for yypParser.yytos > 0 {
		yypParser.yy_pop_parser_stack()
	}
	/* Here code is inserted which will execute if the parser
	 ** stack every overflows */
	/******** Begin %stack_overflow code ******************************************/
//line 493 "pikchr.y"

	p.pik_error(nil, "parser stack overflow")
//line 1879 "pikchr.go"
	/******** End %stack_overflow code ********************************************/
	/* Suppress warning about unused %extra_argument var */
	yypParser.p = p

}

/*







|


|







1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
	}
	for yypParser.yytos > 0 {
		yypParser.yy_pop_parser_stack()
	}
	/* Here code is inserted which will execute if the parser
	 ** stack every overflows */
	/******** Begin %stack_overflow code ******************************************/
//line 488 "pikchr.y"

	p.pik_error(nil, "parser stack overflow")
//line 1874 "pikchr.go"
	/******** End %stack_overflow code ********************************************/
	/* Suppress warning about unused %extra_argument var */
	yypParser.p = p

}

/*
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
	 **  #line <lineno> <grammarfile>
	 **     { ... }           // User supplied code
	 **  #line <lineno> <thisfile>
	 **     break;
	 */
	/********** Begin reduce actions **********************************************/
	case 0: /* document ::= statement_list */
//line 497 "pikchr.y"
		{
			p.pik_render(yypParser.yystack[yypParser.yytos+0].minor.yy186)
		}
//line 2306 "pikchr.go"
		break
	case 1: /* statement_list ::= statement */
//line 500 "pikchr.y"
		{
			yylhsminor.yy186 = p.pik_elist_append(nil, yypParser.yystack[yypParser.yytos+0].minor.yy104)
		}
//line 2311 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy186 = yylhsminor.yy186
		break
	case 2: /* statement_list ::= statement_list EOL statement */
//line 502 "pikchr.y"
		{
			yylhsminor.yy186 = p.pik_elist_append(yypParser.yystack[yypParser.yytos+-2].minor.yy186, yypParser.yystack[yypParser.yytos+0].minor.yy104)
		}
//line 2317 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy186 = yylhsminor.yy186
		break
	case 3: /* statement ::= */
//line 505 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+1].minor.yy104 = nil
		}
//line 2323 "pikchr.go"
		break
	case 4: /* statement ::= direction */
//line 506 "pikchr.y"
		{
			p.pik_set_direction(uint8(yypParser.yystack[yypParser.yytos+0].minor.yy0.eCode))
			yylhsminor.yy104 = nil
		}
//line 2328 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy104 = yylhsminor.yy104
		break
	case 5: /* statement ::= lvalue ASSIGN rvalue */
//line 507 "pikchr.y"
		{
			p.pik_set_var(&yypParser.yystack[yypParser.yytos+-2].minor.yy0, yypParser.yystack[yypParser.yytos+0].minor.yy153, &yypParser.yystack[yypParser.yytos+-1].minor.yy0)
			yylhsminor.yy104 = nil
		}
//line 2334 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy104 = yylhsminor.yy104
		break
	case 6: /* statement ::= PLACENAME COLON unnamed_statement */
//line 509 "pikchr.y"
		{
			yylhsminor.yy104 = yypParser.yystack[yypParser.yytos+0].minor.yy104
			p.pik_elem_setname(yypParser.yystack[yypParser.yytos+0].minor.yy104, &yypParser.yystack[yypParser.yytos+-2].minor.yy0)
		}
//line 2340 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy104 = yylhsminor.yy104
		break
	case 7: /* statement ::= PLACENAME COLON position */
//line 511 "pikchr.y"
		{
			yylhsminor.yy104 = p.pik_elem_new(nil, nil, nil)
			if yylhsminor.yy104 != nil {
				yylhsminor.yy104.ptAt = yypParser.yystack[yypParser.yytos+0].minor.yy79
				p.pik_elem_setname(yylhsminor.yy104, &yypParser.yystack[yypParser.yytos+-2].minor.yy0)
			}
		}
//line 2347 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy104 = yylhsminor.yy104
		break
	case 8: /* statement ::= unnamed_statement */
//line 513 "pikchr.y"
		{
			yylhsminor.yy104 = yypParser.yystack[yypParser.yytos+0].minor.yy104
		}
//line 2353 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy104 = yylhsminor.yy104
		break
	case 9: /* statement ::= print prlist */
//line 514 "pikchr.y"
		{
			p.pik_append("<br>\n")
			yypParser.yystack[yypParser.yytos+-1].minor.yy104 = nil
		}
//line 2359 "pikchr.go"
		break
	case 10: /* statement ::= ASSERT LP expr EQ expr RP */
//line 519 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-5].minor.yy104 = p.pik_assert(yypParser.yystack[yypParser.yytos+-3].minor.yy153, &yypParser.yystack[yypParser.yytos+-2].minor.yy0, yypParser.yystack[yypParser.yytos+-1].minor.yy153)
		}
//line 2364 "pikchr.go"
		break
	case 11: /* statement ::= ASSERT LP position EQ position RP */
//line 521 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-5].minor.yy104 = p.pik_position_assert(&yypParser.yystack[yypParser.yytos+-3].minor.yy79, &yypParser.yystack[yypParser.yytos+-2].minor.yy0, &yypParser.yystack[yypParser.yytos+-1].minor.yy79)
		}
//line 2369 "pikchr.go"
		break
	case 12: /* statement ::= DEFINE ID CODEBLOCK */
//line 522 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-2].minor.yy104 = nil
			p.pik_add_macro(&yypParser.yystack[yypParser.yytos+-1].minor.yy0, &yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2374 "pikchr.go"
		break
	case 13: /* rvalue ::= PLACENAME */
//line 533 "pikchr.y"
		{
			yylhsminor.yy153 = p.pik_lookup_color(&yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2379 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy153 = yylhsminor.yy153
		break
	case 14: /* pritem ::= FILL */
		fallthrough
	case 15: /* pritem ::= COLOR */
		yytestcase(yyruleno == 15)
		fallthrough
	case 16: /* pritem ::= THICKNESS */
		yytestcase(yyruleno == 16)
//line 538 "pikchr.y"
		{
			p.pik_append_num("", p.pik_value(yypParser.yystack[yypParser.yytos+0].minor.yy0.String(), nil))
		}
//line 2389 "pikchr.go"
		break
	case 17: /* pritem ::= rvalue */
//line 541 "pikchr.y"
		{
			p.pik_append_num("", yypParser.yystack[yypParser.yytos+0].minor.yy153)
		}
//line 2394 "pikchr.go"
		break
	case 18: /* pritem ::= STRING */
//line 542 "pikchr.y"
		{
			p.pik_append_text(string(yypParser.yystack[yypParser.yytos+0].minor.yy0.z[1:yypParser.yystack[yypParser.yytos+0].minor.yy0.n-1]), 0)
		}
//line 2399 "pikchr.go"
		break
	case 19: /* prsep ::= COMMA */
//line 543 "pikchr.y"
		{
			p.pik_append(" ")
		}
//line 2404 "pikchr.go"
		break
	case 20: /* unnamed_statement ::= basetype attribute_list */
//line 546 "pikchr.y"
		{
			yylhsminor.yy104 = yypParser.yystack[yypParser.yytos+-1].minor.yy104
			p.pik_after_adding_attributes(yylhsminor.yy104)
		}
//line 2409 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-1].minor.yy104 = yylhsminor.yy104
		break
	case 21: /* basetype ::= CLASSNAME */
//line 548 "pikchr.y"
		{
			yylhsminor.yy104 = p.pik_elem_new(&yypParser.yystack[yypParser.yytos+0].minor.yy0, nil, nil)
		}
//line 2415 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy104 = yylhsminor.yy104
		break
	case 22: /* basetype ::= STRING textposition */
//line 550 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-1].minor.yy0.eCode = int16(yypParser.yystack[yypParser.yytos+0].minor.yy112)
			yylhsminor.yy104 = p.pik_elem_new(nil, &yypParser.yystack[yypParser.yytos+-1].minor.yy0, nil)
		}
//line 2421 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-1].minor.yy104 = yylhsminor.yy104
		break
	case 23: /* basetype ::= LB savelist statement_list RB */
//line 552 "pikchr.y"
		{
			p.list = yypParser.yystack[yypParser.yytos+-2].minor.yy186
			yypParser.yystack[yypParser.yytos+-3].minor.yy104 = p.pik_elem_new(nil, nil, yypParser.yystack[yypParser.yytos+-1].minor.yy186)
			if yypParser.yystack[yypParser.yytos+-3].minor.yy104 != nil {
				yypParser.yystack[yypParser.yytos+-3].minor.yy104.errTok = yypParser.yystack[yypParser.yytos+0].minor.yy0
			}
		}
//line 2427 "pikchr.go"
		break
	case 24: /* savelist ::= */
//line 557 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+1].minor.yy186 = p.list
			p.list = nil
		}
//line 2432 "pikchr.go"
		break
	case 25: /* relexpr ::= expr */
//line 564 "pikchr.y"
		{
			yylhsminor.yy10.rAbs = yypParser.yystack[yypParser.yytos+0].minor.yy153
			yylhsminor.yy10.rRel = 0
		}
//line 2437 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy10 = yylhsminor.yy10
		break
	case 26: /* relexpr ::= expr PERCENT */
//line 565 "pikchr.y"
		{
			yylhsminor.yy10.rAbs = 0
			yylhsminor.yy10.rRel = yypParser.yystack[yypParser.yytos+-1].minor.yy153 / 100
		}
//line 2443 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-1].minor.yy10 = yylhsminor.yy10
		break
	case 27: /* optrelexpr ::= */
//line 567 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+1].minor.yy10.rAbs = 0
			yypParser.yystack[yypParser.yytos+1].minor.yy10.rRel = 1.0
		}
//line 2449 "pikchr.go"
		break
	case 28: /* attribute_list ::= relexpr alist */
//line 569 "pikchr.y"
		{
			p.pik_add_direction(nil, &yypParser.yystack[yypParser.yytos+-1].minor.yy10)
		}
//line 2454 "pikchr.go"
		break
	case 29: /* attribute ::= numproperty relexpr */
//line 573 "pikchr.y"
		{
			p.pik_set_numprop(&yypParser.yystack[yypParser.yytos+-1].minor.yy0, &yypParser.yystack[yypParser.yytos+0].minor.yy10)
		}
//line 2459 "pikchr.go"
		break
	case 30: /* attribute ::= dashproperty expr */
//line 574 "pikchr.y"
		{
			p.pik_set_dashed(&yypParser.yystack[yypParser.yytos+-1].minor.yy0, &yypParser.yystack[yypParser.yytos+0].minor.yy153)
		}
//line 2464 "pikchr.go"
		break
	case 31: /* attribute ::= dashproperty */
//line 575 "pikchr.y"
		{
			p.pik_set_dashed(&yypParser.yystack[yypParser.yytos+0].minor.yy0, nil)
		}
//line 2469 "pikchr.go"
		break
	case 32: /* attribute ::= colorproperty rvalue */
//line 576 "pikchr.y"
		{
			p.pik_set_clrprop(&yypParser.yystack[yypParser.yytos+-1].minor.yy0, yypParser.yystack[yypParser.yytos+0].minor.yy153)
		}
//line 2474 "pikchr.go"
		break
	case 33: /* attribute ::= go direction optrelexpr */
//line 577 "pikchr.y"
		{
			p.pik_add_direction(&yypParser.yystack[yypParser.yytos+-1].minor.yy0, &yypParser.yystack[yypParser.yytos+0].minor.yy10)
		}
//line 2479 "pikchr.go"
		break
	case 34: /* attribute ::= go direction even position */
//line 578 "pikchr.y"
		{
			p.pik_evenwith(&yypParser.yystack[yypParser.yytos+-2].minor.yy0, &yypParser.yystack[yypParser.yytos+0].minor.yy79)
		}
//line 2484 "pikchr.go"
		break
	case 35: /* attribute ::= CLOSE */
//line 579 "pikchr.y"
		{
			p.pik_close_path(&yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2489 "pikchr.go"
		break
	case 36: /* attribute ::= CHOP */
//line 580 "pikchr.y"
		{
			p.cur.bChop = true
		}
//line 2494 "pikchr.go"
		break
	case 37: /* attribute ::= FROM position */
//line 581 "pikchr.y"
		{
			p.pik_set_from(p.cur, &yypParser.yystack[yypParser.yytos+-1].minor.yy0, &yypParser.yystack[yypParser.yytos+0].minor.yy79)
		}
//line 2499 "pikchr.go"
		break
	case 38: /* attribute ::= TO position */
//line 582 "pikchr.y"
		{
			p.pik_add_to(p.cur, &yypParser.yystack[yypParser.yytos+-1].minor.yy0, &yypParser.yystack[yypParser.yytos+0].minor.yy79)
		}
//line 2504 "pikchr.go"
		break
	case 39: /* attribute ::= THEN */
//line 583 "pikchr.y"
		{
			p.pik_then(&yypParser.yystack[yypParser.yytos+0].minor.yy0, p.cur)
		}
//line 2509 "pikchr.go"
		break
	case 40: /* attribute ::= THEN optrelexpr HEADING expr */
		fallthrough
	case 42: /* attribute ::= GO optrelexpr HEADING expr */
		yytestcase(yyruleno == 42)
//line 585 "pikchr.y"
		{
			p.pik_move_hdg(&yypParser.yystack[yypParser.yytos+-2].minor.yy10, &yypParser.yystack[yypParser.yytos+-1].minor.yy0, yypParser.yystack[yypParser.yytos+0].minor.yy153, nil, &yypParser.yystack[yypParser.yytos+-3].minor.yy0)
		}
//line 2516 "pikchr.go"
		break
	case 41: /* attribute ::= THEN optrelexpr EDGEPT */
		fallthrough
	case 43: /* attribute ::= GO optrelexpr EDGEPT */
		yytestcase(yyruleno == 43)
//line 586 "pikchr.y"
		{
			p.pik_move_hdg(&yypParser.yystack[yypParser.yytos+-1].minor.yy10, nil, 0, &yypParser.yystack[yypParser.yytos+0].minor.yy0, &yypParser.yystack[yypParser.yytos+-2].minor.yy0)
		}
//line 2523 "pikchr.go"
		break
	case 44: /* attribute ::= AT position */
//line 591 "pikchr.y"
		{
			p.pik_set_at(nil, &yypParser.yystack[yypParser.yytos+0].minor.yy79, &yypParser.yystack[yypParser.yytos+-1].minor.yy0)
		}
//line 2528 "pikchr.go"
		break
	case 45: /* attribute ::= SAME */
//line 593 "pikchr.y"
		{
			p.pik_same(nil, &yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2533 "pikchr.go"
		break
	case 46: /* attribute ::= SAME AS object */
//line 594 "pikchr.y"
		{
			p.pik_same(yypParser.yystack[yypParser.yytos+0].minor.yy104, &yypParser.yystack[yypParser.yytos+-2].minor.yy0)
		}
//line 2538 "pikchr.go"
		break
	case 47: /* attribute ::= STRING textposition */
//line 595 "pikchr.y"
		{
			p.pik_add_txt(&yypParser.yystack[yypParser.yytos+-1].minor.yy0, int16(yypParser.yystack[yypParser.yytos+0].minor.yy112))
		}
//line 2543 "pikchr.go"
		break
	case 48: /* attribute ::= FIT */
//line 596 "pikchr.y"
		{
			p.pik_size_to_fit(&yypParser.yystack[yypParser.yytos+0].minor.yy0, 3)
		}
//line 2548 "pikchr.go"
		break
	case 49: /* attribute ::= BEHIND object */
//line 597 "pikchr.y"
		{
			p.pik_behind(yypParser.yystack[yypParser.yytos+0].minor.yy104)
		}
//line 2553 "pikchr.go"
		break
	case 50: /* withclause ::= DOT_E edge AT position */
		fallthrough
	case 51: /* withclause ::= edge AT position */
		yytestcase(yyruleno == 51)
//line 605 "pikchr.y"
		{
			p.pik_set_at(&yypParser.yystack[yypParser.yytos+-2].minor.yy0, &yypParser.yystack[yypParser.yytos+0].minor.yy79, &yypParser.yystack[yypParser.yytos+-1].minor.yy0)
		}
//line 2560 "pikchr.go"
		break
	case 52: /* numproperty ::= HEIGHT|WIDTH|RADIUS|DIAMETER|THICKNESS */
//line 609 "pikchr.y"
		{
			yylhsminor.yy0 = yypParser.yystack[yypParser.yytos+0].minor.yy0
		}
//line 2565 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy0 = yylhsminor.yy0
		break
	case 53: /* boolproperty ::= CW */
//line 620 "pikchr.y"
		{
			p.cur.cw = true
		}
//line 2571 "pikchr.go"
		break
	case 54: /* boolproperty ::= CCW */
//line 621 "pikchr.y"
		{
			p.cur.cw = false
		}
//line 2576 "pikchr.go"
		break
	case 55: /* boolproperty ::= LARROW */
//line 622 "pikchr.y"
		{
			p.cur.larrow = true
			p.cur.rarrow = false
		}
//line 2581 "pikchr.go"
		break
	case 56: /* boolproperty ::= RARROW */
//line 623 "pikchr.y"
		{
			p.cur.larrow = false
			p.cur.rarrow = true
		}
//line 2586 "pikchr.go"
		break
	case 57: /* boolproperty ::= LRARROW */
//line 624 "pikchr.y"
		{
			p.cur.larrow = true
			p.cur.rarrow = true
		}
//line 2591 "pikchr.go"
		break
	case 58: /* boolproperty ::= INVIS */
//line 625 "pikchr.y"
		{
			p.cur.sw = 0.0
		}
//line 2596 "pikchr.go"
		break
	case 59: /* boolproperty ::= THICK */
//line 626 "pikchr.y"
		{
			p.cur.sw *= 1.5
		}
//line 2601 "pikchr.go"
		break
	case 60: /* boolproperty ::= THIN */
//line 627 "pikchr.y"
		{
			p.cur.sw *= 0.67
		}
//line 2606 "pikchr.go"
		break
	case 61: /* boolproperty ::= SOLID */
//line 628 "pikchr.y"
		{
			p.cur.sw = p.pik_value("thickness", nil)
			p.cur.dotted = 0.0
			p.cur.dashed = 0.0
		}
//line 2612 "pikchr.go"
		break
	case 62: /* textposition ::= */
//line 631 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+1].minor.yy112 = 0
		}
//line 2617 "pikchr.go"
		break
	case 63: /* textposition ::= textposition CENTER|LJUST|RJUST|ABOVE|BELOW|ITALIC|BOLD|ALIGNED|BIG|SMALL */
//line 634 "pikchr.y"
		{
			yylhsminor.yy112 = pik_text_position(yypParser.yystack[yypParser.yytos+-1].minor.yy112, &yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2622 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-1].minor.yy112 = yylhsminor.yy112
		break
	case 64: /* position ::= expr COMMA expr */
//line 637 "pikchr.y"
		{
			yylhsminor.yy79.x = yypParser.yystack[yypParser.yytos+-2].minor.yy153
			yylhsminor.yy79.y = yypParser.yystack[yypParser.yytos+0].minor.yy153
		}
//line 2628 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy79 = yylhsminor.yy79
		break
	case 65: /* position ::= place PLUS expr COMMA expr */
//line 639 "pikchr.y"
		{
			yylhsminor.yy79.x = yypParser.yystack[yypParser.yytos+-4].minor.yy79.x + yypParser.yystack[yypParser.yytos+-2].minor.yy153
			yylhsminor.yy79.y = yypParser.yystack[yypParser.yytos+-4].minor.yy79.y + yypParser.yystack[yypParser.yytos+0].minor.yy153
		}
//line 2634 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-4].minor.yy79 = yylhsminor.yy79
		break
	case 66: /* position ::= place MINUS expr COMMA expr */
//line 640 "pikchr.y"
		{
			yylhsminor.yy79.x = yypParser.yystack[yypParser.yytos+-4].minor.yy79.x - yypParser.yystack[yypParser.yytos+-2].minor.yy153
			yylhsminor.yy79.y = yypParser.yystack[yypParser.yytos+-4].minor.yy79.y - yypParser.yystack[yypParser.yytos+0].minor.yy153
		}
//line 2640 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-4].minor.yy79 = yylhsminor.yy79
		break
	case 67: /* position ::= place PLUS LP expr COMMA expr RP */
//line 642 "pikchr.y"
		{
			yylhsminor.yy79.x = yypParser.yystack[yypParser.yytos+-6].minor.yy79.x + yypParser.yystack[yypParser.yytos+-3].minor.yy153
			yylhsminor.yy79.y = yypParser.yystack[yypParser.yytos+-6].minor.yy79.y + yypParser.yystack[yypParser.yytos+-1].minor.yy153
		}
//line 2646 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-6].minor.yy79 = yylhsminor.yy79
		break
	case 68: /* position ::= place MINUS LP expr COMMA expr RP */
//line 644 "pikchr.y"
		{
			yylhsminor.yy79.x = yypParser.yystack[yypParser.yytos+-6].minor.yy79.x - yypParser.yystack[yypParser.yytos+-3].minor.yy153
			yylhsminor.yy79.y = yypParser.yystack[yypParser.yytos+-6].minor.yy79.y - yypParser.yystack[yypParser.yytos+-1].minor.yy153
		}
//line 2652 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-6].minor.yy79 = yylhsminor.yy79
		break
	case 69: /* position ::= LP position COMMA position RP */
//line 645 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-4].minor.yy79.x = yypParser.yystack[yypParser.yytos+-3].minor.yy79.x
			yypParser.yystack[yypParser.yytos+-4].minor.yy79.y = yypParser.yystack[yypParser.yytos+-1].minor.yy79.y
		}
//line 2658 "pikchr.go"
		break
	case 70: /* position ::= LP position RP */
//line 646 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-2].minor.yy79 = yypParser.yystack[yypParser.yytos+-1].minor.yy79
		}
//line 2663 "pikchr.go"
		break
	case 71: /* position ::= expr between position AND position */
//line 648 "pikchr.y"
		{
			yylhsminor.yy79 = pik_position_between(yypParser.yystack[yypParser.yytos+-4].minor.yy153, yypParser.yystack[yypParser.yytos+-2].minor.yy79, yypParser.yystack[yypParser.yytos+0].minor.yy79)
		}
//line 2668 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-4].minor.yy79 = yylhsminor.yy79
		break
	case 72: /* position ::= expr LT position COMMA position GT */
//line 650 "pikchr.y"
		{
			yylhsminor.yy79 = pik_position_between(yypParser.yystack[yypParser.yytos+-5].minor.yy153, yypParser.yystack[yypParser.yytos+-3].minor.yy79, yypParser.yystack[yypParser.yytos+-1].minor.yy79)
		}
//line 2674 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-5].minor.yy79 = yylhsminor.yy79
		break
	case 73: /* position ::= expr ABOVE position */
//line 651 "pikchr.y"
		{
			yylhsminor.yy79 = yypParser.yystack[yypParser.yytos+0].minor.yy79
			yylhsminor.yy79.y += yypParser.yystack[yypParser.yytos+-2].minor.yy153
		}
//line 2680 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy79 = yylhsminor.yy79
		break
	case 74: /* position ::= expr BELOW position */
//line 652 "pikchr.y"
		{
			yylhsminor.yy79 = yypParser.yystack[yypParser.yytos+0].minor.yy79
			yylhsminor.yy79.y -= yypParser.yystack[yypParser.yytos+-2].minor.yy153
		}
//line 2686 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy79 = yylhsminor.yy79
		break
	case 75: /* position ::= expr LEFT OF position */
//line 653 "pikchr.y"
		{
			yylhsminor.yy79 = yypParser.yystack[yypParser.yytos+0].minor.yy79
			yylhsminor.yy79.x -= yypParser.yystack[yypParser.yytos+-3].minor.yy153
		}
//line 2692 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-3].minor.yy79 = yylhsminor.yy79
		break
	case 76: /* position ::= expr RIGHT OF position */
//line 654 "pikchr.y"
		{
			yylhsminor.yy79 = yypParser.yystack[yypParser.yytos+0].minor.yy79
			yylhsminor.yy79.x += yypParser.yystack[yypParser.yytos+-3].minor.yy153
		}
//line 2698 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-3].minor.yy79 = yylhsminor.yy79
		break
	case 77: /* position ::= expr ON HEADING EDGEPT OF position */
//line 656 "pikchr.y"
		{
			yylhsminor.yy79 = pik_position_at_hdg(yypParser.yystack[yypParser.yytos+-5].minor.yy153, &yypParser.yystack[yypParser.yytos+-2].minor.yy0, yypParser.yystack[yypParser.yytos+0].minor.yy79)
		}
//line 2704 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-5].minor.yy79 = yylhsminor.yy79
		break
	case 78: /* position ::= expr HEADING EDGEPT OF position */
//line 658 "pikchr.y"
		{
			yylhsminor.yy79 = pik_position_at_hdg(yypParser.yystack[yypParser.yytos+-4].minor.yy153, &yypParser.yystack[yypParser.yytos+-2].minor.yy0, yypParser.yystack[yypParser.yytos+0].minor.yy79)
		}
//line 2710 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-4].minor.yy79 = yylhsminor.yy79
		break
	case 79: /* position ::= expr EDGEPT OF position */
//line 660 "pikchr.y"
		{
			yylhsminor.yy79 = pik_position_at_hdg(yypParser.yystack[yypParser.yytos+-3].minor.yy153, &yypParser.yystack[yypParser.yytos+-2].minor.yy0, yypParser.yystack[yypParser.yytos+0].minor.yy79)
		}
//line 2716 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-3].minor.yy79 = yylhsminor.yy79
		break
	case 80: /* position ::= expr ON HEADING expr FROM position */
//line 662 "pikchr.y"
		{
			yylhsminor.yy79 = pik_position_at_angle(yypParser.yystack[yypParser.yytos+-5].minor.yy153, yypParser.yystack[yypParser.yytos+-2].minor.yy153, yypParser.yystack[yypParser.yytos+0].minor.yy79)
		}
//line 2722 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-5].minor.yy79 = yylhsminor.yy79
		break
	case 81: /* position ::= expr HEADING expr FROM position */
//line 664 "pikchr.y"
		{
			yylhsminor.yy79 = pik_position_at_angle(yypParser.yystack[yypParser.yytos+-4].minor.yy153, yypParser.yystack[yypParser.yytos+-2].minor.yy153, yypParser.yystack[yypParser.yytos+0].minor.yy79)
		}
//line 2728 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-4].minor.yy79 = yylhsminor.yy79
		break
	case 82: /* place ::= edge OF object */
//line 676 "pikchr.y"
		{
			yylhsminor.yy79 = p.pik_place_of_elem(yypParser.yystack[yypParser.yytos+0].minor.yy104, &yypParser.yystack[yypParser.yytos+-2].minor.yy0)
		}
//line 2734 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy79 = yylhsminor.yy79
		break
	case 83: /* place2 ::= object */
//line 677 "pikchr.y"
		{
			yylhsminor.yy79 = p.pik_place_of_elem(yypParser.yystack[yypParser.yytos+0].minor.yy104, nil)
		}
//line 2740 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy79 = yylhsminor.yy79
		break
	case 84: /* place2 ::= object DOT_E edge */
//line 678 "pikchr.y"
		{
			yylhsminor.yy79 = p.pik_place_of_elem(yypParser.yystack[yypParser.yytos+-2].minor.yy104, &yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2746 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy79 = yylhsminor.yy79
		break
	case 85: /* place2 ::= NTH VERTEX OF object */
//line 679 "pikchr.y"
		{
			yylhsminor.yy79 = p.pik_nth_vertex(&yypParser.yystack[yypParser.yytos+-3].minor.yy0, &yypParser.yystack[yypParser.yytos+-2].minor.yy0, yypParser.yystack[yypParser.yytos+0].minor.yy104)
		}
//line 2752 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-3].minor.yy79 = yylhsminor.yy79
		break
	case 86: /* object ::= nth */
//line 691 "pikchr.y"
		{
			yylhsminor.yy104 = p.pik_find_nth(nil, &yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2758 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy104 = yylhsminor.yy104
		break
	case 87: /* object ::= nth OF|IN object */
//line 692 "pikchr.y"
		{
			yylhsminor.yy104 = p.pik_find_nth(yypParser.yystack[yypParser.yytos+0].minor.yy104, &yypParser.yystack[yypParser.yytos+-2].minor.yy0)
		}
//line 2764 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy104 = yylhsminor.yy104
		break
	case 88: /* objectname ::= THIS */
//line 694 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+0].minor.yy104 = p.cur
		}
//line 2770 "pikchr.go"
		break
	case 89: /* objectname ::= PLACENAME */
//line 695 "pikchr.y"
		{
			yylhsminor.yy104 = p.pik_find_byname(nil, &yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2775 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy104 = yylhsminor.yy104
		break
	case 90: /* objectname ::= objectname DOT_U PLACENAME */
//line 697 "pikchr.y"
		{
			yylhsminor.yy104 = p.pik_find_byname(yypParser.yystack[yypParser.yytos+-2].minor.yy104, &yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2781 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy104 = yylhsminor.yy104
		break
	case 91: /* nth ::= NTH CLASSNAME */
//line 699 "pikchr.y"
		{
			yylhsminor.yy0 = yypParser.yystack[yypParser.yytos+0].minor.yy0
			yylhsminor.yy0.eCode = p.pik_nth_value(&yypParser.yystack[yypParser.yytos+-1].minor.yy0)
		}
//line 2787 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-1].minor.yy0 = yylhsminor.yy0
		break
	case 92: /* nth ::= NTH LAST CLASSNAME */
//line 700 "pikchr.y"
		{
			yylhsminor.yy0 = yypParser.yystack[yypParser.yytos+0].minor.yy0
			yylhsminor.yy0.eCode = -p.pik_nth_value(&yypParser.yystack[yypParser.yytos+-2].minor.yy0)
		}
//line 2793 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy0 = yylhsminor.yy0
		break
	case 93: /* nth ::= LAST CLASSNAME */
//line 701 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-1].minor.yy0 = yypParser.yystack[yypParser.yytos+0].minor.yy0
			yypParser.yystack[yypParser.yytos+-1].minor.yy0.eCode = -1
		}
//line 2799 "pikchr.go"
		break
	case 94: /* nth ::= LAST */
//line 702 "pikchr.y"
		{
			yylhsminor.yy0 = yypParser.yystack[yypParser.yytos+0].minor.yy0
			yylhsminor.yy0.eCode = -1
		}
//line 2804 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy0 = yylhsminor.yy0
		break
	case 95: /* nth ::= NTH LB RB */
//line 703 "pikchr.y"
		{
			yylhsminor.yy0 = yypParser.yystack[yypParser.yytos+-1].minor.yy0
			yylhsminor.yy0.eCode = p.pik_nth_value(&yypParser.yystack[yypParser.yytos+-2].minor.yy0)
		}
//line 2810 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy0 = yylhsminor.yy0
		break
	case 96: /* nth ::= NTH LAST LB RB */
//line 704 "pikchr.y"
		{
			yylhsminor.yy0 = yypParser.yystack[yypParser.yytos+-1].minor.yy0
			yylhsminor.yy0.eCode = -p.pik_nth_value(&yypParser.yystack[yypParser.yytos+-3].minor.yy0)
		}
//line 2816 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-3].minor.yy0 = yylhsminor.yy0
		break
	case 97: /* nth ::= LAST LB RB */
//line 705 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-2].minor.yy0 = yypParser.yystack[yypParser.yytos+-1].minor.yy0
			yypParser.yystack[yypParser.yytos+-2].minor.yy0.eCode = -1
		}
//line 2822 "pikchr.go"
		break
	case 98: /* expr ::= expr PLUS expr */
//line 707 "pikchr.y"
		{
			yylhsminor.yy153 = yypParser.yystack[yypParser.yytos+-2].minor.yy153 + yypParser.yystack[yypParser.yytos+0].minor.yy153
		}
//line 2827 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy153 = yylhsminor.yy153
		break
	case 99: /* expr ::= expr MINUS expr */
//line 708 "pikchr.y"
		{
			yylhsminor.yy153 = yypParser.yystack[yypParser.yytos+-2].minor.yy153 - yypParser.yystack[yypParser.yytos+0].minor.yy153
		}
//line 2833 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy153 = yylhsminor.yy153
		break
	case 100: /* expr ::= expr STAR expr */
//line 709 "pikchr.y"
		{
			yylhsminor.yy153 = yypParser.yystack[yypParser.yytos+-2].minor.yy153 * yypParser.yystack[yypParser.yytos+0].minor.yy153
		}
//line 2839 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy153 = yylhsminor.yy153
		break
	case 101: /* expr ::= expr SLASH expr */
//line 710 "pikchr.y"
		{
			if yypParser.yystack[yypParser.yytos+0].minor.yy153 == 0.0 {
				p.pik_error(&yypParser.yystack[yypParser.yytos+-1].minor.yy0, "division by zero")
				yylhsminor.yy153 = 0.0
			} else {
				yylhsminor.yy153 = yypParser.yystack[yypParser.yytos+-2].minor.yy153 / yypParser.yystack[yypParser.yytos+0].minor.yy153
			}
		}
//line 2847 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy153 = yylhsminor.yy153
		break
	case 102: /* expr ::= MINUS expr */
//line 713 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-1].minor.yy153 = -yypParser.yystack[yypParser.yytos+0].minor.yy153
		}
//line 2853 "pikchr.go"
		break
	case 103: /* expr ::= PLUS expr */
//line 714 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-1].minor.yy153 = yypParser.yystack[yypParser.yytos+0].minor.yy153
		}
//line 2858 "pikchr.go"
		break
	case 104: /* expr ::= LP expr RP */
//line 715 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-2].minor.yy153 = yypParser.yystack[yypParser.yytos+-1].minor.yy153
		}
//line 2863 "pikchr.go"
		break
	case 105: /* expr ::= LP FILL|COLOR|THICKNESS RP */
//line 716 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-2].minor.yy153 = p.pik_get_var(&yypParser.yystack[yypParser.yytos+-1].minor.yy0)
		}
//line 2868 "pikchr.go"
		break
	case 106: /* expr ::= NUMBER */
//line 717 "pikchr.y"
		{
			yylhsminor.yy153 = pik_atof(&yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2873 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy153 = yylhsminor.yy153
		break
	case 107: /* expr ::= ID */
//line 718 "pikchr.y"
		{
			yylhsminor.yy153 = p.pik_get_var(&yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2879 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy153 = yylhsminor.yy153
		break
	case 108: /* expr ::= FUNC1 LP expr RP */
//line 719 "pikchr.y"
		{
			yylhsminor.yy153 = p.pik_func(&yypParser.yystack[yypParser.yytos+-3].minor.yy0, yypParser.yystack[yypParser.yytos+-1].minor.yy153, 0.0)
		}
//line 2885 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-3].minor.yy153 = yylhsminor.yy153
		break
	case 109: /* expr ::= FUNC2 LP expr COMMA expr RP */
//line 720 "pikchr.y"
		{
			yylhsminor.yy153 = p.pik_func(&yypParser.yystack[yypParser.yytos+-5].minor.yy0, yypParser.yystack[yypParser.yytos+-3].minor.yy153, yypParser.yystack[yypParser.yytos+-1].minor.yy153)
		}
//line 2891 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-5].minor.yy153 = yylhsminor.yy153
		break
	case 110: /* expr ::= DIST LP position COMMA position RP */
//line 721 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-5].minor.yy153 = pik_dist(&yypParser.yystack[yypParser.yytos+-3].minor.yy79, &yypParser.yystack[yypParser.yytos+-1].minor.yy79)
		}
//line 2897 "pikchr.go"
		break
	case 111: /* expr ::= place2 DOT_XY X */
//line 722 "pikchr.y"
		{
			yylhsminor.yy153 = yypParser.yystack[yypParser.yytos+-2].minor.yy79.x
		}
//line 2902 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy153 = yylhsminor.yy153
		break
	case 112: /* expr ::= place2 DOT_XY Y */
//line 723 "pikchr.y"
		{
			yylhsminor.yy153 = yypParser.yystack[yypParser.yytos+-2].minor.yy79.y
		}
//line 2908 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy153 = yylhsminor.yy153
		break
	case 113: /* expr ::= object DOT_L numproperty */
		fallthrough
	case 114: /* expr ::= object DOT_L dashproperty */
		yytestcase(yyruleno == 114)
		fallthrough
	case 115: /* expr ::= object DOT_L colorproperty */
		yytestcase(yyruleno == 115)
//line 724 "pikchr.y"
		{
			yylhsminor.yy153 = pik_property_of(yypParser.yystack[yypParser.yytos+-2].minor.yy104, &yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2918 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy153 = yylhsminor.yy153
		break
	default:
		/* (116) lvalue ::= ID */ yytestcase(yyruleno == 116)
		/* (117) lvalue ::= FILL */ yytestcase(yyruleno == 117)
		/* (118) lvalue ::= COLOR */ yytestcase(yyruleno == 118)
		/* (119) lvalue ::= THICKNESS */ yytestcase(yyruleno == 119)







|



|


|



|



|



|



|



|


|




|



|




|



|




|



|







|



|



|



|




|


|



|


|



|


|




|


|



|









|



|


|



|


|



|


|



|


|




|



|



|



|




|



|







|


|




|


|




|



|




|



|




|


|



|


|



|


|



|


|



|


|



|


|



|


|



|


|



|


|



|


|



|


|



|


|



|





|



|





|



|


|



|


|



|


|



|


|



|


|



|


|



|





|



|


|



|



|



|


|



|


|




|


|




|


|




|


|



|


|



|


|



|


|





|


|



|


|



|



|




|



|




|



|




|



|




|



|




|



|




|


|



|


|



|



|



|



|




|



|




|



|




|



|




|



|



|



|



|



|



|



|



|



|



|



|



|



|



|



|



|



|



|



|



|



|



|



|



|


|



|



|



|



|




|



|




|



|




|


|




|



|




|



|




|



|




|


|



|



|



|



|



|



|








|



|



|


|



|


|



|


|



|


|



|



|



|



|



|



|



|



|



|


|



|



|



|









|



|







2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
	 **  #line <lineno> <grammarfile>
	 **     { ... }           // User supplied code
	 **  #line <lineno> <thisfile>
	 **     break;
	 */
	/********** Begin reduce actions **********************************************/
	case 0: /* document ::= statement_list */
//line 492 "pikchr.y"
		{
			p.pik_render(yypParser.yystack[yypParser.yytos+0].minor.yy186)
		}
//line 2301 "pikchr.go"
		break
	case 1: /* statement_list ::= statement */
//line 495 "pikchr.y"
		{
			yylhsminor.yy186 = p.pik_elist_append(nil, yypParser.yystack[yypParser.yytos+0].minor.yy104)
		}
//line 2306 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy186 = yylhsminor.yy186
		break
	case 2: /* statement_list ::= statement_list EOL statement */
//line 497 "pikchr.y"
		{
			yylhsminor.yy186 = p.pik_elist_append(yypParser.yystack[yypParser.yytos+-2].minor.yy186, yypParser.yystack[yypParser.yytos+0].minor.yy104)
		}
//line 2312 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy186 = yylhsminor.yy186
		break
	case 3: /* statement ::= */
//line 500 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+1].minor.yy104 = nil
		}
//line 2318 "pikchr.go"
		break
	case 4: /* statement ::= direction */
//line 501 "pikchr.y"
		{
			p.pik_set_direction(uint8(yypParser.yystack[yypParser.yytos+0].minor.yy0.eCode))
			yylhsminor.yy104 = nil
		}
//line 2323 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy104 = yylhsminor.yy104
		break
	case 5: /* statement ::= lvalue ASSIGN rvalue */
//line 502 "pikchr.y"
		{
			p.pik_set_var(&yypParser.yystack[yypParser.yytos+-2].minor.yy0, yypParser.yystack[yypParser.yytos+0].minor.yy153, &yypParser.yystack[yypParser.yytos+-1].minor.yy0)
			yylhsminor.yy104 = nil
		}
//line 2329 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy104 = yylhsminor.yy104
		break
	case 6: /* statement ::= PLACENAME COLON unnamed_statement */
//line 504 "pikchr.y"
		{
			yylhsminor.yy104 = yypParser.yystack[yypParser.yytos+0].minor.yy104
			p.pik_elem_setname(yypParser.yystack[yypParser.yytos+0].minor.yy104, &yypParser.yystack[yypParser.yytos+-2].minor.yy0)
		}
//line 2335 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy104 = yylhsminor.yy104
		break
	case 7: /* statement ::= PLACENAME COLON position */
//line 506 "pikchr.y"
		{
			yylhsminor.yy104 = p.pik_elem_new(nil, nil, nil)
			if yylhsminor.yy104 != nil {
				yylhsminor.yy104.ptAt = yypParser.yystack[yypParser.yytos+0].minor.yy79
				p.pik_elem_setname(yylhsminor.yy104, &yypParser.yystack[yypParser.yytos+-2].minor.yy0)
			}
		}
//line 2342 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy104 = yylhsminor.yy104
		break
	case 8: /* statement ::= unnamed_statement */
//line 508 "pikchr.y"
		{
			yylhsminor.yy104 = yypParser.yystack[yypParser.yytos+0].minor.yy104
		}
//line 2348 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy104 = yylhsminor.yy104
		break
	case 9: /* statement ::= print prlist */
//line 509 "pikchr.y"
		{
			p.pik_append("<br>\n")
			yypParser.yystack[yypParser.yytos+-1].minor.yy104 = nil
		}
//line 2354 "pikchr.go"
		break
	case 10: /* statement ::= ASSERT LP expr EQ expr RP */
//line 514 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-5].minor.yy104 = p.pik_assert(yypParser.yystack[yypParser.yytos+-3].minor.yy153, &yypParser.yystack[yypParser.yytos+-2].minor.yy0, yypParser.yystack[yypParser.yytos+-1].minor.yy153)
		}
//line 2359 "pikchr.go"
		break
	case 11: /* statement ::= ASSERT LP position EQ position RP */
//line 516 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-5].minor.yy104 = p.pik_position_assert(&yypParser.yystack[yypParser.yytos+-3].minor.yy79, &yypParser.yystack[yypParser.yytos+-2].minor.yy0, &yypParser.yystack[yypParser.yytos+-1].minor.yy79)
		}
//line 2364 "pikchr.go"
		break
	case 12: /* statement ::= DEFINE ID CODEBLOCK */
//line 517 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-2].minor.yy104 = nil
			p.pik_add_macro(&yypParser.yystack[yypParser.yytos+-1].minor.yy0, &yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2369 "pikchr.go"
		break
	case 13: /* rvalue ::= PLACENAME */
//line 528 "pikchr.y"
		{
			yylhsminor.yy153 = p.pik_lookup_color(&yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2374 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy153 = yylhsminor.yy153
		break
	case 14: /* pritem ::= FILL */
		fallthrough
	case 15: /* pritem ::= COLOR */
		yytestcase(yyruleno == 15)
		fallthrough
	case 16: /* pritem ::= THICKNESS */
		yytestcase(yyruleno == 16)
//line 533 "pikchr.y"
		{
			p.pik_append_num("", p.pik_value(yypParser.yystack[yypParser.yytos+0].minor.yy0.String(), nil))
		}
//line 2384 "pikchr.go"
		break
	case 17: /* pritem ::= rvalue */
//line 536 "pikchr.y"
		{
			p.pik_append_num("", yypParser.yystack[yypParser.yytos+0].minor.yy153)
		}
//line 2389 "pikchr.go"
		break
	case 18: /* pritem ::= STRING */
//line 537 "pikchr.y"
		{
			p.pik_append_text(string(yypParser.yystack[yypParser.yytos+0].minor.yy0.z[1:yypParser.yystack[yypParser.yytos+0].minor.yy0.n-1]), 0)
		}
//line 2394 "pikchr.go"
		break
	case 19: /* prsep ::= COMMA */
//line 538 "pikchr.y"
		{
			p.pik_append(" ")
		}
//line 2399 "pikchr.go"
		break
	case 20: /* unnamed_statement ::= basetype attribute_list */
//line 541 "pikchr.y"
		{
			yylhsminor.yy104 = yypParser.yystack[yypParser.yytos+-1].minor.yy104
			p.pik_after_adding_attributes(yylhsminor.yy104)
		}
//line 2404 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-1].minor.yy104 = yylhsminor.yy104
		break
	case 21: /* basetype ::= CLASSNAME */
//line 543 "pikchr.y"
		{
			yylhsminor.yy104 = p.pik_elem_new(&yypParser.yystack[yypParser.yytos+0].minor.yy0, nil, nil)
		}
//line 2410 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy104 = yylhsminor.yy104
		break
	case 22: /* basetype ::= STRING textposition */
//line 545 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-1].minor.yy0.eCode = int16(yypParser.yystack[yypParser.yytos+0].minor.yy112)
			yylhsminor.yy104 = p.pik_elem_new(nil, &yypParser.yystack[yypParser.yytos+-1].minor.yy0, nil)
		}
//line 2416 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-1].minor.yy104 = yylhsminor.yy104
		break
	case 23: /* basetype ::= LB savelist statement_list RB */
//line 547 "pikchr.y"
		{
			p.list = yypParser.yystack[yypParser.yytos+-2].minor.yy186
			yypParser.yystack[yypParser.yytos+-3].minor.yy104 = p.pik_elem_new(nil, nil, yypParser.yystack[yypParser.yytos+-1].minor.yy186)
			if yypParser.yystack[yypParser.yytos+-3].minor.yy104 != nil {
				yypParser.yystack[yypParser.yytos+-3].minor.yy104.errTok = yypParser.yystack[yypParser.yytos+0].minor.yy0
			}
		}
//line 2422 "pikchr.go"
		break
	case 24: /* savelist ::= */
//line 552 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+1].minor.yy186 = p.list
			p.list = nil
		}
//line 2427 "pikchr.go"
		break
	case 25: /* relexpr ::= expr */
//line 559 "pikchr.y"
		{
			yylhsminor.yy10.rAbs = yypParser.yystack[yypParser.yytos+0].minor.yy153
			yylhsminor.yy10.rRel = 0
		}
//line 2432 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy10 = yylhsminor.yy10
		break
	case 26: /* relexpr ::= expr PERCENT */
//line 560 "pikchr.y"
		{
			yylhsminor.yy10.rAbs = 0
			yylhsminor.yy10.rRel = yypParser.yystack[yypParser.yytos+-1].minor.yy153 / 100
		}
//line 2438 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-1].minor.yy10 = yylhsminor.yy10
		break
	case 27: /* optrelexpr ::= */
//line 562 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+1].minor.yy10.rAbs = 0
			yypParser.yystack[yypParser.yytos+1].minor.yy10.rRel = 1.0
		}
//line 2444 "pikchr.go"
		break
	case 28: /* attribute_list ::= relexpr alist */
//line 564 "pikchr.y"
		{
			p.pik_add_direction(nil, &yypParser.yystack[yypParser.yytos+-1].minor.yy10)
		}
//line 2449 "pikchr.go"
		break
	case 29: /* attribute ::= numproperty relexpr */
//line 568 "pikchr.y"
		{
			p.pik_set_numprop(&yypParser.yystack[yypParser.yytos+-1].minor.yy0, &yypParser.yystack[yypParser.yytos+0].minor.yy10)
		}
//line 2454 "pikchr.go"
		break
	case 30: /* attribute ::= dashproperty expr */
//line 569 "pikchr.y"
		{
			p.pik_set_dashed(&yypParser.yystack[yypParser.yytos+-1].minor.yy0, &yypParser.yystack[yypParser.yytos+0].minor.yy153)
		}
//line 2459 "pikchr.go"
		break
	case 31: /* attribute ::= dashproperty */
//line 570 "pikchr.y"
		{
			p.pik_set_dashed(&yypParser.yystack[yypParser.yytos+0].minor.yy0, nil)
		}
//line 2464 "pikchr.go"
		break
	case 32: /* attribute ::= colorproperty rvalue */
//line 571 "pikchr.y"
		{
			p.pik_set_clrprop(&yypParser.yystack[yypParser.yytos+-1].minor.yy0, yypParser.yystack[yypParser.yytos+0].minor.yy153)
		}
//line 2469 "pikchr.go"
		break
	case 33: /* attribute ::= go direction optrelexpr */
//line 572 "pikchr.y"
		{
			p.pik_add_direction(&yypParser.yystack[yypParser.yytos+-1].minor.yy0, &yypParser.yystack[yypParser.yytos+0].minor.yy10)
		}
//line 2474 "pikchr.go"
		break
	case 34: /* attribute ::= go direction even position */
//line 573 "pikchr.y"
		{
			p.pik_evenwith(&yypParser.yystack[yypParser.yytos+-2].minor.yy0, &yypParser.yystack[yypParser.yytos+0].minor.yy79)
		}
//line 2479 "pikchr.go"
		break
	case 35: /* attribute ::= CLOSE */
//line 574 "pikchr.y"
		{
			p.pik_close_path(&yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2484 "pikchr.go"
		break
	case 36: /* attribute ::= CHOP */
//line 575 "pikchr.y"
		{
			p.cur.bChop = true
		}
//line 2489 "pikchr.go"
		break
	case 37: /* attribute ::= FROM position */
//line 576 "pikchr.y"
		{
			p.pik_set_from(p.cur, &yypParser.yystack[yypParser.yytos+-1].minor.yy0, &yypParser.yystack[yypParser.yytos+0].minor.yy79)
		}
//line 2494 "pikchr.go"
		break
	case 38: /* attribute ::= TO position */
//line 577 "pikchr.y"
		{
			p.pik_add_to(p.cur, &yypParser.yystack[yypParser.yytos+-1].minor.yy0, &yypParser.yystack[yypParser.yytos+0].minor.yy79)
		}
//line 2499 "pikchr.go"
		break
	case 39: /* attribute ::= THEN */
//line 578 "pikchr.y"
		{
			p.pik_then(&yypParser.yystack[yypParser.yytos+0].minor.yy0, p.cur)
		}
//line 2504 "pikchr.go"
		break
	case 40: /* attribute ::= THEN optrelexpr HEADING expr */
		fallthrough
	case 42: /* attribute ::= GO optrelexpr HEADING expr */
		yytestcase(yyruleno == 42)
//line 580 "pikchr.y"
		{
			p.pik_move_hdg(&yypParser.yystack[yypParser.yytos+-2].minor.yy10, &yypParser.yystack[yypParser.yytos+-1].minor.yy0, yypParser.yystack[yypParser.yytos+0].minor.yy153, nil, &yypParser.yystack[yypParser.yytos+-3].minor.yy0)
		}
//line 2511 "pikchr.go"
		break
	case 41: /* attribute ::= THEN optrelexpr EDGEPT */
		fallthrough
	case 43: /* attribute ::= GO optrelexpr EDGEPT */
		yytestcase(yyruleno == 43)
//line 581 "pikchr.y"
		{
			p.pik_move_hdg(&yypParser.yystack[yypParser.yytos+-1].minor.yy10, nil, 0, &yypParser.yystack[yypParser.yytos+0].minor.yy0, &yypParser.yystack[yypParser.yytos+-2].minor.yy0)
		}
//line 2518 "pikchr.go"
		break
	case 44: /* attribute ::= AT position */
//line 586 "pikchr.y"
		{
			p.pik_set_at(nil, &yypParser.yystack[yypParser.yytos+0].minor.yy79, &yypParser.yystack[yypParser.yytos+-1].minor.yy0)
		}
//line 2523 "pikchr.go"
		break
	case 45: /* attribute ::= SAME */
//line 588 "pikchr.y"
		{
			p.pik_same(nil, &yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2528 "pikchr.go"
		break
	case 46: /* attribute ::= SAME AS object */
//line 589 "pikchr.y"
		{
			p.pik_same(yypParser.yystack[yypParser.yytos+0].minor.yy104, &yypParser.yystack[yypParser.yytos+-2].minor.yy0)
		}
//line 2533 "pikchr.go"
		break
	case 47: /* attribute ::= STRING textposition */
//line 590 "pikchr.y"
		{
			p.pik_add_txt(&yypParser.yystack[yypParser.yytos+-1].minor.yy0, int16(yypParser.yystack[yypParser.yytos+0].minor.yy112))
		}
//line 2538 "pikchr.go"
		break
	case 48: /* attribute ::= FIT */
//line 591 "pikchr.y"
		{
			p.pik_size_to_fit(&yypParser.yystack[yypParser.yytos+0].minor.yy0, 3)
		}
//line 2543 "pikchr.go"
		break
	case 49: /* attribute ::= BEHIND object */
//line 592 "pikchr.y"
		{
			p.pik_behind(yypParser.yystack[yypParser.yytos+0].minor.yy104)
		}
//line 2548 "pikchr.go"
		break
	case 50: /* withclause ::= DOT_E edge AT position */
		fallthrough
	case 51: /* withclause ::= edge AT position */
		yytestcase(yyruleno == 51)
//line 600 "pikchr.y"
		{
			p.pik_set_at(&yypParser.yystack[yypParser.yytos+-2].minor.yy0, &yypParser.yystack[yypParser.yytos+0].minor.yy79, &yypParser.yystack[yypParser.yytos+-1].minor.yy0)
		}
//line 2555 "pikchr.go"
		break
	case 52: /* numproperty ::= HEIGHT|WIDTH|RADIUS|DIAMETER|THICKNESS */
//line 604 "pikchr.y"
		{
			yylhsminor.yy0 = yypParser.yystack[yypParser.yytos+0].minor.yy0
		}
//line 2560 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy0 = yylhsminor.yy0
		break
	case 53: /* boolproperty ::= CW */
//line 615 "pikchr.y"
		{
			p.cur.cw = true
		}
//line 2566 "pikchr.go"
		break
	case 54: /* boolproperty ::= CCW */
//line 616 "pikchr.y"
		{
			p.cur.cw = false
		}
//line 2571 "pikchr.go"
		break
	case 55: /* boolproperty ::= LARROW */
//line 617 "pikchr.y"
		{
			p.cur.larrow = true
			p.cur.rarrow = false
		}
//line 2576 "pikchr.go"
		break
	case 56: /* boolproperty ::= RARROW */
//line 618 "pikchr.y"
		{
			p.cur.larrow = false
			p.cur.rarrow = true
		}
//line 2581 "pikchr.go"
		break
	case 57: /* boolproperty ::= LRARROW */
//line 619 "pikchr.y"
		{
			p.cur.larrow = true
			p.cur.rarrow = true
		}
//line 2586 "pikchr.go"
		break
	case 58: /* boolproperty ::= INVIS */
//line 620 "pikchr.y"
		{
			p.cur.sw = 0.0
		}
//line 2591 "pikchr.go"
		break
	case 59: /* boolproperty ::= THICK */
//line 621 "pikchr.y"
		{
			p.cur.sw *= 1.5
		}
//line 2596 "pikchr.go"
		break
	case 60: /* boolproperty ::= THIN */
//line 622 "pikchr.y"
		{
			p.cur.sw *= 0.67
		}
//line 2601 "pikchr.go"
		break
	case 61: /* boolproperty ::= SOLID */
//line 623 "pikchr.y"
		{
			p.cur.sw = p.pik_value("thickness", nil)
			p.cur.dotted = 0.0
			p.cur.dashed = 0.0
		}
//line 2607 "pikchr.go"
		break
	case 62: /* textposition ::= */
//line 626 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+1].minor.yy112 = 0
		}
//line 2612 "pikchr.go"
		break
	case 63: /* textposition ::= textposition CENTER|LJUST|RJUST|ABOVE|BELOW|ITALIC|BOLD|ALIGNED|BIG|SMALL */
//line 629 "pikchr.y"
		{
			yylhsminor.yy112 = pik_text_position(yypParser.yystack[yypParser.yytos+-1].minor.yy112, &yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2617 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-1].minor.yy112 = yylhsminor.yy112
		break
	case 64: /* position ::= expr COMMA expr */
//line 632 "pikchr.y"
		{
			yylhsminor.yy79.x = yypParser.yystack[yypParser.yytos+-2].minor.yy153
			yylhsminor.yy79.y = yypParser.yystack[yypParser.yytos+0].minor.yy153
		}
//line 2623 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy79 = yylhsminor.yy79
		break
	case 65: /* position ::= place PLUS expr COMMA expr */
//line 634 "pikchr.y"
		{
			yylhsminor.yy79.x = yypParser.yystack[yypParser.yytos+-4].minor.yy79.x + yypParser.yystack[yypParser.yytos+-2].minor.yy153
			yylhsminor.yy79.y = yypParser.yystack[yypParser.yytos+-4].minor.yy79.y + yypParser.yystack[yypParser.yytos+0].minor.yy153
		}
//line 2629 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-4].minor.yy79 = yylhsminor.yy79
		break
	case 66: /* position ::= place MINUS expr COMMA expr */
//line 635 "pikchr.y"
		{
			yylhsminor.yy79.x = yypParser.yystack[yypParser.yytos+-4].minor.yy79.x - yypParser.yystack[yypParser.yytos+-2].minor.yy153
			yylhsminor.yy79.y = yypParser.yystack[yypParser.yytos+-4].minor.yy79.y - yypParser.yystack[yypParser.yytos+0].minor.yy153
		}
//line 2635 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-4].minor.yy79 = yylhsminor.yy79
		break
	case 67: /* position ::= place PLUS LP expr COMMA expr RP */
//line 637 "pikchr.y"
		{
			yylhsminor.yy79.x = yypParser.yystack[yypParser.yytos+-6].minor.yy79.x + yypParser.yystack[yypParser.yytos+-3].minor.yy153
			yylhsminor.yy79.y = yypParser.yystack[yypParser.yytos+-6].minor.yy79.y + yypParser.yystack[yypParser.yytos+-1].minor.yy153
		}
//line 2641 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-6].minor.yy79 = yylhsminor.yy79
		break
	case 68: /* position ::= place MINUS LP expr COMMA expr RP */
//line 639 "pikchr.y"
		{
			yylhsminor.yy79.x = yypParser.yystack[yypParser.yytos+-6].minor.yy79.x - yypParser.yystack[yypParser.yytos+-3].minor.yy153
			yylhsminor.yy79.y = yypParser.yystack[yypParser.yytos+-6].minor.yy79.y - yypParser.yystack[yypParser.yytos+-1].minor.yy153
		}
//line 2647 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-6].minor.yy79 = yylhsminor.yy79
		break
	case 69: /* position ::= LP position COMMA position RP */
//line 640 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-4].minor.yy79.x = yypParser.yystack[yypParser.yytos+-3].minor.yy79.x
			yypParser.yystack[yypParser.yytos+-4].minor.yy79.y = yypParser.yystack[yypParser.yytos+-1].minor.yy79.y
		}
//line 2653 "pikchr.go"
		break
	case 70: /* position ::= LP position RP */
//line 641 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-2].minor.yy79 = yypParser.yystack[yypParser.yytos+-1].minor.yy79
		}
//line 2658 "pikchr.go"
		break
	case 71: /* position ::= expr between position AND position */
//line 643 "pikchr.y"
		{
			yylhsminor.yy79 = pik_position_between(yypParser.yystack[yypParser.yytos+-4].minor.yy153, yypParser.yystack[yypParser.yytos+-2].minor.yy79, yypParser.yystack[yypParser.yytos+0].minor.yy79)
		}
//line 2663 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-4].minor.yy79 = yylhsminor.yy79
		break
	case 72: /* position ::= expr LT position COMMA position GT */
//line 645 "pikchr.y"
		{
			yylhsminor.yy79 = pik_position_between(yypParser.yystack[yypParser.yytos+-5].minor.yy153, yypParser.yystack[yypParser.yytos+-3].minor.yy79, yypParser.yystack[yypParser.yytos+-1].minor.yy79)
		}
//line 2669 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-5].minor.yy79 = yylhsminor.yy79
		break
	case 73: /* position ::= expr ABOVE position */
//line 646 "pikchr.y"
		{
			yylhsminor.yy79 = yypParser.yystack[yypParser.yytos+0].minor.yy79
			yylhsminor.yy79.y += yypParser.yystack[yypParser.yytos+-2].minor.yy153
		}
//line 2675 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy79 = yylhsminor.yy79
		break
	case 74: /* position ::= expr BELOW position */
//line 647 "pikchr.y"
		{
			yylhsminor.yy79 = yypParser.yystack[yypParser.yytos+0].minor.yy79
			yylhsminor.yy79.y -= yypParser.yystack[yypParser.yytos+-2].minor.yy153
		}
//line 2681 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy79 = yylhsminor.yy79
		break
	case 75: /* position ::= expr LEFT OF position */
//line 648 "pikchr.y"
		{
			yylhsminor.yy79 = yypParser.yystack[yypParser.yytos+0].minor.yy79
			yylhsminor.yy79.x -= yypParser.yystack[yypParser.yytos+-3].minor.yy153
		}
//line 2687 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-3].minor.yy79 = yylhsminor.yy79
		break
	case 76: /* position ::= expr RIGHT OF position */
//line 649 "pikchr.y"
		{
			yylhsminor.yy79 = yypParser.yystack[yypParser.yytos+0].minor.yy79
			yylhsminor.yy79.x += yypParser.yystack[yypParser.yytos+-3].minor.yy153
		}
//line 2693 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-3].minor.yy79 = yylhsminor.yy79
		break
	case 77: /* position ::= expr ON HEADING EDGEPT OF position */
//line 651 "pikchr.y"
		{
			yylhsminor.yy79 = pik_position_at_hdg(yypParser.yystack[yypParser.yytos+-5].minor.yy153, &yypParser.yystack[yypParser.yytos+-2].minor.yy0, yypParser.yystack[yypParser.yytos+0].minor.yy79)
		}
//line 2699 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-5].minor.yy79 = yylhsminor.yy79
		break
	case 78: /* position ::= expr HEADING EDGEPT OF position */
//line 653 "pikchr.y"
		{
			yylhsminor.yy79 = pik_position_at_hdg(yypParser.yystack[yypParser.yytos+-4].minor.yy153, &yypParser.yystack[yypParser.yytos+-2].minor.yy0, yypParser.yystack[yypParser.yytos+0].minor.yy79)
		}
//line 2705 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-4].minor.yy79 = yylhsminor.yy79
		break
	case 79: /* position ::= expr EDGEPT OF position */
//line 655 "pikchr.y"
		{
			yylhsminor.yy79 = pik_position_at_hdg(yypParser.yystack[yypParser.yytos+-3].minor.yy153, &yypParser.yystack[yypParser.yytos+-2].minor.yy0, yypParser.yystack[yypParser.yytos+0].minor.yy79)
		}
//line 2711 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-3].minor.yy79 = yylhsminor.yy79
		break
	case 80: /* position ::= expr ON HEADING expr FROM position */
//line 657 "pikchr.y"
		{
			yylhsminor.yy79 = pik_position_at_angle(yypParser.yystack[yypParser.yytos+-5].minor.yy153, yypParser.yystack[yypParser.yytos+-2].minor.yy153, yypParser.yystack[yypParser.yytos+0].minor.yy79)
		}
//line 2717 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-5].minor.yy79 = yylhsminor.yy79
		break
	case 81: /* position ::= expr HEADING expr FROM position */
//line 659 "pikchr.y"
		{
			yylhsminor.yy79 = pik_position_at_angle(yypParser.yystack[yypParser.yytos+-4].minor.yy153, yypParser.yystack[yypParser.yytos+-2].minor.yy153, yypParser.yystack[yypParser.yytos+0].minor.yy79)
		}
//line 2723 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-4].minor.yy79 = yylhsminor.yy79
		break
	case 82: /* place ::= edge OF object */
//line 671 "pikchr.y"
		{
			yylhsminor.yy79 = p.pik_place_of_elem(yypParser.yystack[yypParser.yytos+0].minor.yy104, &yypParser.yystack[yypParser.yytos+-2].minor.yy0)
		}
//line 2729 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy79 = yylhsminor.yy79
		break
	case 83: /* place2 ::= object */
//line 672 "pikchr.y"
		{
			yylhsminor.yy79 = p.pik_place_of_elem(yypParser.yystack[yypParser.yytos+0].minor.yy104, nil)
		}
//line 2735 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy79 = yylhsminor.yy79
		break
	case 84: /* place2 ::= object DOT_E edge */
//line 673 "pikchr.y"
		{
			yylhsminor.yy79 = p.pik_place_of_elem(yypParser.yystack[yypParser.yytos+-2].minor.yy104, &yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2741 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy79 = yylhsminor.yy79
		break
	case 85: /* place2 ::= NTH VERTEX OF object */
//line 674 "pikchr.y"
		{
			yylhsminor.yy79 = p.pik_nth_vertex(&yypParser.yystack[yypParser.yytos+-3].minor.yy0, &yypParser.yystack[yypParser.yytos+-2].minor.yy0, yypParser.yystack[yypParser.yytos+0].minor.yy104)
		}
//line 2747 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-3].minor.yy79 = yylhsminor.yy79
		break
	case 86: /* object ::= nth */
//line 686 "pikchr.y"
		{
			yylhsminor.yy104 = p.pik_find_nth(nil, &yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2753 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy104 = yylhsminor.yy104
		break
	case 87: /* object ::= nth OF|IN object */
//line 687 "pikchr.y"
		{
			yylhsminor.yy104 = p.pik_find_nth(yypParser.yystack[yypParser.yytos+0].minor.yy104, &yypParser.yystack[yypParser.yytos+-2].minor.yy0)
		}
//line 2759 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy104 = yylhsminor.yy104
		break
	case 88: /* objectname ::= THIS */
//line 689 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+0].minor.yy104 = p.cur
		}
//line 2765 "pikchr.go"
		break
	case 89: /* objectname ::= PLACENAME */
//line 690 "pikchr.y"
		{
			yylhsminor.yy104 = p.pik_find_byname(nil, &yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2770 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy104 = yylhsminor.yy104
		break
	case 90: /* objectname ::= objectname DOT_U PLACENAME */
//line 692 "pikchr.y"
		{
			yylhsminor.yy104 = p.pik_find_byname(yypParser.yystack[yypParser.yytos+-2].minor.yy104, &yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2776 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy104 = yylhsminor.yy104
		break
	case 91: /* nth ::= NTH CLASSNAME */
//line 694 "pikchr.y"
		{
			yylhsminor.yy0 = yypParser.yystack[yypParser.yytos+0].minor.yy0
			yylhsminor.yy0.eCode = p.pik_nth_value(&yypParser.yystack[yypParser.yytos+-1].minor.yy0)
		}
//line 2782 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-1].minor.yy0 = yylhsminor.yy0
		break
	case 92: /* nth ::= NTH LAST CLASSNAME */
//line 695 "pikchr.y"
		{
			yylhsminor.yy0 = yypParser.yystack[yypParser.yytos+0].minor.yy0
			yylhsminor.yy0.eCode = -p.pik_nth_value(&yypParser.yystack[yypParser.yytos+-2].minor.yy0)
		}
//line 2788 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy0 = yylhsminor.yy0
		break
	case 93: /* nth ::= LAST CLASSNAME */
//line 696 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-1].minor.yy0 = yypParser.yystack[yypParser.yytos+0].minor.yy0
			yypParser.yystack[yypParser.yytos+-1].minor.yy0.eCode = -1
		}
//line 2794 "pikchr.go"
		break
	case 94: /* nth ::= LAST */
//line 697 "pikchr.y"
		{
			yylhsminor.yy0 = yypParser.yystack[yypParser.yytos+0].minor.yy0
			yylhsminor.yy0.eCode = -1
		}
//line 2799 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy0 = yylhsminor.yy0
		break
	case 95: /* nth ::= NTH LB RB */
//line 698 "pikchr.y"
		{
			yylhsminor.yy0 = yypParser.yystack[yypParser.yytos+-1].minor.yy0
			yylhsminor.yy0.eCode = p.pik_nth_value(&yypParser.yystack[yypParser.yytos+-2].minor.yy0)
		}
//line 2805 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy0 = yylhsminor.yy0
		break
	case 96: /* nth ::= NTH LAST LB RB */
//line 699 "pikchr.y"
		{
			yylhsminor.yy0 = yypParser.yystack[yypParser.yytos+-1].minor.yy0
			yylhsminor.yy0.eCode = -p.pik_nth_value(&yypParser.yystack[yypParser.yytos+-3].minor.yy0)
		}
//line 2811 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-3].minor.yy0 = yylhsminor.yy0
		break
	case 97: /* nth ::= LAST LB RB */
//line 700 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-2].minor.yy0 = yypParser.yystack[yypParser.yytos+-1].minor.yy0
			yypParser.yystack[yypParser.yytos+-2].minor.yy0.eCode = -1
		}
//line 2817 "pikchr.go"
		break
	case 98: /* expr ::= expr PLUS expr */
//line 702 "pikchr.y"
		{
			yylhsminor.yy153 = yypParser.yystack[yypParser.yytos+-2].minor.yy153 + yypParser.yystack[yypParser.yytos+0].minor.yy153
		}
//line 2822 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy153 = yylhsminor.yy153
		break
	case 99: /* expr ::= expr MINUS expr */
//line 703 "pikchr.y"
		{
			yylhsminor.yy153 = yypParser.yystack[yypParser.yytos+-2].minor.yy153 - yypParser.yystack[yypParser.yytos+0].minor.yy153
		}
//line 2828 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy153 = yylhsminor.yy153
		break
	case 100: /* expr ::= expr STAR expr */
//line 704 "pikchr.y"
		{
			yylhsminor.yy153 = yypParser.yystack[yypParser.yytos+-2].minor.yy153 * yypParser.yystack[yypParser.yytos+0].minor.yy153
		}
//line 2834 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy153 = yylhsminor.yy153
		break
	case 101: /* expr ::= expr SLASH expr */
//line 705 "pikchr.y"
		{
			if yypParser.yystack[yypParser.yytos+0].minor.yy153 == 0.0 {
				p.pik_error(&yypParser.yystack[yypParser.yytos+-1].minor.yy0, "division by zero")
				yylhsminor.yy153 = 0.0
			} else {
				yylhsminor.yy153 = yypParser.yystack[yypParser.yytos+-2].minor.yy153 / yypParser.yystack[yypParser.yytos+0].minor.yy153
			}
		}
//line 2842 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy153 = yylhsminor.yy153
		break
	case 102: /* expr ::= MINUS expr */
//line 708 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-1].minor.yy153 = -yypParser.yystack[yypParser.yytos+0].minor.yy153
		}
//line 2848 "pikchr.go"
		break
	case 103: /* expr ::= PLUS expr */
//line 709 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-1].minor.yy153 = yypParser.yystack[yypParser.yytos+0].minor.yy153
		}
//line 2853 "pikchr.go"
		break
	case 104: /* expr ::= LP expr RP */
//line 710 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-2].minor.yy153 = yypParser.yystack[yypParser.yytos+-1].minor.yy153
		}
//line 2858 "pikchr.go"
		break
	case 105: /* expr ::= LP FILL|COLOR|THICKNESS RP */
//line 711 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-2].minor.yy153 = p.pik_get_var(&yypParser.yystack[yypParser.yytos+-1].minor.yy0)
		}
//line 2863 "pikchr.go"
		break
	case 106: /* expr ::= NUMBER */
//line 712 "pikchr.y"
		{
			yylhsminor.yy153 = pik_atof(&yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2868 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy153 = yylhsminor.yy153
		break
	case 107: /* expr ::= ID */
//line 713 "pikchr.y"
		{
			yylhsminor.yy153 = p.pik_get_var(&yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2874 "pikchr.go"
		yypParser.yystack[yypParser.yytos+0].minor.yy153 = yylhsminor.yy153
		break
	case 108: /* expr ::= FUNC1 LP expr RP */
//line 714 "pikchr.y"
		{
			yylhsminor.yy153 = p.pik_func(&yypParser.yystack[yypParser.yytos+-3].minor.yy0, yypParser.yystack[yypParser.yytos+-1].minor.yy153, 0.0)
		}
//line 2880 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-3].minor.yy153 = yylhsminor.yy153
		break
	case 109: /* expr ::= FUNC2 LP expr COMMA expr RP */
//line 715 "pikchr.y"
		{
			yylhsminor.yy153 = p.pik_func(&yypParser.yystack[yypParser.yytos+-5].minor.yy0, yypParser.yystack[yypParser.yytos+-3].minor.yy153, yypParser.yystack[yypParser.yytos+-1].minor.yy153)
		}
//line 2886 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-5].minor.yy153 = yylhsminor.yy153
		break
	case 110: /* expr ::= DIST LP position COMMA position RP */
//line 716 "pikchr.y"
		{
			yypParser.yystack[yypParser.yytos+-5].minor.yy153 = pik_dist(&yypParser.yystack[yypParser.yytos+-3].minor.yy79, &yypParser.yystack[yypParser.yytos+-1].minor.yy79)
		}
//line 2892 "pikchr.go"
		break
	case 111: /* expr ::= place2 DOT_XY X */
//line 717 "pikchr.y"
		{
			yylhsminor.yy153 = yypParser.yystack[yypParser.yytos+-2].minor.yy79.x
		}
//line 2897 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy153 = yylhsminor.yy153
		break
	case 112: /* expr ::= place2 DOT_XY Y */
//line 718 "pikchr.y"
		{
			yylhsminor.yy153 = yypParser.yystack[yypParser.yytos+-2].minor.yy79.y
		}
//line 2903 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy153 = yylhsminor.yy153
		break
	case 113: /* expr ::= object DOT_L numproperty */
		fallthrough
	case 114: /* expr ::= object DOT_L dashproperty */
		yytestcase(yyruleno == 114)
		fallthrough
	case 115: /* expr ::= object DOT_L colorproperty */
		yytestcase(yyruleno == 115)
//line 719 "pikchr.y"
		{
			yylhsminor.yy153 = pik_property_of(yypParser.yystack[yypParser.yytos+-2].minor.yy104, &yypParser.yystack[yypParser.yytos+0].minor.yy0)
		}
//line 2913 "pikchr.go"
		yypParser.yystack[yypParser.yytos+-2].minor.yy153 = yylhsminor.yy153
		break
	default:
		/* (116) lvalue ::= ID */ yytestcase(yyruleno == 116)
		/* (117) lvalue ::= FILL */ yytestcase(yyruleno == 117)
		/* (118) lvalue ::= COLOR */ yytestcase(yyruleno == 118)
		/* (119) lvalue ::= THICKNESS */ yytestcase(yyruleno == 119)
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273

	p := yypParser.p
	_ = p

	TOKEN := yyminor
	_ = TOKEN
	/************ Begin %syntax_error code ****************************************/
//line 486 "pikchr.y"

	if TOKEN.z != nil && TOKEN.z[0] != 0 {
		p.pik_error(&TOKEN, "syntax error")
	} else {
		p.pik_error(nil, "syntax error")
	}
//line 3031 "pikchr.go"

	/************ End %syntax_error code ******************************************/
	/* Suppress warning about unused %extra_argument variable */
	yypParser.p = p

}








|






|







3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268

	p := yypParser.p
	_ = p

	TOKEN := yyminor
	_ = TOKEN
	/************ Begin %syntax_error code ****************************************/
//line 481 "pikchr.y"

	if TOKEN.z != nil && TOKEN.z[0] != 0 {
		p.pik_error(&TOKEN, "syntax error")
	} else {
		p.pik_error(nil, "syntax error")
	}
//line 3026 "pikchr.go"

	/************ End %syntax_error code ******************************************/
	/* Suppress warning about unused %extra_argument variable */
	yypParser.p = p

}

3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
// to check invariants.
func assert(condition bool, message string) {
	if !condition {
		panic(message)
	}
}

//line 729 "pikchr.y"

/* Chart of the 148 official CSS color names with their
** corresponding RGB values thru Color Module Level 4:
** https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
**
** Two new names "None" and "Off" are added with a value
** of -1.







|







3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
// to check invariants.
func assert(condition bool, message string) {
	if !condition {
		panic(message)
	}
}

//line 724 "pikchr.y"

/* Chart of the 148 official CSS color names with their
** corresponding RGB values thru Color Module Level 4:
** https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
**
** Two new names "None" and "Off" are added with a value
** of -1.
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
	pObj.h = pObj.w
	pObj.rad = 0.5 * pObj.w
}
func circleNumProp(p *Pik, pObj *PObj, pId *PToken) {
	/* For a circle, the width must equal the height and both must
	 ** be twice the radius.  Enforce those constraints. */
	switch pId.eType {
	case T_DIAMETER, T_RADIUS:
		pObj.w = 2.0 * pObj.rad
		pObj.h = 2.0 * pObj.rad
	case T_WIDTH:
		pObj.h = pObj.w
		pObj.rad = 0.5 * pObj.w
	case T_HEIGHT:
		pObj.w = pObj.h







|







4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
	pObj.h = pObj.w
	pObj.rad = 0.5 * pObj.w
}
func circleNumProp(p *Pik, pObj *PObj, pId *PToken) {
	/* For a circle, the width must equal the height and both must
	 ** be twice the radius.  Enforce those constraints. */
	switch pId.eType {
	case T_RADIUS:
		pObj.w = 2.0 * pObj.rad
		pObj.h = 2.0 * pObj.rad
	case T_WIDTH:
		pObj.h = pObj.w
		pObj.rad = 0.5 * pObj.w
	case T_HEIGHT:
		pObj.w = pObj.h
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
/*
** Append raw text to zOut
 */
func (p *Pik) pik_append(zText string) {
	p.zOut.WriteString(zText)
}

var re_entity = regexp.MustCompile(`&(#([0-9]{2,});)|([a-zA-Z][a-zA-Z0-9]+;)`)

/*
** Append text to zOut with HTML characters escaped.
**
**   *  The space character is changed into non-breaking space (U+00a0)
**      if mFlags has the 0x01 bit set. This is needed when outputting
**      text to preserve leading and trailing whitespace.  Turns out we
**      cannot use &nbsp; as that is an HTML-ism and is not valid in XML.
**
**   *  The "&" character is changed into "&amp;" if mFlags has the
**      0x02 bit set.  This is needed when generating error message text.
**
**   *  Except for the above, only "<" and ">" are escaped.
 */
func (p *Pik) pik_append_text(zText string, mFlags int) {
	bQSpace := mFlags&1 > 0
	bQAmp := mFlags&2 > 0

	last := 0
	var html string
	for i := 0; i < len(zText); i++ {
		switch zText[i] {
		case '<':
			html = "&lt;"
		case '>':
			html = "&gt;"
		case '&':
			if !bQAmp {
				continue
			}
			match := re_entity.FindStringSubmatch(zText[i:])
			if len(match) > 0 {
				continue
			}
			html = "&amp;"
		case ' ':
			if !bQSpace {
				continue
			}
			html = "\u00a0"
		default:
			continue
		}
		p.pik_append(zText[last:i])
		p.pik_append(html)
		last = i + 1
	}
	p.pik_append(zText[last:])
}

/*
** Append error message text.  This is either a raw append, or an append
** with HTML escapes, depending on whether the PIKCHR_PLAINTEXT_ERRORS flag
** is set.
 */







|


















<
|
<
|
|
|
|
|
|
<
<
<
<
<
<
<
|
<
|
<
<
|

|

<
<
<
|
|







4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849

4850

4851
4852
4853
4854
4855
4856







4857

4858


4859
4860
4861
4862



4863
4864
4865
4866
4867
4868
4869
4870
4871
/*
** Append raw text to zOut
 */
func (p *Pik) pik_append(zText string) {
	p.zOut.WriteString(zText)
}

var html_re_with_space = regexp.MustCompile(`[<>& ]`)

/*
** Append text to zOut with HTML characters escaped.
**
**   *  The space character is changed into non-breaking space (U+00a0)
**      if mFlags has the 0x01 bit set. This is needed when outputting
**      text to preserve leading and trailing whitespace.  Turns out we
**      cannot use &nbsp; as that is an HTML-ism and is not valid in XML.
**
**   *  The "&" character is changed into "&amp;" if mFlags has the
**      0x02 bit set.  This is needed when generating error message text.
**
**   *  Except for the above, only "<" and ">" are escaped.
 */
func (p *Pik) pik_append_text(zText string, mFlags int) {
	bQSpace := mFlags&1 > 0
	bQAmp := mFlags&2 > 0


	text := html_re_with_space.ReplaceAllStringFunc(zText, func(s string) string {

		switch {
		case s == "<":
			return "&lt;"
		case s == ">":
			return "&gt;"
		case s == "&" && bQAmp:







			return "&amp;"

		case s == " " && bQSpace:


			return "\302\240"
		default:
			return s
		}



	})
	p.pik_append(text)
}

/*
** Append error message text.  This is either a raw append, or an append
** with HTML escapes, depending on whether the PIKCHR_PLAINTEXT_ERRORS flag
** is set.
 */
6194
6195
6196
6197
6198
6199
6200
6201



6202
6203
6204
6205
6206
6207
6208
	}
	p.pik_reset_samepath()
	n := 0
	for n < 1 {
		n = p.pik_next_rpath(pErr)
	}
	if pHeading != nil {
		rHdg = math.Mod(rHdg, 360.0)



	} else if pEdgept.eEdge == CP_C {
		p.pik_error(pEdgept, "syntax error")
		return
	} else {
		rHdg = pik_hdg_angle[pEdgept.eEdge]
	}
	if rHdg <= 45.0 {







|
>
>
>







6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
	}
	p.pik_reset_samepath()
	n := 0
	for n < 1 {
		n = p.pik_next_rpath(pErr)
	}
	if pHeading != nil {
		if rHdg < 0.0 || rHdg > 360.0 {
			p.pik_error(pHeading, "headings should be between 0 and 360")
			return
		}
	} else if pEdgept.eEdge == CP_C {
		p.pik_error(pEdgept, "syntax error")
		return
	} else {
		rHdg = pik_hdg_angle[pEdgept.eEdge]
	}
	if rHdg <= 45.0 {
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139

/* Compute one of the built-in functions
 */
func (p *Pik) pik_func(pFunc *PToken, x PNum, y PNum) PNum {
	var v PNum
	switch pFunc.eCode {
	case FN_ABS:
		if x < 0 {
			v = -x
		} else {
			v = x
		}
	case FN_COS:
		v = math.Cos(x)
	case FN_INT:
		v = math.Round(x)
	case FN_SIN:
		v = math.Sin(x)







<
|
|
|







7105
7106
7107
7108
7109
7110
7111

7112
7113
7114
7115
7116
7117
7118
7119
7120
7121

/* Compute one of the built-in functions
 */
func (p *Pik) pik_func(pFunc *PToken, x PNum, y PNum) PNum {
	var v PNum
	switch pFunc.eCode {
	case FN_ABS:

		v = x
		if v < 0 {
			v = -v
		}
	case FN_COS:
		v = math.Cos(x)
	case FN_INT:
		v = math.Round(x)
	case FN_SIN:
		v = math.Sin(x)
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
				n = 0
			}

			fmt.Printf("******** Token %s (%d): \"%s\" **************\n",
				yyTokenName[token.eType], token.eType, string(token.z[:n]))
		} // #endif
		token.n = sz
		p.nToken++
		if p.nToken > PIKCHR_TOKEN_LIMIT {
			p.pik_error(&token, "script is too complex")
			break
		}
		pParser.pik_parser(token.eType, token)
	}
}

/*
** Parse the PIKCHR script contained in zText[].  Return a rendering.  Or
** if an error is encountered, return the error text.  The error message







<
<
<
<
<







8324
8325
8326
8327
8328
8329
8330





8331
8332
8333
8334
8335
8336
8337
				n = 0
			}

			fmt.Printf("******** Token %s (%d): \"%s\" **************\n",
				yyTokenName[token.eType], token.eType, string(token.z[:n]))
		} // #endif
		token.n = sz





		pParser.pik_parser(token.eType, token)
	}
}

/*
** Parse the PIKCHR script contained in zText[].  Return a rendering.  Or
** if an error is encountered, return the error text.  The error message
8481
8482
8483
8484
8485
8486
8487
8488
		if b[i] != bb {
			return false
		}
	}
	return true
}

//line 8253 "pikchr.go"







|
8458
8459
8460
8461
8462
8463
8464
8465
		if b[i] != bb {
			return false
		}
	}
	return true
}

//line 8230 "pikchr.go"

Changes to parser/pikchr/internal/pikchr.y.

127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
	"math"
	"os"
	"regexp"
	"strconv"
	"strings"
)

// Limit the number of tokens in a single script to avoid run-away macro expansion attacks.
// See forum post https://pikchr.org/home/forumpost/ef8684c6955a411a
const PIKCHR_TOKEN_LIMIT = 100000

// Numeric value
type PNum = float64

// Compass points
const (
	CP_N uint8 = iota + 1
	CP_NE







<
<
<
<







127
128
129
130
131
132
133




134
135
136
137
138
139
140
	"math"
	"os"
	"regexp"
	"strconv"
	"strings"
)





// Numeric value
type PNum = float64

// Compass points
const (
	CP_N uint8 = iota + 1
	CP_NE
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
}

/* Each call to the pikchr() subroutine uses an instance of the following
** object to pass around context to all of its subroutines.
 */
type Pik struct {
	nErr      int          /* Number of errors seen */
	nToken    int          // Number of tokens parsed
	sIn       PToken       /* Input Pikchr-language text */
	zOut      bytes.Buffer /* Result accumulates here */
	nOut      uint         /* Bytes written to zOut[] so far */
	nOutAlloc uint         /* Space allocated to zOut[] */
	eDir      uint8        /* Current direction */
	mFlags    uint         /* Flags passed to pikchr() */
	cur       *PObj        /* Object under construction */







<







359
360
361
362
363
364
365

366
367
368
369
370
371
372
}

/* Each call to the pikchr() subroutine uses an instance of the following
** object to pass around context to all of its subroutines.
 */
type Pik struct {
	nErr      int          /* Number of errors seen */

	sIn       PToken       /* Input Pikchr-language text */
	zOut      bytes.Buffer /* Result accumulates here */
	nOut      uint         /* Bytes written to zOut[] so far */
	nOutAlloc uint         /* Space allocated to zOut[] */
	eDir      uint8        /* Current direction */
	mFlags    uint         /* Flags passed to pikchr() */
	cur       *PObj        /* Object under construction */
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
	pObj.h = pObj.w
	pObj.rad = 0.5 * pObj.w
}
func circleNumProp(p *Pik, pObj *PObj, pId *PToken) {
	/* For a circle, the width must equal the height and both must
	 ** be twice the radius.  Enforce those constraints. */
	switch pId.eType {
	case T_DIAMETER, T_RADIUS:
		pObj.w = 2.0 * pObj.rad
		pObj.h = 2.0 * pObj.rad
	case T_WIDTH:
		pObj.h = pObj.w
		pObj.rad = 0.5 * pObj.w
	case T_HEIGHT:
		pObj.w = pObj.h







|







1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
	pObj.h = pObj.w
	pObj.rad = 0.5 * pObj.w
}
func circleNumProp(p *Pik, pObj *PObj, pId *PToken) {
	/* For a circle, the width must equal the height and both must
	 ** be twice the radius.  Enforce those constraints. */
	switch pId.eType {
	case T_RADIUS:
		pObj.w = 2.0 * pObj.rad
		pObj.h = 2.0 * pObj.rad
	case T_WIDTH:
		pObj.h = pObj.w
		pObj.rad = 0.5 * pObj.w
	case T_HEIGHT:
		pObj.w = pObj.h
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
/*
** Append raw text to zOut
 */
func (p *Pik) pik_append(zText string) {
	p.zOut.WriteString(zText)
}

var re_entity = regexp.MustCompile(`&(#([0-9]{2,});)|([a-zA-Z][a-zA-Z0-9]+;)`)

/*
** Append text to zOut with HTML characters escaped.
**
**   *  The space character is changed into non-breaking space (U+00a0)
**      if mFlags has the 0x01 bit set. This is needed when outputting
**      text to preserve leading and trailing whitespace.  Turns out we
**      cannot use &nbsp; as that is an HTML-ism and is not valid in XML.
**
**   *  The "&" character is changed into "&amp;" if mFlags has the
**      0x02 bit set.  This is needed when generating error message text.
**
**   *  Except for the above, only "<" and ">" are escaped.
 */
func (p *Pik) pik_append_text(zText string, mFlags int) {
	bQSpace := mFlags&1 > 0
	bQAmp := mFlags&2 > 0

	last := 0
	var html string
	for i := 0; i < len(zText); i++ {
		switch zText[i] {
		case '<':
			html = "&lt;"
		case '>':
			html = "&gt;"
		case '&':
			if !bQAmp {
				continue
			}
			match := re_entity.FindStringSubmatch(zText[i:])
			if len(match) > 0 {
				continue
			}
			html = "&amp;"
		case ' ':
			if !bQSpace {
				continue
			}
			html = "\u00a0"
		default:
			continue
		}
		p.pik_append(zText[last:i])
		p.pik_append(html)
		last = i + 1
	}
	p.pik_append(zText[last:])
}

/*
** Append error message text.  This is either a raw append, or an append
** with HTML escapes, depending on whether the PIKCHR_PLAINTEXT_ERRORS flag
** is set.
 */







|


















<
|
<
|
|
|
|
|
|
<
<
<
<
<
<
<
|
<
|
<
<
|

|

<
<
<
|
|







2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025

2026

2027
2028
2029
2030
2031
2032







2033

2034


2035
2036
2037
2038



2039
2040
2041
2042
2043
2044
2045
2046
2047
/*
** Append raw text to zOut
 */
func (p *Pik) pik_append(zText string) {
	p.zOut.WriteString(zText)
}

var html_re_with_space = regexp.MustCompile(`[<>& ]`)

/*
** Append text to zOut with HTML characters escaped.
**
**   *  The space character is changed into non-breaking space (U+00a0)
**      if mFlags has the 0x01 bit set. This is needed when outputting
**      text to preserve leading and trailing whitespace.  Turns out we
**      cannot use &nbsp; as that is an HTML-ism and is not valid in XML.
**
**   *  The "&" character is changed into "&amp;" if mFlags has the
**      0x02 bit set.  This is needed when generating error message text.
**
**   *  Except for the above, only "<" and ">" are escaped.
 */
func (p *Pik) pik_append_text(zText string, mFlags int) {
	bQSpace := mFlags&1 > 0
	bQAmp := mFlags&2 > 0


	text := html_re_with_space.ReplaceAllStringFunc(zText, func(s string) string {

		switch {
		case s == "<":
			return "&lt;"
		case s == ">":
			return "&gt;"
		case s == "&" && bQAmp:







			return "&amp;"

		case s == " " && bQSpace:


			return "\302\240"
		default:
			return s
		}



	})
	p.pik_append(text)
}

/*
** Append error message text.  This is either a raw append, or an append
** with HTML escapes, depending on whether the PIKCHR_PLAINTEXT_ERRORS flag
** is set.
 */
3370
3371
3372
3373
3374
3375
3376
3377



3378
3379
3380
3381
3382
3383
3384
	}
	p.pik_reset_samepath()
	n := 0
	for n < 1 {
		n = p.pik_next_rpath(pErr)
	}
	if pHeading != nil {
		rHdg = math.Mod(rHdg, 360.0)



	} else if pEdgept.eEdge == CP_C {
		p.pik_error(pEdgept, "syntax error")
		return
	} else {
		rHdg = pik_hdg_angle[pEdgept.eEdge]
	}
	if rHdg <= 45.0 {







|
>
>
>







3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
	}
	p.pik_reset_samepath()
	n := 0
	for n < 1 {
		n = p.pik_next_rpath(pErr)
	}
	if pHeading != nil {
		if rHdg < 0.0 || rHdg > 360.0 {
			p.pik_error(pHeading, "headings should be between 0 and 360")
			return
		}
	} else if pEdgept.eEdge == CP_C {
		p.pik_error(pEdgept, "syntax error")
		return
	} else {
		rHdg = pik_hdg_angle[pEdgept.eEdge]
	}
	if rHdg <= 45.0 {
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315

/* Compute one of the built-in functions
 */
func (p *Pik) pik_func(pFunc *PToken, x PNum, y PNum) PNum {
	var v PNum
	switch pFunc.eCode {
	case FN_ABS:
		if x < 0 {
			v = -x
		} else {
			v = x
		}
	case FN_COS:
		v = math.Cos(x)
	case FN_INT:
		v = math.Round(x)
	case FN_SIN:
		v = math.Sin(x)







<
|
|
|







4281
4282
4283
4284
4285
4286
4287

4288
4289
4290
4291
4292
4293
4294
4295
4296
4297

/* Compute one of the built-in functions
 */
func (p *Pik) pik_func(pFunc *PToken, x PNum, y PNum) PNum {
	var v PNum
	switch pFunc.eCode {
	case FN_ABS:

		v = x
		if v < 0 {
			v = -v
		}
	case FN_COS:
		v = math.Cos(x)
	case FN_INT:
		v = math.Round(x)
	case FN_SIN:
		v = math.Sin(x)
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
				n = 0
			}

			fmt.Printf("******** Token %s (%d): \"%s\" **************\n",
				yyTokenName[token.eType], token.eType, string(token.z[:n]))
		} // #endif
		token.n = sz
		p.nToken++
		if p.nToken > PIKCHR_TOKEN_LIMIT {
        	p.pik_error(&token, "script is too complex");
        	break;
    	}
		pParser.pik_parser(token.eType, token)
	}
}

/*
** Parse the PIKCHR script contained in zText[].  Return a rendering.  Or
** if an error is encountered, return the error text.  The error message







<
<
<
<
<







5500
5501
5502
5503
5504
5505
5506





5507
5508
5509
5510
5511
5512
5513
				n = 0
			}

			fmt.Printf("******** Token %s (%d): \"%s\" **************\n",
				yyTokenName[token.eType], token.eType, string(token.z[:n]))
		} // #endif
		token.n = sz





		pParser.pik_parser(token.eType, token)
	}
}

/*
** Parse the PIKCHR script contained in zText[].  Return a rendering.  Or
** if an error is encountered, return the error text.  The error message

Changes to parser/zettelmark/inline.go.

63
64
65
66
67
68
69


70
71
72
73
74
75
76
				in, success = cp.parseMark()
			}
		case '{':
			inp.Next()
			if inp.Ch == '{' {
				in, success = cp.parseEmbed()
			}


		case '%':
			in, success = cp.parseComment()
		case '_', '*', '>', '~', '^', ',', '"', ':':
			in, success = cp.parseFormat()
		case '@', '\'', '`', '=', runeModGrave:
			in, success = cp.parseLiteral()
		case '$':







>
>







63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
				in, success = cp.parseMark()
			}
		case '{':
			inp.Next()
			if inp.Ch == '{' {
				in, success = cp.parseEmbed()
			}
		case '#':
			return cp.parseTag()
		case '%':
			in, success = cp.parseComment()
		case '_', '*', '>', '~', '^', ',', '"', ':':
			in, success = cp.parseFormat()
		case '@', '\'', '`', '=', runeModGrave:
			in, success = cp.parseLiteral()
		case '$':
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
		return cp.parseBackslashRest()
	}
	for {
		inp.Next()
		switch inp.Ch {
		// The following case must contain all runes that occur in parseInline!
		// Plus the closing brackets ] and } and ) and the middle |
		case input.EOS, '\n', '\r', ' ', '\t', '[', ']', '{', '}', '(', ')', '|', '%', '_', '*', '>', '~', '^', ',', '"', ':', '\'', '@', '`', runeModGrave, '$', '=', '\\', '-', '&':
			return &ast.TextNode{Text: string(inp.Src[pos:inp.Pos])}
		}
	}
}

func (cp *zmkP) parseBackslash() ast.InlineNode {
	inp := cp.inp







|







100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
		return cp.parseBackslashRest()
	}
	for {
		inp.Next()
		switch inp.Ch {
		// The following case must contain all runes that occur in parseInline!
		// Plus the closing brackets ] and } and ) and the middle |
		case input.EOS, '\n', '\r', ' ', '\t', '[', ']', '{', '}', '(', ')', '|', '#', '%', '_', '*', '>', '~', '^', ',', '"', ':', '\'', '@', '`', runeModGrave, '$', '=', '\\', '-', '&':
			return &ast.TextNode{Text: string(inp.Src[pos:inp.Pos])}
		}
	}
}

func (cp *zmkP) parseBackslash() ast.InlineNode {
	inp := cp.inp
377
378
379
380
381
382
383














384
385
386
387
388
389
390
		}
	} else {
		inp.Next()
	}
	mn := &ast.MarkNode{Mark: string(mark), Inlines: ins}
	return mn, true
}















func (cp *zmkP) parseComment() (res *ast.LiteralNode, success bool) {
	inp := cp.inp
	inp.Next()
	if inp.Ch != '%' {
		return nil, false
	}







>
>
>
>
>
>
>
>
>
>
>
>
>
>







379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
		}
	} else {
		inp.Next()
	}
	mn := &ast.MarkNode{Mark: string(mark), Inlines: ins}
	return mn, true
}

func (cp *zmkP) parseTag() ast.InlineNode {
	inp := cp.inp
	posH := inp.Pos
	inp.Next()
	pos := inp.Pos
	for isNameRune(inp.Ch) {
		inp.Next()
	}
	if pos == inp.Pos || inp.Ch == '#' {
		return &ast.TextNode{Text: string(inp.Src[posH:inp.Pos])}
	}
	return &ast.TagNode{Tag: string(inp.Src[pos:inp.Pos])}
}

func (cp *zmkP) parseComment() (res *ast.LiteralNode, success bool) {
	inp := cp.inp
	inp.Next()
	if inp.Ch != '%' {
		return nil, false
	}

Changes to parser/zettelmark/zettelmark_test.go.

243
244
245
246
247
248
249













250
251
252
253
254
255
256
		{"{{b\\}|a}}", "(PARA (EMBED a b}))"},
		{"{{\\}\\||a}}", "(PARA (EMBED a }|))"},
		{"{{http://a}}", "(PARA (EMBED http://a))"},
		{"{{http://a|http://a}}", "(PARA (EMBED http://a http://a))"},
		{"{{{{a}}}}", "(PARA (EMBED %7B%7Ba) }})"},
	})
}














func TestMark(t *testing.T) {
	t.Parallel()
	checkTcs(t, TestCases{
		{"[!", "(PARA [!)"},
		{"[!\n", "(PARA [!)"},
		{"[!]", "(PARA (MARK #*))"},







>
>
>
>
>
>
>
>
>
>
>
>
>







243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
		{"{{b\\}|a}}", "(PARA (EMBED a b}))"},
		{"{{\\}\\||a}}", "(PARA (EMBED a }|))"},
		{"{{http://a}}", "(PARA (EMBED http://a))"},
		{"{{http://a|http://a}}", "(PARA (EMBED http://a http://a))"},
		{"{{{{a}}}}", "(PARA (EMBED %7B%7Ba) }})"},
	})
}

func TestTag(t *testing.T) {
	t.Parallel()
	checkTcs(t, TestCases{
		{"#", "(PARA #)"},
		{"##", "(PARA ##)"},
		{"###", "(PARA ###)"},
		{"#tag", "(PARA #tag#)"},
		{"#tag,", "(PARA #tag# ,)"},
		{"#t-g ", "(PARA #t-g#)"},
		{"#t_g", "(PARA #t_g#)"},
	})
}

func TestMark(t *testing.T) {
	t.Parallel()
	checkTcs(t, TestCases{
		{"[!", "(PARA [!)"},
		{"[!\n", "(PARA [!)"},
		{"[!]", "(PARA (MARK #*))"},
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424

func TestEntity(t *testing.T) {
	t.Parallel()
	checkTcs(t, TestCases{
		{"&", "(PARA &)"},
		{"&;", "(PARA &;)"},
		{"&#;", "(PARA &#;)"},
		{"&#1a;", "(PARA &#1a;)"},
		{"&#x;", "(PARA &#x;)"},
		{"&#x0z;", "(PARA &#x0z;)"},
		{"&1;", "(PARA &1;)"},
		{"&#9;", "(PARA &#9;)"}, // No numeric entities below space are not allowed.
		{"&#x1f;", "(PARA &#x1f;)"},

		// Good cases
		{"&lt;", "(PARA <)"},
		{"&#48;", "(PARA 0)"},
		{"&#x4A;", "(PARA J)"},
		{"&#X4a;", "(PARA J)"},
		{"&hellip;", "(PARA \u2026)"},
		{"&nbsp;", "(PARA \u00a0)"},
		{"E: &amp;,&#63;;&#x63;.", "(PARA E: SP &,?;c.)"},
	})
}

func TestVerbatimZettel(t *testing.T) {
	t.Parallel()
	checkTcs(t, TestCases{
		{"@@@\n@@@", "(ZETTEL)"},







|
|
|

<
<
<






<
|







409
410
411
412
413
414
415
416
417
418
419



420
421
422
423
424
425

426
427
428
429
430
431
432
433

func TestEntity(t *testing.T) {
	t.Parallel()
	checkTcs(t, TestCases{
		{"&", "(PARA &)"},
		{"&;", "(PARA &;)"},
		{"&#;", "(PARA &#;)"},
		{"&#1a;", "(PARA & #1a# ;)"},
		{"&#x;", "(PARA & #x# ;)"},
		{"&#x0z;", "(PARA & #x0z# ;)"},
		{"&1;", "(PARA &1;)"},



		// Good cases
		{"&lt;", "(PARA <)"},
		{"&#48;", "(PARA 0)"},
		{"&#x4A;", "(PARA J)"},
		{"&#X4a;", "(PARA J)"},
		{"&hellip;", "(PARA \u2026)"},

		{"E: &amp;,&#13;;&#xa;.", "(PARA E: SP &,\r;\n.)"},
	})
}

func TestVerbatimZettel(t *testing.T) {
	t.Parallel()
	checkTcs(t, TestCases{
		{"@@@\n@@@", "(ZETTEL)"},
874
875
876
877
878
879
880




881
882
883
884
885
886
887
		tv.visitAttributes(n.Attrs)
	case *ast.BLOBNode:
		tv.buf.WriteString("(BLOB ")
		tv.buf.WriteString(n.Syntax)
		tv.buf.WriteString(")")
	case *ast.TextNode:
		tv.buf.WriteString(n.Text)




	case *ast.SpaceNode:
		if l := n.Count(); l == 1 {
			tv.buf.WriteString("SP")
		} else {
			fmt.Fprintf(&tv.buf, "SP%d", l)
		}
	case *ast.BreakNode:







>
>
>
>







883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
		tv.visitAttributes(n.Attrs)
	case *ast.BLOBNode:
		tv.buf.WriteString("(BLOB ")
		tv.buf.WriteString(n.Syntax)
		tv.buf.WriteString(")")
	case *ast.TextNode:
		tv.buf.WriteString(n.Text)
	case *ast.TagNode:
		tv.buf.WriteByte('#')
		tv.buf.WriteString(n.Tag)
		tv.buf.WriteByte('#')
	case *ast.SpaceNode:
		if l := n.Count(); l == 1 {
			tv.buf.WriteString("SP")
		} else {
			fmt.Fprintf(&tv.buf, "SP%d", l)
		}
	case *ast.BreakNode:

Changes to query/query.go.

10
11
12
13
14
15
16

17
18
19
20
21
22
23

// Package query provides a query for zettel.
package query

import (
	"math/rand"
	"sort"


	"zettelstore.de/z/domain/id"
	"zettelstore.de/z/domain/meta"
)

// Searcher is used to select zettel identifier based on search criteria.
type Searcher interface {







>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

// Package query provides a query for zettel.
package query

import (
	"math/rand"
	"sort"
	"strings"

	"zettelstore.de/z/domain/id"
	"zettelstore.de/z/domain/meta"
)

// Searcher is used to select zettel identifier based on search criteria.
type Searcher interface {
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276





277
278
279
280
281
282
283

// EnrichNeeded returns true, if the query references a metadata key that
// is calculated via metadata enrichments.
func (q *Query) EnrichNeeded() bool {
	if q == nil {
		return false
	}
	if len(q.actions) > 0 {
		// Unknown, what an action will use. Example: RSS needs api.KeyPublished.
		return true
	}
	for _, term := range q.terms {
		for key := range term.keys {
			if meta.IsProperty(key) {
				return true
			}
		}
		for key := range term.mvals {
			if meta.IsProperty(key) {
				return true
			}
		}
	}
	for _, o := range q.order {
		if meta.IsProperty(o.key) {
			return true
		}





	}
	return false
}

// RetrieveAndCompile queries the search index and returns a predicate
// for its results and returns a matching predicate.
func (q *Query) RetrieveAndCompile(searcher Searcher) Compiled {







<
<
<
<
















>
>
>
>
>







251
252
253
254
255
256
257




258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285

// EnrichNeeded returns true, if the query references a metadata key that
// is calculated via metadata enrichments.
func (q *Query) EnrichNeeded() bool {
	if q == nil {
		return false
	}




	for _, term := range q.terms {
		for key := range term.keys {
			if meta.IsProperty(key) {
				return true
			}
		}
		for key := range term.mvals {
			if meta.IsProperty(key) {
				return true
			}
		}
	}
	for _, o := range q.order {
		if meta.IsProperty(o.key) {
			return true
		}
	}
	for _, a := range q.actions {
		if meta.IsProperty(strings.ToLower(a)) {
			return true
		}
	}
	return false
}

// RetrieveAndCompile queries the search index and returns a predicate
// for its results and returns a matching predicate.
func (q *Query) RetrieveAndCompile(searcher Searcher) Compiled {

Changes to usecase/lists.go.

98
99
100
101
102
103
104




































	q := query.Parse(api.KeyRole + api.ExistOperator) // We look for all metadata with an existing role key
	metas, err := uc.port.SelectMeta(box.NoEnrichContext(ctx), q)
	if err != nil {
		return nil, err
	}
	return meta.CreateArrangement(metas, api.KeyRole), nil
}











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
	q := query.Parse(api.KeyRole + api.ExistOperator) // We look for all metadata with an existing role key
	metas, err := uc.port.SelectMeta(box.NoEnrichContext(ctx), q)
	if err != nil {
		return nil, err
	}
	return meta.CreateArrangement(metas, api.KeyRole), nil
}

// -------- List tags --------------------------------------------------------

// ListTagsPort is the interface used by this use case.
type ListTagsPort interface {
	// SelectMeta returns all zettel metadata that match the selection criteria.
	SelectMeta(ctx context.Context, q *query.Query) ([]*meta.Meta, error)
}

// ListTags is the data for this use case.
type ListTags struct {
	port ListTagsPort
}

// NewListTags creates a new use case.
func NewListTags(port ListTagsPort) ListTags {
	return ListTags{port: port}
}

// Run executes the use case.
func (uc ListTags) Run(ctx context.Context, minCount int) (meta.Arrangement, error) {
	q := query.Parse(api.KeyAllTags + api.ExistOperator) // We look for all metadata with a tag
	metas, err := uc.port.SelectMeta(ctx, q)
	if err != nil {
		return nil, err
	}
	result := meta.CreateArrangement(metas, api.KeyAllTags)
	if minCount > 1 {
		for t, ms := range result {
			if len(ms) < minCount {
				delete(result, t)
			}
		}
	}
	return result, nil
}

Changes to web/adapter/api/command.go.

21
22
23
24
25
26
27





28
29
30
31
32
33
34
35
// MakePostCommandHandler creates a new HTTP handler to execute certain commands.
func (a *API) MakePostCommandHandler(
	ucIsAuth *usecase.IsAuthenticated,
	ucRefresh *usecase.Refresh,
) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		ctx := r.Context()





		switch api.Command(r.URL.Query().Get(api.QueryKeyCommand)) {
		case api.CommandAuthenticated:
			handleIsAuthenticated(ctx, w, ucIsAuth)
			return
		case api.CommandRefresh:
			err := ucRefresh.Run(ctx)
			if err != nil {
				a.reportUsecaseError(w, err)







>
>
>
>
>
|







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// MakePostCommandHandler creates a new HTTP handler to execute certain commands.
func (a *API) MakePostCommandHandler(
	ucIsAuth *usecase.IsAuthenticated,
	ucRefresh *usecase.Refresh,
) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		ctx := r.Context()
		q := r.URL.Query()
		cmd := q.Get(api.QueryKeyCommand)
		if cmd == "" {
			cmd = q.Get("_cmd")
		}
		switch api.Command(cmd) {
		case api.CommandAuthenticated:
			handleIsAuthenticated(ctx, w, ucIsAuth)
			return
		case api.CommandRefresh:
			err := ucRefresh.Run(ctx)
			if err != nil {
				a.reportUsecaseError(w, err)

Added web/adapter/api/get_lists.go.



































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//-----------------------------------------------------------------------------
// Copyright (c) 2020-2022 Detlef Stern
//
// This file is part of Zettelstore.
//
// Zettelstore is licensed under the latest version of the EUPL (European Union
// Public License). Please see file LICENSE.txt for your rights and obligations
// under this license.
//-----------------------------------------------------------------------------

package api

import (
	"bytes"
	"net/http"
	"strconv"

	"zettelstore.de/c/api"
	"zettelstore.de/z/domain/meta"
	"zettelstore.de/z/usecase"
)

// MakeListMapMetaHandler creates a new HTTP handler to retrieve mappings of
// metadata values of a specific key to the list of zettel IDs, which contain
// this value.
func (a *API) MakeListMapMetaHandler(listRole usecase.ListRoles, listTags usecase.ListTags) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		ctx := r.Context()
		var buf bytes.Buffer
		query := r.URL.Query()

		minVal := query.Get(api.QueryKeyMin)
		if minVal == "" {
			minVal = query.Get("_min")
		}
		iMinCount, err := strconv.Atoi(minVal)
		if err != nil || iMinCount < 0 {
			iMinCount = 0
		}
		key := query.Get(api.QueryKeyKey)
		if key == "" {
			key = query.Get("_key")
		}

		var ar meta.Arrangement
		switch key {
		case api.KeyRole:
			ar, err = listRole.Run(ctx)
		case api.KeyTags:
			ar, err = listTags.Run(ctx, iMinCount)
		default:
			a.log.Info().Str("key", key).Msg("illegal key for retrieving meta map")
			http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
			return
		}
		if err != nil {
			a.reportUsecaseError(w, err)
			return
		}

		mm := make(api.MapMeta, len(ar))
		for tag, metaList := range ar {
			zidList := make([]api.ZettelID, 0, len(metaList))
			for _, m := range metaList {
				zidList = append(zidList, api.ZettelID(m.Zid.String()))
			}
			mm[tag] = zidList
		}

		buf.Reset()
		err = encodeJSONData(&buf, api.MapListJSON{Map: mm})
		if err != nil {
			a.log.Fatal().Err(err).Msg("Unable to store map list in buffer")
			http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
			return
		}

		err = writeBuffer(w, &buf, ctJSON)
		a.log.IfErr(err).Str("key", key).Msg("write meta map")
	}
}

Changes to web/adapter/api/get_unlinked_refs.go.

39
40
41
42
43
44
45



46
47
48
49
50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65
		if err != nil {
			a.reportUsecaseError(w, err)
			return
		}

		que := r.URL.Query()
		phrase := que.Get(api.QueryKeyPhrase)



		if phrase == "" {
			if zmkTitle, found := zm.Get(api.KeyTitle); found {
				isTitle := evaluate.RunMetadata(ctx, zmkTitle)
				encdr := textenc.Create()
				var b strings.Builder
				_, err = encdr.WriteInlines(&b, &isTitle)
				if err == nil {
					phrase = b.String()
				}
			}
		}


		metaList, err := unlinkedRefs.Run(ctx, phrase, adapter.AddUnlinkedRefsToQuery(adapter.GetQuery(que), zm))
		if err != nil {
			a.reportUsecaseError(w, err)
			return
		}

		result := api.ZidMetaRelatedList{
			ID:     api.ZettelID(zid.String()),







>
>
>












>
|







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
		if err != nil {
			a.reportUsecaseError(w, err)
			return
		}

		que := r.URL.Query()
		phrase := que.Get(api.QueryKeyPhrase)
		if phrase == "" {
			phrase = que.Get("_phrase")
		}
		if phrase == "" {
			if zmkTitle, found := zm.Get(api.KeyTitle); found {
				isTitle := evaluate.RunMetadata(ctx, zmkTitle)
				encdr := textenc.Create()
				var b strings.Builder
				_, err = encdr.WriteInlines(&b, &isTitle)
				if err == nil {
					phrase = b.String()
				}
			}
		}

		metaList, err := unlinkedRefs.Run(
			ctx, phrase, adapter.AddUnlinkedRefsToQuery(adapter.GetQuery(que), zm))
		if err != nil {
			a.reportUsecaseError(w, err)
			return
		}

		result := api.ZidMetaRelatedList{
			ID:     api.ZettelID(zid.String()),

Changes to web/adapter/api/get_zettel_context.go.

25
26
27
28
29
30
31




32
33



34
35
36
37



38
39
40
41
42
43
44
	return func(w http.ResponseWriter, r *http.Request) {
		zid, err := id.Parse(r.URL.Path[1:])
		if err != nil {
			http.NotFound(w, r)
			return
		}
		q := r.URL.Query()




		dir := adapter.GetZCDirection(q.Get(api.QueryKeyDir))
		depth, ok := adapter.GetInteger(q, api.QueryKeyDepth)



		if !ok || depth < 0 {
			depth = 5
		}
		limit, ok := adapter.GetInteger(q, api.QueryKeyLimit)



		if !ok || limit < 0 {
			limit = 200
		}
		ctx := r.Context()
		metaList, err := getContext.Run(ctx, zid, dir, depth, limit)
		if err != nil {
			a.reportUsecaseError(w, err)







>
>
>
>
|

>
>
>




>
>
>







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
	return func(w http.ResponseWriter, r *http.Request) {
		zid, err := id.Parse(r.URL.Path[1:])
		if err != nil {
			http.NotFound(w, r)
			return
		}
		q := r.URL.Query()
		dirVal := q.Get(api.QueryKeyDir)
		if dirVal == "" {
			dirVal = q.Get("_dir")
		}
		dir := adapter.GetZCDirection(dirVal)
		depth, ok := adapter.GetInteger(q, api.QueryKeyDepth)
		if !ok {
			depth, ok = adapter.GetInteger(q, "_depth")
		}
		if !ok || depth < 0 {
			depth = 5
		}
		limit, ok := adapter.GetInteger(q, api.QueryKeyLimit)
		if !ok {
			limit, ok = adapter.GetInteger(q, "_limit")
		}
		if !ok || limit < 0 {
			limit = 200
		}
		ctx := r.Context()
		metaList, err := getContext.Run(ctx, zid, dir, depth, limit)
		if err != nil {
			a.reportUsecaseError(w, err)

Changes to web/adapter/api/get_zettel_list.go.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17

18
19
20





































21
22
23
24
25
26
27
//-----------------------------------------------------------------------------
// Copyright (c) 2020-2022 Detlef Stern
//
// This file is part of Zettelstore.
//
// Zettelstore is licensed under the latest version of the EUPL (European Union
// Public License). Please see file LICENSE.txt for your rights and obligations
// under this license.
//-----------------------------------------------------------------------------


package api

import (
	"bytes"
	"fmt"
	"net/http"


	"zettelstore.de/z/usecase"
	"zettelstore.de/z/web/adapter"
)






































// MakeListPlainHandler creates a new HTTP handler for the use case "list some zettel".
func (a *API) MakeListPlainHandler(listMeta usecase.ListMeta) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		ctx := r.Context()
		metaList, err := listMeta.Run(ctx, adapter.GetQuery(r.URL.Query()))
		if err != nil {










>







>



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//-----------------------------------------------------------------------------
// Copyright (c) 2020-2022 Detlef Stern
//
// This file is part of Zettelstore.
//
// Zettelstore is licensed under the latest version of the EUPL (European Union
// Public License). Please see file LICENSE.txt for your rights and obligations
// under this license.
//-----------------------------------------------------------------------------

// Package api provides api handlers for web requests.
package api

import (
	"bytes"
	"fmt"
	"net/http"

	"zettelstore.de/c/api"
	"zettelstore.de/z/usecase"
	"zettelstore.de/z/web/adapter"
)

// MakeListMetaHandler creates a new HTTP handler for the use case "list some zettel".
func (a *API) MakeListMetaHandler(listMeta usecase.ListMeta) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		ctx := r.Context()
		q := adapter.GetQuery(r.URL.Query())
		metaList, err := listMeta.Run(ctx, q)
		if err != nil {
			a.reportUsecaseError(w, err)
			return
		}

		result := make([]api.ZidMetaJSON, 0, len(metaList))
		for _, m := range metaList {
			result = append(result, api.ZidMetaJSON{
				ID:     api.ZettelID(m.Zid.String()),
				Meta:   m.Map(),
				Rights: a.getRights(ctx, m),
			})
		}

		var buf bytes.Buffer
		err = encodeJSONData(&buf, api.ZettelListJSON{
			Query: q.String(),
			Human: q.Human(),
			List:  result,
		})
		if err != nil {
			a.log.Fatal().Err(err).Msg("Unable to store meta list in buffer")
			http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
			return
		}

		err = writeBuffer(w, &buf, ctJSON)
		a.log.IfErr(err).Msg("Write JSON List")
	}
}

// MakeListPlainHandler creates a new HTTP handler for the use case "list some zettel".
func (a *API) MakeListPlainHandler(listMeta usecase.ListMeta) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		ctx := r.Context()
		metaList, err := listMeta.Run(ctx, adapter.GetQuery(r.URL.Query()))
		if err != nil {

Changes to web/adapter/api/query.go.

8
9
10
11
12
13
14
15
16
17
18
19
20
21

22
23
24
25
26
27
28
29
30
31
32




33



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// under this license.
//-----------------------------------------------------------------------------

package api

import (
	"bytes"
	"context"
	"io"
	"net/http"
	"strconv"
	"strings"

	"zettelstore.de/c/api"

	"zettelstore.de/z/domain/meta"
	"zettelstore.de/z/query"
	"zettelstore.de/z/usecase"
	"zettelstore.de/z/web/adapter"
)

// MakeQueryHandler creates a new HTTP handler to perform a query.
func (a *API) MakeQueryHandler(listMeta usecase.ListMeta) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		ctx := r.Context()
		q := adapter.GetQuery(r.URL.Query())








		metaList, err := listMeta.Run(ctx, q)
		if err != nil {
			a.reportUsecaseError(w, err)
			return
		}

		var buf bytes.Buffer
		contentType, err := a.queryAction(ctx, &buf, q, metaList)
		if err != nil {
			a.reportUsecaseError(w, err)
			return
		}
		err = writeBuffer(w, &buf, contentType)
		a.log.IfErr(err).Msg("write action")
	}
}

func (a *API) queryAction(ctx context.Context, w io.Writer, q *query.Query, ml []*meta.Meta) (string, error) {
	ap := actionPara{
		w:   w,
		q:   q,
		ml:  ml,
		min: -1,
		max: -1,
	}







<






>











>
>
>
>
|
>
>
>







|









|







8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// under this license.
//-----------------------------------------------------------------------------

package api

import (
	"bytes"

	"io"
	"net/http"
	"strconv"
	"strings"

	"zettelstore.de/c/api"
	"zettelstore.de/z/box"
	"zettelstore.de/z/domain/meta"
	"zettelstore.de/z/query"
	"zettelstore.de/z/usecase"
	"zettelstore.de/z/web/adapter"
)

// MakeQueryHandler creates a new HTTP handler to perform a query.
func (a *API) MakeQueryHandler(listMeta usecase.ListMeta) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		ctx := r.Context()
		q := adapter.GetQuery(r.URL.Query())
		if q == nil {
			a.log.Sense().Msg("no parameter for query")
			http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
			return
		}
		if !q.EnrichNeeded() {
			ctx = box.NoEnrichContext(ctx)
		}
		metaList, err := listMeta.Run(ctx, q)
		if err != nil {
			a.reportUsecaseError(w, err)
			return
		}

		var buf bytes.Buffer
		contentType, err := queryAction(&buf, q, metaList)
		if err != nil {
			a.reportUsecaseError(w, err)
			return
		}
		err = writeBuffer(w, &buf, contentType)
		a.log.IfErr(err).Msg("write action")
	}
}

func queryAction(w io.Writer, q *query.Query, ml []*meta.Meta) (string, error) {
	ap := actionPara{
		w:   w,
		q:   q,
		ml:  ml,
		min: -1,
		max: -1,
	}
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
			key := strings.ToLower(act)
			switch meta.Type(key) {
			case meta.TypeWord, meta.TypeTagSet:
				return ap.createMapMeta(key)
			}
		}
	}
	err := a.writeQueryMetaList(ctx, w, q, ml)
	return ctJSON, err
}

type actionPara struct {
	w   io.Writer
	q   *query.Query
	ml  []*meta.Meta
	min int







<
|







84
85
86
87
88
89
90

91
92
93
94
95
96
97
98
			key := strings.ToLower(act)
			switch meta.Type(key) {
			case meta.TypeWord, meta.TypeTagSet:
				return ap.createMapMeta(key)
			}
		}
	}

	return "", nil
}

type actionPara struct {
	w   io.Writer
	q   *query.Query
	ml  []*meta.Meta
	min int
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
		}
		mm[tag] = zidList
	}

	err := encodeJSONData(ap.w, api.MapListJSON{Map: mm})
	return ctJSON, err
}

func (a *API) writeQueryMetaList(ctx context.Context, w io.Writer, q *query.Query, ml []*meta.Meta) error {
	result := make([]api.ZidMetaJSON, 0, len(ml))
	for _, m := range ml {
		result = append(result, api.ZidMetaJSON{
			ID:     api.ZettelID(m.Zid.String()),
			Meta:   m.Map(),
			Rights: a.getRights(ctx, m),
		})
	}

	err := encodeJSONData(w, api.ZettelListJSON{
		Query: q.String(),
		Human: q.Human(),
		List:  result,
	})
	return err
}







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
119
120
121
122
123
124
125


















		}
		mm[tag] = zidList
	}

	err := encodeJSONData(ap.w, api.MapListJSON{Map: mm})
	return ctJSON, err
}


















Changes to web/adapter/api/request.go.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27



28
29
30
31
32
33
34
//-----------------------------------------------------------------------------
// Copyright (c) 2020-2022 Detlef Stern
//
// This file is part of Zettelstore.
//
// Zettelstore is licensed under the latest version of the EUPL (European Union
// Public License). Please see file LICENSE.txt for your rights and obligations
// under this license.
//-----------------------------------------------------------------------------


package api

import (
	"io"
	"net/http"
	"net/url"

	"zettelstore.de/c/api"
	"zettelstore.de/z/domain"
	"zettelstore.de/z/domain/id"
	"zettelstore.de/z/domain/meta"
	"zettelstore.de/z/input"
)

// getEncoding returns the data encoding selected by the caller.
func getEncoding(r *http.Request, q url.Values, defEncoding api.EncodingEnum) (api.EncodingEnum, string) {
	encoding := q.Get(api.QueryKeyEncoding)



	if encoding != "" {
		return api.Encoder(encoding), encoding
	}
	if enc, ok := getOneEncoding(r, api.HeaderAccept); ok {
		return api.Encoder(enc), enc
	}
	if enc, ok := getOneEncoding(r, api.HeaderContentType); ok {










>

















>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//-----------------------------------------------------------------------------
// Copyright (c) 2020-2022 Detlef Stern
//
// This file is part of Zettelstore.
//
// Zettelstore is licensed under the latest version of the EUPL (European Union
// Public License). Please see file LICENSE.txt for your rights and obligations
// under this license.
//-----------------------------------------------------------------------------

// Package api provides api handlers for web requests.
package api

import (
	"io"
	"net/http"
	"net/url"

	"zettelstore.de/c/api"
	"zettelstore.de/z/domain"
	"zettelstore.de/z/domain/id"
	"zettelstore.de/z/domain/meta"
	"zettelstore.de/z/input"
)

// getEncoding returns the data encoding selected by the caller.
func getEncoding(r *http.Request, q url.Values, defEncoding api.EncodingEnum) (api.EncodingEnum, string) {
	encoding := q.Get(api.QueryKeyEncoding)
	if encoding == "" {
		encoding = q.Get("_enc")
	}
	if encoding != "" {
		return api.Encoder(encoding), encoding
	}
	if enc, ok := getOneEncoding(r, api.HeaderAccept); ok {
		return api.Encoder(enc), enc
	}
	if enc, ok := getOneEncoding(r, api.HeaderContentType); ok {
73
74
75
76
77
78
79



80
81
82
83
84
85
86
	api.PartContent: partContent,
	api.PartZettel:  partZettel,
}

func getPart(q url.Values, defPart partType) partType {
	if part, ok := partMap[q.Get(api.QueryKeyPart)]; ok {
		return part



	}
	return defPart
}

func (p partType) String() string {
	switch p {
	case partMeta:







>
>
>







77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
	api.PartContent: partContent,
	api.PartZettel:  partZettel,
}

func getPart(q url.Values, defPart partType) partType {
	if part, ok := partMap[q.Get(api.QueryKeyPart)]; ok {
		return part
	}
	if part, ok := partMap[q.Get("_part")]; ok {
		return part
	}
	return defPart
}

func (p partType) String() string {
	switch p {
	case partMeta:

Changes to web/adapter/request.go.

51
52
53
54
55
56
57



58
59
60
61
62
63
64
}

// GetQuery retrieves the specified options from a query.
func GetQuery(vals url.Values) *query.Query {
	if exprs, found := vals[api.QueryKeyQuery]; found {
		return query.Parse(strings.Join(exprs, " "))
	}



	return nil
}

// GetZCDirection returns a direction value for a given string.
func GetZCDirection(s string) usecase.ZettelContextDirection {
	switch s {
	case api.DirBackward:







>
>
>







51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
}

// GetQuery retrieves the specified options from a query.
func GetQuery(vals url.Values) *query.Query {
	if exprs, found := vals[api.QueryKeyQuery]; found {
		return query.Parse(strings.Join(exprs, " "))
	}
	if exprs, found := vals["_s"]; found {
		return query.Parse(strings.Join(exprs, " "))
	}
	return nil
}

// GetZCDirection returns a direction value for a given string.
func GetZCDirection(s string) usecase.ZettelContextDirection {
	switch s {
	case api.DirBackward:

Changes to web/adapter/webui/get_zettel.go.

141
142
143
144
145
146
147
148
149
150
151
152
153
154
155

func (wui *WebUI) buildTagInfos(m *meta.Meta) []simpleLink {
	var tagInfos []simpleLink
	if tags, ok := m.GetList(api.KeyTags); ok {
		ub := wui.NewURLBuilder('h')
		tagInfos = make([]simpleLink, len(tags))
		for i, tag := range tags {
			tagInfos[i] = simpleLink{Text: tag, URL: ub.AppendQuery(api.KeyTags + api.SearchOperatorHas + tag).String()}
			ub.ClearQuery()
		}
	}
	return tagInfos
}

func (wui *WebUI) encodeIdentifierSet(m *meta.Meta, key string, getTextTitle getTextTitleFunc) string {







|







141
142
143
144
145
146
147
148
149
150
151
152
153
154
155

func (wui *WebUI) buildTagInfos(m *meta.Meta) []simpleLink {
	var tagInfos []simpleLink
	if tags, ok := m.GetList(api.KeyTags); ok {
		ub := wui.NewURLBuilder('h')
		tagInfos = make([]simpleLink, len(tags))
		for i, tag := range tags {
			tagInfos[i] = simpleLink{Text: tag, URL: ub.AppendQuery(api.KeyAllTags + api.SearchOperatorHas + tag).String()}
			ub.ClearQuery()
		}
	}
	return tagInfos
}

func (wui *WebUI) encodeIdentifierSet(m *meta.Meta, key string, getTextTitle getTextTitleFunc) string {

Changes to web/adapter/webui/htmlgen.go.

45
46
47
48
49
50
51

52
53
54
55
56
57
58
	gen := &htmlGenerator{
		builder:   builder,
		textEnc:   textenc.Create(),
		extMarker: extMarker,
		env:       env,
	}


	env.Builtins.Set(sexpr.SymLinkZettel, sxpf.NewBuiltin("linkZ", true, 2, -1, gen.generateLinkZettel))
	env.Builtins.Set(sexpr.SymLinkFound, sxpf.NewBuiltin("linkZ", true, 2, -1, gen.generateLinkZettel))
	env.Builtins.Set(sexpr.SymLinkBased, sxpf.NewBuiltin("linkB", true, 2, -1, gen.generateLinkBased))
	env.Builtins.Set(sexpr.SymLinkQuery, sxpf.NewBuiltin("linkQ", true, 2, -1, gen.generateLinkQuery))
	env.Builtins.Set(sexpr.SymLinkExternal, sxpf.NewBuiltin("linkE", true, 2, -1, gen.generateLinkExternal))

	f, err := env.Builtins.LookupForm(sexpr.SymEmbed)







>







45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
	gen := &htmlGenerator{
		builder:   builder,
		textEnc:   textenc.Create(),
		extMarker: extMarker,
		env:       env,
	}

	env.Builtins.Set(sexpr.SymTag, sxpf.NewBuiltin("tag", true, 0, -1, gen.generateTag))
	env.Builtins.Set(sexpr.SymLinkZettel, sxpf.NewBuiltin("linkZ", true, 2, -1, gen.generateLinkZettel))
	env.Builtins.Set(sexpr.SymLinkFound, sxpf.NewBuiltin("linkZ", true, 2, -1, gen.generateLinkZettel))
	env.Builtins.Set(sexpr.SymLinkBased, sxpf.NewBuiltin("linkB", true, 2, -1, gen.generateLinkBased))
	env.Builtins.Set(sexpr.SymLinkQuery, sxpf.NewBuiltin("linkQ", true, 2, -1, gen.generateLinkQuery))
	env.Builtins.Set(sexpr.SymLinkExternal, sxpf.NewBuiltin("linkE", true, 2, -1, gen.generateLinkExternal))

	f, err := env.Builtins.LookupForm(sexpr.SymEmbed)
69
70
71
72
73
74
75
76




77
78
79
80
81
82
83
	api.KeyLicense:   "license",
}

func (g *htmlGenerator) MetaString(m *meta.Meta, evalMeta encoder.EvalMetaFunc) string {
	ignore := strfun.NewSet(api.KeyTitle, api.KeyLang)
	var buf bytes.Buffer

	if tags, ok := m.Get(api.KeyTags); ok {




		writeMetaTags(&buf, tags)
		ignore.Set(api.KeyTags)
	}

	for _, p := range m.ComputedPairs() {
		key := p.Key
		if ignore.Has(key) {







|
>
>
>
>







70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
	api.KeyLicense:   "license",
}

func (g *htmlGenerator) MetaString(m *meta.Meta, evalMeta encoder.EvalMetaFunc) string {
	ignore := strfun.NewSet(api.KeyTitle, api.KeyLang)
	var buf bytes.Buffer

	if tags, ok := m.Get(api.KeyAllTags); ok {
		writeMetaTags(&buf, tags)
		ignore.Set(api.KeyAllTags)
		ignore.Set(api.KeyTags)
	} else if tags, ok = m.Get(api.KeyTags); ok {
		writeMetaTags(&buf, tags)
		ignore.Set(api.KeyTags)
	}

	for _, p := range m.ComputedPairs() {
		key := p.Key
		if ignore.Has(key) {
129
130
131
132
133
134
135
















136
137
138
139
140
141
142
// InlinesString writes an inline slice to the writer
func (g *htmlGenerator) InlinesString(is *ast.InlineSlice) (string, error) {
	if is == nil || len(*is) == 0 {
		return "", nil
	}
	return html.EvaluateInline(g.env, sexprenc.GetSexpr(is), true, false), nil
}

















func (g *htmlGenerator) generateLinkZettel(senv sxpf.Environment, args *sxpf.Pair, _ int) (sxpf.Value, error) {
	env := senv.(*html.EncEnvironment)
	if a, refValue, ok := html.PrepareLink(env, args); ok {
		zid, fragment, hasFragment := strings.Cut(refValue, "#")
		u := g.builder.NewURLBuilder('h').SetZid(api.ZettelID(zid))
		if hasFragment {







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// InlinesString writes an inline slice to the writer
func (g *htmlGenerator) InlinesString(is *ast.InlineSlice) (string, error) {
	if is == nil || len(*is) == 0 {
		return "", nil
	}
	return html.EvaluateInline(g.env, sexprenc.GetSexpr(is), true, false), nil
}

func (g *htmlGenerator) generateTag(senv sxpf.Environment, args *sxpf.Pair, _ int) (sxpf.Value, error) {
	if !sxpf.IsNil(args) {
		env := senv.(*html.EncEnvironment)
		s := env.GetString(args)
		if env.IgnoreLinks() {
			env.WriteEscaped(s)
		} else {
			u := g.builder.NewURLBuilder('h').AppendQuery(api.KeyAllTags + ":#" + strings.ToLower(s))
			env.WriteStrings(`<a href="`, u.String(), `">#`)
			env.WriteEscaped(s)
			env.WriteString("</a>")
		}
	}
	return nil, nil
}

func (g *htmlGenerator) generateLinkZettel(senv sxpf.Environment, args *sxpf.Pair, _ int) (sxpf.Value, error) {
	env := senv.(*html.EncEnvironment)
	if a, refValue, ok := html.PrepareLink(env, args); ok {
		zid, fragment, hasFragment := strings.Cut(refValue, "#")
		u := g.builder.NewURLBuilder('h').SetZid(api.ZettelID(zid))
		if hasFragment {

Changes to web/adapter/webui/webui.go.

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

		tokenLifetime: kernel.Main.GetConfig(kernel.WebService, kernel.WebTokenLifetimeHTML).(time.Duration),
		cssBaseURL:    ab.NewURLBuilder('z').SetZid(api.ZidBaseCSS).String(),
		cssUserURL:    ab.NewURLBuilder('z').SetZid(api.ZidUserCSS).String(),
		homeURL:       ab.NewURLBuilder('/').String(),
		listZettelURL: ab.NewURLBuilder('h').String(),
		listRolesURL:  ab.NewURLBuilder('h').AppendQuery(api.ActionSeparator + api.KeyRole).String(),
		listTagsURL:   ab.NewURLBuilder('h').AppendQuery(api.ActionSeparator + api.KeyTags).String(),
		refreshURL:    ab.NewURLBuilder('g').AppendKVQuery("_c", "r").String(),
		withAuth:      authz.WithAuth(),
		loginURL:      loginoutBase.String(),
		logoutURL:     loginoutBase.AppendKVQuery("logout", "").String(),
		searchURL:     ab.NewURLBuilder('h').String(),
	}
	wui.observe(box.UpdateInfo{Box: mgr, Reason: box.OnReload, Zid: id.Invalid})







|







96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

		tokenLifetime: kernel.Main.GetConfig(kernel.WebService, kernel.WebTokenLifetimeHTML).(time.Duration),
		cssBaseURL:    ab.NewURLBuilder('z').SetZid(api.ZidBaseCSS).String(),
		cssUserURL:    ab.NewURLBuilder('z').SetZid(api.ZidUserCSS).String(),
		homeURL:       ab.NewURLBuilder('/').String(),
		listZettelURL: ab.NewURLBuilder('h').String(),
		listRolesURL:  ab.NewURLBuilder('h').AppendQuery(api.ActionSeparator + api.KeyRole).String(),
		listTagsURL:   ab.NewURLBuilder('h').AppendQuery(api.ActionSeparator + api.KeyAllTags).String(),
		refreshURL:    ab.NewURLBuilder('g').AppendKVQuery("_c", "r").String(),
		withAuth:      authz.WithAuth(),
		loginURL:      loginoutBase.String(),
		logoutURL:     loginoutBase.AppendKVQuery("logout", "").String(),
		searchURL:     ab.NewURLBuilder('h').String(),
	}
	wui.observe(box.UpdateInfo{Box: mgr, Reason: box.OnReload, Zid: id.Invalid})

Changes to www/changes.wiki.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<title>Change Log</title>

<a name="0_8"></a>
<h2>Changes for Version 0.8.0 (pending)</h2>
  *  Remove support for tags within zettel content. Removes also property
     metadata keys <tt>all-tags</tt> and <tt>computed-tags</tt>. Deprecated in
     version 0.7.0.
     (breaking: zettelmarkup, api, webui)
  *  Remove API endpoint <tt>/m</tt>, which retrieve aggregated (tags, roles)
     zettel identifier. Deprecated in version 0.7.0.
     (breaking: api)
  *  Remove support for URL query parameter starting with an underscore.
     Deprecated in version 0.7.0.
     (breaking: api, webui)
  *  Endpoint <tt>/q</tt> returns list of full metadata, if no query action is
     specified. A HTTP call <tt>GET /z</tt> (retrieving metadata of all or some
     zettel) is now an alias for <tt>GET /q</tt>.
     (major: api)
  *  Allow transclusion to reference local image via URL.
     (minor: zettelmarkup)
  *  Ignore entities with code point that is not allowed in HTML.
     (minor: zettelmarkup)

<a name="0_7"></a>
<h2>Changes for Version 0.7.1 (2022-09-18)</h2>
  *  Produce a RSS feed compatible to Miniflux.
     (minor)
  *  Make sure to always produce a pubdata in RSS feed.
     (bug)
  *  Prefix search for data that looks like a zettel identifier may end with a
     <tt>0</tt>.
     (bug)
  *  Fix glitch on manual zettel.
     (bug)

<h2>Changes for Version 0.7.0 (2022-09-17)</h2>
  *  Removes support for URL query parameter to search for metadata values,
     sorting, offset, and limit a zettel list. Deprecated in version 0.6.0
     (breaking: api, webui)
  *  Allow to search for the existence / non-existence of a metadata key with
     the "?" operator: <tt>key?</tt> and <tt>key!?</tt>. Previously, the ":"
     operator was used for this by specifying an empty search value. Now you
     can use the ":" operator to find empty / non-empty metadata values. If you



|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


<
<
<
<
<
<
<
<
<
<
<
|







1
2
3
4


















5
6











7
8
9
10
11
12
13
14
<title>Change Log</title>

<a name="0_8"></a>
<h2>Changes for Version 0.8.0 (2022-09-17)</h2>



















<a name="0_7"></a>











<h2>Changes for Version 0.7.0 (pending)</h2>
  *  Removes support for URL query parameter to search for metadata values,
     sorting, offset, and limit a zettel list. Deprecated in version 0.6.0
     (breaking: api, webui)
  *  Allow to search for the existence / non-existence of a metadata key with
     the "?" operator: <tt>key?</tt> and <tt>key!?</tt>. Previously, the ":"
     operator was used for this by specifying an empty search value. Now you
     can use the ":" operator to find empty / non-empty metadata values. If you

Changes to www/download.wiki.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<title>Download</title>
<h1>Download of Zettelstore Software</h1>
<h2>Foreword</h2>
  *  Zettelstore is free/libre open source software, licensed under EUPL-1.2-or-later.
  *  The software is provided as-is.
  *  There is no guarantee that it will not damage your system.
  *  However, it is in use by the main developer since March 2020 without any damage.
  *  It may be useful for you. It is useful for me.
  *  Take a look at the [https://zettelstore.de/manual/|manual] to know how to start and use it.

<h2>ZIP-ped Executables</h2>
Build: <code>v0.7.1</code> (2022-09-18).

  *  [/uv/zettelstore-0.7.1-linux-amd64.zip|Linux] (amd64)
  *  [/uv/zettelstore-0.7.1-linux-arm.zip|Linux] (arm6, e.g. Raspberry Pi)
  *  [/uv/zettelstore-0.7.1-windows-amd64.zip|Windows] (amd64)
  *  [/uv/zettelstore-0.7.1-darwin-amd64.zip|macOS] (amd64)
  *  [/uv/zettelstore-0.7.1-darwin-arm64.zip|macOS] (arm64, aka Apple silicon)

Unzip the appropriate file, install and execute Zettelstore according to the manual.

<h2>Zettel for the manual</h2>
As a starter, you can download the zettel for the manual
[/uv/manual-0.7.0.zip|here].
Just unzip the contained files and put them into your zettel folder or
configure a file box to read the zettel directly from the ZIP file.











|

|
|
|
|
|








1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<title>Download</title>
<h1>Download of Zettelstore Software</h1>
<h2>Foreword</h2>
  *  Zettelstore is free/libre open source software, licensed under EUPL-1.2-or-later.
  *  The software is provided as-is.
  *  There is no guarantee that it will not damage your system.
  *  However, it is in use by the main developer since March 2020 without any damage.
  *  It may be useful for you. It is useful for me.
  *  Take a look at the [https://zettelstore.de/manual/|manual] to know how to start and use it.

<h2>ZIP-ped Executables</h2>
Build: <code>v0.7.0</code> (2022-09-17).

  *  [/uv/zettelstore-0.7.0-linux-amd64.zip|Linux] (amd64)
  *  [/uv/zettelstore-0.7.0-linux-arm.zip|Linux] (arm6, e.g. Raspberry Pi)
  *  [/uv/zettelstore-0.7.0-windows-amd64.zip|Windows] (amd64)
  *  [/uv/zettelstore-0.7.0-darwin-amd64.zip|macOS] (amd64)
  *  [/uv/zettelstore-0.7.0-darwin-arm64.zip|macOS] (arm64, aka Apple silicon)

Unzip the appropriate file, install and execute Zettelstore according to the manual.

<h2>Zettel for the manual</h2>
As a starter, you can download the zettel for the manual
[/uv/manual-0.7.0.zip|here].
Just unzip the contained files and put them into your zettel folder or
configure a file box to read the zettel directly from the ZIP file.

Changes to www/index.wiki.

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
access Zettelstore via its API more easily,
[https://zettelstore.de/contrib|Zettelstore Contrib] contains contributed
software, which often connects to Zettelstore via its API. Some of the software
packages may be experimental.

[https://twitter.com/zettelstore|Stay tuned]&nbsp;&hellip;
<hr>
<h3>Latest Release: 0.7.1 (2022-09-18)</h3>
  *  [./download.wiki|Download]
  *  [./changes.wiki#0_7|Change summary]
  *  [/timeline?p=v0.7.1&bt=v0.6.0&y=ci|Check-ins for version 0.7.1],
     [/vdiff?to=v0.7.1&from=v0.6.0|content diff]
  *  [/timeline?df=v0.7.0&y=ci|Check-ins derived from the 0.7.0 release],
     [/vdiff?from=v0.7.0&to=trunk|content diff]
  *  [./plan.wiki|Limitations and planned improvements]
  *  [/timeline?t=release|Timeline of all past releases]

<hr>
<h2>Build instructions</h2>
Just install [https://golang.org/dl/|Go] and some Go-based tools. Please read
the [./build.md|instructions] for details.

  *  [/dir?ci=trunk|Source code]
  *  [/download|Download the source code] as a tarball or a ZIP file
     (you must [/login|login] as user &quot;anonymous&quot;).







|


|
|













20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
access Zettelstore via its API more easily,
[https://zettelstore.de/contrib|Zettelstore Contrib] contains contributed
software, which often connects to Zettelstore via its API. Some of the software
packages may be experimental.

[https://twitter.com/zettelstore|Stay tuned]&nbsp;&hellip;
<hr>
<h3>Latest Release: 0.7.0 (2022-09-17)</h3>
  *  [./download.wiki|Download]
  *  [./changes.wiki#0_7|Change summary]
  *  [/timeline?p=v0.7.0&bt=v0.6.0&y=ci|Check-ins for version 0.7.0],
     [/vdiff?to=v0.7.0&from=v0.6.0|content diff]
  *  [/timeline?df=v0.7.0&y=ci|Check-ins derived from the 0.7.0 release],
     [/vdiff?from=v0.7.0&to=trunk|content diff]
  *  [./plan.wiki|Limitations and planned improvements]
  *  [/timeline?t=release|Timeline of all past releases]

<hr>
<h2>Build instructions</h2>
Just install [https://golang.org/dl/|Go] and some Go-based tools. Please read
the [./build.md|instructions] for details.

  *  [/dir?ci=trunk|Source code]
  *  [/download|Download the source code] as a tarball or a ZIP file
     (you must [/login|login] as user &quot;anonymous&quot;).