Zettelstore Client

Check-in Differences
Login

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

Difference From v0.6.0 To trunk

2022-09-17
17:13
Remove unneeded URL query parameter ... (Leaf check-in: 5fcf178ef5 user: stern tags: trunk)
15:33
Remove support for inline / content tags ... (check-in: 425d4ee831 user: stern tags: trunk)
2022-08-12
11:25
Remove constants to work with URL query parameter based search; update API to use search expressions ... (check-in: 0e4cf52fe7 user: stern tags: trunk)
2022-08-11
16:58
Version 0.6.0 ... (check-in: 7ef11c70e3 user: stern tags: trunk, release, v0.6.0)
08:53
Typo ... (check-in: 6f9ea3ec0b user: stern tags: trunk)

Changes to api/const.go.

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
	ZidListTemplate    = ZettelID("00000000010300")
	ZidZettelTemplate  = ZettelID("00000000010401")
	ZidInfoTemplate    = ZettelID("00000000010402")
	ZidFormTemplate    = ZettelID("00000000010403")
	ZidRenameTemplate  = ZettelID("00000000010404")
	ZidDeleteTemplate  = ZettelID("00000000010405")
	ZidContextTemplate = ZettelID("00000000010406")
	ZidRolesTemplate   = ZettelID("00000000010500")
	ZidTagsTemplate    = ZettelID("00000000010600")
	ZidErrorTemplate   = ZettelID("00000000010700")

	// CSS-related zettel are in the range 20000..29999
	ZidBaseCSS    = ZettelID("00000000020001")
	ZidUserCSS    = ZettelID("00000000025001")
	ZidRoleCSSMap = ZettelID("00000000029000") // Maps roles to CSS zettel, which should be in the range 29001..29999.








<
<







34
35
36
37
38
39
40


41
42
43
44
45
46
47
	ZidListTemplate    = ZettelID("00000000010300")
	ZidZettelTemplate  = ZettelID("00000000010401")
	ZidInfoTemplate    = ZettelID("00000000010402")
	ZidFormTemplate    = ZettelID("00000000010403")
	ZidRenameTemplate  = ZettelID("00000000010404")
	ZidDeleteTemplate  = ZettelID("00000000010405")
	ZidContextTemplate = ZettelID("00000000010406")


	ZidErrorTemplate   = ZettelID("00000000010700")

	// CSS-related zettel are in the range 20000..29999
	ZidBaseCSS    = ZettelID("00000000020001")
	ZidUserCSS    = ZettelID("00000000025001")
	ZidRoleCSSMap = ZettelID("00000000029000") // Maps roles to CSS zettel, which should be in the range 29001..29999.

82
83
84
85
86
87
88
89
90
91
92
93
94

95
96
97
98
99
100
101
// Predefined general Metadata keys
const (
	KeyID           = "id"
	KeyTitle        = "title"
	KeyRole         = "role"
	KeyTags         = "tags"
	KeySyntax       = "syntax"
	KeyAllTags      = "all-" + KeyTags
	KeyBack         = "back"
	KeyBackward     = "backward"
	KeyBoxNumber    = "box-number"
	KeyContentTags  = "content-" + KeyTags
	KeyCopyright    = "copyright"

	KeyCredential   = "credential"
	KeyDead         = "dead"
	KeyFolge        = "folge"
	KeyForward      = "forward"
	KeyLang         = "lang"
	KeyLicense      = "license"
	KeyModified     = "modified"







|



<

>







80
81
82
83
84
85
86
87
88
89
90

91
92
93
94
95
96
97
98
99
// Predefined general Metadata keys
const (
	KeyID           = "id"
	KeyTitle        = "title"
	KeyRole         = "role"
	KeyTags         = "tags"
	KeySyntax       = "syntax"
	KeyAuthor       = "author"
	KeyBack         = "back"
	KeyBackward     = "backward"
	KeyBoxNumber    = "box-number"

	KeyCopyright    = "copyright"
	KeyCreated      = "created"
	KeyCredential   = "credential"
	KeyDead         = "dead"
	KeyFolge        = "folge"
	KeyForward      = "forward"
	KeyLang         = "lang"
	KeyLicense      = "license"
	KeyModified     = "modified"
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
	HeaderContentType = "Content-Type"
	HeaderDestination = "Destination"
	HeaderLocation    = "Location"
)

// Values for HTTP query parameter.
const (
	QueryKeyCommand  = "_cmd"
	QueryKeyDepth    = "_depth"
	QueryKeyDir      = "_dir"
	QueryKeyEncoding = "_enc"
	QueryKeyKey      = "_key"
	QueryKeyLimit    = "_limit"
	QueryKeyMin      = "_min"
	QueryKeyNegate   = "_negate"
	QueryKeyOffset   = "_offset"
	QueryKeyOrder    = "_order"
	QueryKeyPart     = "_part"
	QueryKeyPhrase   = "_phrase"
	QueryKeySearch   = "_s"
	QueryKeySort     = "_sort"
)

// Supported dir values.
const (
	DirBackward = "backward"
	DirForward  = "forward"
)







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







140
141
142
143
144
145
146
147
148
149
150

151




152
153
154

155
156
157
158
159
160
161
	HeaderContentType = "Content-Type"
	HeaderDestination = "Destination"
	HeaderLocation    = "Location"
)

// Values for HTTP query parameter.
const (
	QueryKeyCommand  = "cmd"
	QueryKeyDepth    = "depth"
	QueryKeyDir      = "dir"
	QueryKeyEncoding = "enc"

	QueryKeyLimit    = "limit"




	QueryKeyPart     = "part"
	QueryKeyPhrase   = "phrase"
	QueryKeyQuery    = "q"

)

// Supported dir values.
const (
	DirBackward = "backward"
	DirForward  = "forward"
)
232
233
234
235
236
237
238
















type Command string

// Supported command values
const (
	CommandAuthenticated = Command("authenticated")
	CommandRefresh       = Command("refresh")
)























>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
type Command string

// Supported command values
const (
	CommandAuthenticated = Command("authenticated")
	CommandRefresh       = Command("refresh")
)

// Supported search operator representations
const (
	ActionSeparator        = "|"
	ExistOperator          = "?"
	ExistNotOperator       = "!?"
	SearchOperatorNot      = "!"
	SearchOperatorHas      = ":"
	SearchOperatorHasNot   = "!:"
	SearchOperatorPrefix   = ">"
	SearchOperatorNoPrefix = "!>"
	SearchOperatorSuffix   = "<"
	SearchOperatorNoSuffix = "!<"
	SearchOperatorMatch    = "~"
	SearchOperatorNoMatch  = "!~"
)

Changes to api/urlbuilder.go.

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
	}
	if p != "" {
		ub.path = append(ub.path, p)
	}
	return ub
}

// AppendQuery adds a new query parameter
func (ub *URLBuilder) AppendQuery(key, value string) *URLBuilder {
	ub.rawLocal = ""
	ub.query = append(ub.query, urlQuery{key, value})
	return ub
}

// AppendSearch adds a new search
func (ub *URLBuilder) AppendSearch(value string) *URLBuilder {
	ub.rawLocal = ""
	ub.query = append(ub.query, urlQuery{QueryKeySearch, value})
	return ub
}

// ClearQuery removes all query parameters.
func (ub *URLBuilder) ClearQuery() *URLBuilder {
	ub.rawLocal = ""
	ub.query = nil







|
|





|
|

|







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
	}
	if p != "" {
		ub.path = append(ub.path, p)
	}
	return ub
}

// AppendKVQuery adds a new key/value query parameter
func (ub *URLBuilder) AppendKVQuery(key, value string) *URLBuilder {
	ub.rawLocal = ""
	ub.query = append(ub.query, urlQuery{key, value})
	return ub
}

// AppendQuery adds a new query
func (ub *URLBuilder) AppendQuery(value string) *URLBuilder {
	ub.rawLocal = ""
	ub.query = append(ub.query, urlQuery{QueryKeyQuery, value})
	return ub
}

// ClearQuery removes all query parameters.
func (ub *URLBuilder) ClearQuery() *URLBuilder {
	ub.rawLocal = ""
	ub.query = nil

Changes to client/client.go.

262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
	enc.SetEscapeHTML(false)
	return enc.Encode(&data)
}

var bsLF = []byte{'\n'}

// ListZettel returns a list of all Zettel.
func (c *Client) ListZettel(ctx context.Context, query url.Values) ([][]byte, error) {
	ub := c.newQueryURLBuilder('z', query)
	resp, err := c.buildAndExecuteRequest(ctx, http.MethodGet, ub, nil, nil)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		return nil, statusToError(resp)
	}
	data, err := io.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	lines := bytes.Split(data, bsLF)
	if len(lines[len(lines)-1]) == 0 {
		lines = lines[:len(lines)-1]
	}
	return lines, nil
}

// ListZettelJSON returns a list of zettel.
func (c *Client) ListZettelJSON(ctx context.Context, query url.Values) (string, string, []api.ZidMetaJSON, error) {
	ub := c.newQueryURLBuilder('j', query)
	resp, err := c.buildAndExecuteRequest(ctx, http.MethodGet, ub, nil, nil)
	if err != nil {
		return "", "", nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		return "", "", nil, statusToError(resp)







|
|




















|
|







262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
	enc.SetEscapeHTML(false)
	return enc.Encode(&data)
}

var bsLF = []byte{'\n'}

// ListZettel returns a list of all Zettel.
func (c *Client) ListZettel(ctx context.Context, query string) ([][]byte, error) {
	ub := c.newURLBuilder('z').AppendQuery(query)
	resp, err := c.buildAndExecuteRequest(ctx, http.MethodGet, ub, nil, nil)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		return nil, statusToError(resp)
	}
	data, err := io.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	lines := bytes.Split(data, bsLF)
	if len(lines[len(lines)-1]) == 0 {
		lines = lines[:len(lines)-1]
	}
	return lines, nil
}

// ListZettelJSON returns a list of zettel.
func (c *Client) ListZettelJSON(ctx context.Context, query string) (string, string, []api.ZidMetaJSON, error) {
	ub := c.newURLBuilder('j').AppendQuery(query)
	resp, err := c.buildAndExecuteRequest(ctx, http.MethodGet, ub, nil, nil)
	if err != nil {
		return "", "", nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		return "", "", nil, statusToError(resp)
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
	return zl.Query, zl.Human, zl.List, nil
}

// GetZettel returns a zettel as a string.
func (c *Client) GetZettel(ctx context.Context, zid api.ZettelID, part string) ([]byte, error) {
	ub := c.newURLBuilder('z').SetZid(zid)
	if part != "" && part != api.PartContent {
		ub.AppendQuery(api.QueryKeyPart, part)
	}
	resp, err := c.buildAndExecuteRequest(ctx, http.MethodGet, ub, nil, nil)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {







|







307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
	return zl.Query, zl.Human, zl.List, nil
}

// GetZettel returns a zettel as a string.
func (c *Client) GetZettel(ctx context.Context, zid api.ZettelID, part string) ([]byte, error) {
	ub := c.newURLBuilder('z').SetZid(zid)
	if part != "" && part != api.PartContent {
		ub.AppendKVQuery(api.QueryKeyPart, part)
	}
	resp, err := c.buildAndExecuteRequest(ctx, http.MethodGet, ub, nil, nil)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
// GetEvaluatedZettel return an evaluated zettel in a defined encoding.
func (c *Client) GetEvaluatedZettel(ctx context.Context, zid api.ZettelID, enc api.EncodingEnum) ([]byte, error) {
	return c.getZettelString(ctx, 'v', zid, enc)
}

func (c *Client) getZettelString(ctx context.Context, key byte, zid api.ZettelID, enc api.EncodingEnum) ([]byte, error) {
	ub := c.newURLBuilder(key).SetZid(zid)
	ub.AppendQuery(api.QueryKeyEncoding, enc.String())
	ub.AppendQuery(api.QueryKeyPart, api.PartContent)
	resp, err := c.buildAndExecuteRequest(ctx, http.MethodGet, ub, nil, nil)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		return nil, statusToError(resp)







|
|







352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
// GetEvaluatedZettel return an evaluated zettel in a defined encoding.
func (c *Client) GetEvaluatedZettel(ctx context.Context, zid api.ZettelID, enc api.EncodingEnum) ([]byte, error) {
	return c.getZettelString(ctx, 'v', zid, enc)
}

func (c *Client) getZettelString(ctx context.Context, key byte, zid api.ZettelID, enc api.EncodingEnum) ([]byte, error) {
	ub := c.newURLBuilder(key).SetZid(zid)
	ub.AppendKVQuery(api.QueryKeyEncoding, enc.String())
	ub.AppendKVQuery(api.QueryKeyPart, api.PartContent)
	resp, err := c.buildAndExecuteRequest(ctx, http.MethodGet, ub, nil, nil)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		return nil, statusToError(resp)
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
// GetEvaluatedZettelZJSON returns an evaluated zettel as a JSON-decoded data structure.
func (c *Client) GetEvaluatedSexpr(ctx context.Context, zid api.ZettelID, part string) (sxpf.Value, error) {
	return c.getSexpr(ctx, 'v', zid, part)
}

func (c *Client) getSexpr(ctx context.Context, key byte, zid api.ZettelID, part string) (sxpf.Value, error) {
	ub := c.newURLBuilder(key).SetZid(zid)
	ub.AppendQuery(api.QueryKeyEncoding, api.EncodingSexpr)
	if part != "" {
		ub.AppendQuery(api.QueryKeyPart, part)
	}
	resp, err := c.buildAndExecuteRequest(ctx, http.MethodGet, ub, nil, nil)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {







|

|







377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
// GetEvaluatedZettelZJSON returns an evaluated zettel as a JSON-decoded data structure.
func (c *Client) GetEvaluatedSexpr(ctx context.Context, zid api.ZettelID, part string) (sxpf.Value, error) {
	return c.getSexpr(ctx, 'v', zid, part)
}

func (c *Client) getSexpr(ctx context.Context, key byte, zid api.ZettelID, part string) (sxpf.Value, error) {
	ub := c.newURLBuilder(key).SetZid(zid)
	ub.AppendKVQuery(api.QueryKeyEncoding, api.EncodingSexpr)
	if part != "" {
		ub.AppendKVQuery(api.QueryKeyPart, part)
	}
	resp, err := c.buildAndExecuteRequest(ctx, http.MethodGet, ub, nil, nil)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
// GetEvaluatedZettelZJSON returns an evaluated zettel as a JSON-decoded data structure.
func (c *Client) GetEvaluatedZJSON(ctx context.Context, zid api.ZettelID, part string) (zjson.Value, error) {
	return c.getZJSON(ctx, 'v', zid, part)
}

func (c *Client) getZJSON(ctx context.Context, key byte, zid api.ZettelID, part string) (zjson.Value, error) {
	ub := c.newURLBuilder(key).SetZid(zid)
	ub.AppendQuery(api.QueryKeyEncoding, api.EncodingZJSON)
	if part != "" {
		ub.AppendQuery(api.QueryKeyPart, part)
	}
	resp, err := c.buildAndExecuteRequest(ctx, http.MethodGet, ub, nil, nil)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {







|

|







405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
// GetEvaluatedZettelZJSON returns an evaluated zettel as a JSON-decoded data structure.
func (c *Client) GetEvaluatedZJSON(ctx context.Context, zid api.ZettelID, part string) (zjson.Value, error) {
	return c.getZJSON(ctx, 'v', zid, part)
}

func (c *Client) getZJSON(ctx context.Context, key byte, zid api.ZettelID, part string) (zjson.Value, error) {
	ub := c.newURLBuilder(key).SetZid(zid)
	ub.AppendKVQuery(api.QueryKeyEncoding, api.EncodingZJSON)
	if part != "" {
		ub.AppendKVQuery(api.QueryKeyPart, part)
	}
	resp, err := c.buildAndExecuteRequest(ctx, http.MethodGet, ub, nil, nil)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
func (c *Client) GetZettelContext(
	ctx context.Context, zid api.ZettelID, dir ContextDirection, depth, limit int) (
	*api.ZidMetaRelatedList, error,
) {
	ub := c.newURLBuilder('x').SetZid(zid)
	switch dir {
	case DirBackward:
		ub.AppendQuery(api.QueryKeyDir, api.DirBackward)
	case DirForward:
		ub.AppendQuery(api.QueryKeyDir, api.DirForward)
	}
	if depth > 0 {
		ub.AppendQuery(api.QueryKeyDepth, strconv.Itoa(depth))
	}
	if limit > 0 {
		ub.AppendQuery(api.QueryKeyLimit, strconv.Itoa(limit))
	}
	resp, err := c.buildAndExecuteRequest(ctx, http.MethodGet, ub, nil, nil)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {







|

|


|


|







481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
func (c *Client) GetZettelContext(
	ctx context.Context, zid api.ZettelID, dir ContextDirection, depth, limit int) (
	*api.ZidMetaRelatedList, error,
) {
	ub := c.newURLBuilder('x').SetZid(zid)
	switch dir {
	case DirBackward:
		ub.AppendKVQuery(api.QueryKeyDir, api.DirBackward)
	case DirForward:
		ub.AppendKVQuery(api.QueryKeyDir, api.DirForward)
	}
	if depth > 0 {
		ub.AppendKVQuery(api.QueryKeyDepth, strconv.Itoa(depth))
	}
	if limit > 0 {
		ub.AppendKVQuery(api.QueryKeyLimit, strconv.Itoa(limit))
	}
	resp, err := c.buildAndExecuteRequest(ctx, http.MethodGet, ub, nil, nil)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
		return statusToError(resp)
	}
	return nil
}

// ExecuteCommand will execute a given command at the Zettelstore.
func (c *Client) ExecuteCommand(ctx context.Context, command api.Command) error {
	ub := c.newURLBuilder('x').AppendQuery(api.QueryKeyCommand, string(command))
	resp, err := c.buildAndExecuteRequest(ctx, http.MethodPost, ub, nil, nil)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusNoContent {
		return statusToError(resp)
	}
	return nil
}

func (c *Client) newQueryURLBuilder(key byte, query url.Values) *api.URLBuilder {
	ub := c.newURLBuilder(key)
	for key, values := range query {
		if key == api.QueryKeyEncoding {
			continue
		}
		for _, val := range values {
			ub.AppendQuery(key, val)
		}
	}
	return ub
}

// ListMapMeta returns a map of all metadata values with the given key to the
// list of zettel IDs containing this value.
func (c *Client) ListMapMeta(ctx context.Context, key string) (api.MapMeta, error) {
	err := c.updateToken(ctx)
	if err != nil {
		return nil, err
	}
	req, err := c.newRequest(ctx, http.MethodGet, c.newURLBuilder('m').AppendQuery(api.QueryKeyKey, key), nil)
	if err != nil {
		return nil, err
	}
	resp, err := c.executeRequest(req)
	if err != nil {
		return nil, err
	}







|


















|





|

|




|







594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
		return statusToError(resp)
	}
	return nil
}

// ExecuteCommand will execute a given command at the Zettelstore.
func (c *Client) ExecuteCommand(ctx context.Context, command api.Command) error {
	ub := c.newURLBuilder('x').AppendKVQuery(api.QueryKeyCommand, string(command))
	resp, err := c.buildAndExecuteRequest(ctx, http.MethodPost, ub, nil, nil)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusNoContent {
		return statusToError(resp)
	}
	return nil
}

func (c *Client) newQueryURLBuilder(key byte, query url.Values) *api.URLBuilder {
	ub := c.newURLBuilder(key)
	for key, values := range query {
		if key == api.QueryKeyEncoding {
			continue
		}
		for _, val := range values {
			ub.AppendKVQuery(key, val)
		}
	}
	return ub
}

// QueryMapMeta returns a map of all metadata values with the given query action to the
// list of zettel IDs containing this value.
func (c *Client) QueryMapMeta(ctx context.Context, query string) (api.MapMeta, error) {
	err := c.updateToken(ctx)
	if err != nil {
		return nil, err
	}
	req, err := c.newRequest(ctx, http.MethodGet, c.newURLBuilder('q').AppendQuery(query), nil)
	if err != nil {
		return nil, err
	}
	resp, err := c.executeRequest(req)
	if err != nil {
		return nil, err
	}

Changes to client/client_test.go.

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
	"zettelstore.de/c/api"
	"zettelstore.de/c/client"
	"zettelstore.de/c/zjson"
)

func TestZettelList(t *testing.T) {
	c := getClient()
	_, err := c.ListZettel(context.Background(), nil)
	if err != nil {
		t.Error(err)
		return
	}
}

func TestGetProtectedZettel(t *testing.T) {







|







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
	"zettelstore.de/c/api"
	"zettelstore.de/c/client"
	"zettelstore.de/c/zjson"
)

func TestZettelList(t *testing.T) {
	c := getClient()
	_, err := c.ListZettel(context.Background(), "")
	if err != nil {
		t.Error(err)
		return
	}
}

func TestGetProtectedZettel(t *testing.T) {

Changes to html/sencoder.go.

444
445
446
447
448
449
450

451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
	}},
	{sexpr.SymVerbatimZettel, 0, DoNothingFn},
	{sexpr.SymBLOB, 3, func(env *EncEnvironment, args *sxpf.Pair) {
		argSyntax := args.GetTail()
		env.writeBLOB(env.GetString(args), env.GetString(argSyntax), env.GetString(argSyntax.GetTail()))
	}},
	{sexpr.SymTransclude, 2, func(env *EncEnvironment, args *sxpf.Pair) {

		ref := env.GetPair(args)
		refKind := env.GetSymbol(ref)
		if refKind == nil {
			return
		}
		if refValue := env.GetString(ref.GetTail()); refValue != "" {
			if sexpr.SymRefStateExternal.Equal(refKind) {
				a := attrs.Attributes{}.Set("src", refValue).AddClass("external")
				env.WriteString("<p><img")
				env.WriteAttributes(a)
				env.WriteString("></p>")
				return
			}
			env.WriteStrings("<!-- transclude ", refKind.GetValue(), ": ")
			env.WriteEscaped(refValue)







>
|






|







444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
	}},
	{sexpr.SymVerbatimZettel, 0, DoNothingFn},
	{sexpr.SymBLOB, 3, func(env *EncEnvironment, args *sxpf.Pair) {
		argSyntax := args.GetTail()
		env.writeBLOB(env.GetString(args), env.GetString(argSyntax), env.GetString(argSyntax.GetTail()))
	}},
	{sexpr.SymTransclude, 2, func(env *EncEnvironment, args *sxpf.Pair) {
		a := sexpr.GetAttributes(env.GetPair(args))
		ref := env.GetPair(args.GetTail())
		refKind := env.GetSymbol(ref)
		if refKind == nil {
			return
		}
		if refValue := env.GetString(ref.GetTail()); refValue != "" {
			if sexpr.SymRefStateExternal.Equal(refKind) {
				a = a.Set("src", refValue).AddClass("external")
				env.WriteString("<p><img")
				env.WriteAttributes(a)
				env.WriteString("></p>")
				return
			}
			env.WriteStrings("<!-- transclude ", refKind.GetValue(), ": ")
			env.WriteEscaped(refValue)
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
			env.WriteString(" ")
			return
		}
		env.WriteEscaped(env.GetString(args))
	}},
	{sexpr.SymSoft, 0, func(env *EncEnvironment, _ *sxpf.Pair) { env.WriteString(" ") }},
	{sexpr.SymHard, 0, func(env *EncEnvironment, _ *sxpf.Pair) { env.WriteString("<br>") }},
	{sexpr.SymTag, 0, func(env *EncEnvironment, args *sxpf.Pair) {
		if !sxpf.IsNil(args) {
			env.WriteEscaped(env.GetString(args))
		}
	}},
	{sexpr.SymLinkInvalid, 2, func(env *EncEnvironment, args *sxpf.Pair) { WriteAsSpan(env, args) }},
	{sexpr.SymLinkZettel, 2, func(env *EncEnvironment, args *sxpf.Pair) { WriteHRefLink(env, args) }},
	{sexpr.SymLinkSelf, 2, func(env *EncEnvironment, args *sxpf.Pair) { WriteHRefLink(env, args) }},
	{sexpr.SymLinkFound, 2, func(env *EncEnvironment, args *sxpf.Pair) { WriteHRefLink(env, args) }},
	{sexpr.SymLinkBroken, 2, func(env *EncEnvironment, args *sxpf.Pair) {
		if a, refValue, ok := PrepareLink(env, args); ok {
			WriteLink(env, args, a.AddClass("broken"), refValue, "")
		}
	}},
	{sexpr.SymLinkHosted, 2, func(env *EncEnvironment, args *sxpf.Pair) { WriteHRefLink(env, args) }},
	{sexpr.SymLinkBased, 2, func(env *EncEnvironment, args *sxpf.Pair) { WriteHRefLink(env, args) }},
	{sexpr.SymLinkSearch, 2, func(env *EncEnvironment, args *sxpf.Pair) {
		if a, refValue, ok := PrepareLink(env, args); ok {
			query := "?" + api.QueryKeySearch + "=" + url.QueryEscape(refValue)
			WriteLink(env, args, a.Set("href", query), refValue, "")
		}
	}},
	{sexpr.SymLinkExternal, 2, func(env *EncEnvironment, args *sxpf.Pair) {
		if a, refValue, ok := PrepareLink(env, args); ok {
			WriteLink(env, args, a.Set("href", refValue).AddClass("external"), refValue, "")
		}







<
<
<
<
<











|

|







482
483
484
485
486
487
488





489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
			env.WriteString(" ")
			return
		}
		env.WriteEscaped(env.GetString(args))
	}},
	{sexpr.SymSoft, 0, func(env *EncEnvironment, _ *sxpf.Pair) { env.WriteString(" ") }},
	{sexpr.SymHard, 0, func(env *EncEnvironment, _ *sxpf.Pair) { env.WriteString("<br>") }},





	{sexpr.SymLinkInvalid, 2, func(env *EncEnvironment, args *sxpf.Pair) { WriteAsSpan(env, args) }},
	{sexpr.SymLinkZettel, 2, func(env *EncEnvironment, args *sxpf.Pair) { WriteHRefLink(env, args) }},
	{sexpr.SymLinkSelf, 2, func(env *EncEnvironment, args *sxpf.Pair) { WriteHRefLink(env, args) }},
	{sexpr.SymLinkFound, 2, func(env *EncEnvironment, args *sxpf.Pair) { WriteHRefLink(env, args) }},
	{sexpr.SymLinkBroken, 2, func(env *EncEnvironment, args *sxpf.Pair) {
		if a, refValue, ok := PrepareLink(env, args); ok {
			WriteLink(env, args, a.AddClass("broken"), refValue, "")
		}
	}},
	{sexpr.SymLinkHosted, 2, func(env *EncEnvironment, args *sxpf.Pair) { WriteHRefLink(env, args) }},
	{sexpr.SymLinkBased, 2, func(env *EncEnvironment, args *sxpf.Pair) { WriteHRefLink(env, args) }},
	{sexpr.SymLinkQuery, 2, func(env *EncEnvironment, args *sxpf.Pair) {
		if a, refValue, ok := PrepareLink(env, args); ok {
			query := "?" + api.QueryKeyQuery + "=" + url.QueryEscape(refValue)
			WriteLink(env, args, a.Set("href", query), refValue, "")
		}
	}},
	{sexpr.SymLinkExternal, 2, func(env *EncEnvironment, args *sxpf.Pair) {
		if a, refValue, ok := PrepareLink(env, args); ok {
			WriteLink(env, args, a.Set("href", refValue).AddClass("external"), refValue, "")
		}

Changes to sexpr/const.go.

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
	SymLinkInvalid     = Smk.MakeSymbol("LINK-INVALID")
	SymLinkZettel      = Smk.MakeSymbol("LINK-ZETTEL")
	SymLinkSelf        = Smk.MakeSymbol("LINK-SELF")
	SymLinkFound       = Smk.MakeSymbol("LINK-FOUND")
	SymLinkBroken      = Smk.MakeSymbol("LINK-BROKEN")
	SymLinkHosted      = Smk.MakeSymbol("LINK-HOSTED")
	SymLinkBased       = Smk.MakeSymbol("LINK-BASED")
	SymLinkSearch      = Smk.MakeSymbol("LINK-SEARCH")
	SymLinkExternal    = Smk.MakeSymbol("LINK-EXTERNAL")
	SymListOrdered     = Smk.MakeSymbol("ORDERED")
	SymListUnordered   = Smk.MakeSymbol("UNORDERED")
	SymListQuote       = Smk.MakeSymbol("QUOTATION")
	SymLiteralProg     = Smk.MakeSymbol("LITERAL-CODE")
	SymLiteralComment  = Smk.MakeSymbol("LITERAL-COMMENT")
	SymLiteralHTML     = Smk.MakeSymbol("LITERAL-HTML")
	SymLiteralInput    = Smk.MakeSymbol("LITERAL-INPUT")
	SymLiteralMath     = Smk.MakeSymbol("LITERAL-MATH")
	SymLiteralOutput   = Smk.MakeSymbol("LITERAL-OUTPUT")
	SymLiteralZettel   = Smk.MakeSymbol("LITERAL-ZETTEL")
	SymMark            = Smk.MakeSymbol("MARK")
	SymPara            = Smk.MakeSymbol("PARA")
	SymRegionBlock     = Smk.MakeSymbol("REGION-BLOCK")
	SymRegionQuote     = Smk.MakeSymbol("REGION-QUOTE")
	SymRegionVerse     = Smk.MakeSymbol("REGION-VERSE")
	SymSoft            = Smk.MakeSymbol("SOFT")
	SymSpace           = Smk.MakeSymbol("SPACE")
	SymTable           = Smk.MakeSymbol("TABLE")
	SymTag             = Smk.MakeSymbol("TAG")
	SymText            = Smk.MakeSymbol("TEXT")
	SymThematic        = Smk.MakeSymbol("THEMATIC")
	SymTransclude      = Smk.MakeSymbol("TRANSCLUDE")
	SymUnknown         = Smk.MakeSymbol("UNKNOWN-NODE")
	SymVerbatimComment = Smk.MakeSymbol("VERBATIM-COMMENT")
	SymVerbatimEval    = Smk.MakeSymbol("VERBATIM-EVAL")
	SymVerbatimHTML    = Smk.MakeSymbol("VERBATIM-HTML")







|



















<







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
	SymLinkInvalid     = Smk.MakeSymbol("LINK-INVALID")
	SymLinkZettel      = Smk.MakeSymbol("LINK-ZETTEL")
	SymLinkSelf        = Smk.MakeSymbol("LINK-SELF")
	SymLinkFound       = Smk.MakeSymbol("LINK-FOUND")
	SymLinkBroken      = Smk.MakeSymbol("LINK-BROKEN")
	SymLinkHosted      = Smk.MakeSymbol("LINK-HOSTED")
	SymLinkBased       = Smk.MakeSymbol("LINK-BASED")
	SymLinkQuery       = Smk.MakeSymbol("LINK-QUERY")
	SymLinkExternal    = Smk.MakeSymbol("LINK-EXTERNAL")
	SymListOrdered     = Smk.MakeSymbol("ORDERED")
	SymListUnordered   = Smk.MakeSymbol("UNORDERED")
	SymListQuote       = Smk.MakeSymbol("QUOTATION")
	SymLiteralProg     = Smk.MakeSymbol("LITERAL-CODE")
	SymLiteralComment  = Smk.MakeSymbol("LITERAL-COMMENT")
	SymLiteralHTML     = Smk.MakeSymbol("LITERAL-HTML")
	SymLiteralInput    = Smk.MakeSymbol("LITERAL-INPUT")
	SymLiteralMath     = Smk.MakeSymbol("LITERAL-MATH")
	SymLiteralOutput   = Smk.MakeSymbol("LITERAL-OUTPUT")
	SymLiteralZettel   = Smk.MakeSymbol("LITERAL-ZETTEL")
	SymMark            = Smk.MakeSymbol("MARK")
	SymPara            = Smk.MakeSymbol("PARA")
	SymRegionBlock     = Smk.MakeSymbol("REGION-BLOCK")
	SymRegionQuote     = Smk.MakeSymbol("REGION-QUOTE")
	SymRegionVerse     = Smk.MakeSymbol("REGION-VERSE")
	SymSoft            = Smk.MakeSymbol("SOFT")
	SymSpace           = Smk.MakeSymbol("SPACE")
	SymTable           = Smk.MakeSymbol("TABLE")

	SymText            = Smk.MakeSymbol("TEXT")
	SymThematic        = Smk.MakeSymbol("THEMATIC")
	SymTransclude      = Smk.MakeSymbol("TRANSCLUDE")
	SymUnknown         = Smk.MakeSymbol("UNKNOWN-NODE")
	SymVerbatimComment = Smk.MakeSymbol("VERBATIM-COMMENT")
	SymVerbatimEval    = Smk.MakeSymbol("VERBATIM-EVAL")
	SymVerbatimHTML    = Smk.MakeSymbol("VERBATIM-HTML")
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
	SymRefStateInvalid  = Smk.MakeSymbol("INVALID")
	SymRefStateZettel   = Smk.MakeSymbol("ZETTEL")
	SymRefStateSelf     = Smk.MakeSymbol("SELF")
	SymRefStateFound    = Smk.MakeSymbol("FOUND")
	SymRefStateBroken   = Smk.MakeSymbol("BROKEN")
	SymRefStateHosted   = Smk.MakeSymbol("HOSTED")
	SymRefStateBased    = Smk.MakeSymbol("BASED")
	SymRefStateSearch   = Smk.MakeSymbol("SEARCH")
	SymRefStateExternal = Smk.MakeSymbol("EXTERNAL")
)

// Symbols for metadata types
var (
	SymTypeCredential   = Smk.MakeSymbol("CREDENTIAL")
	SymTypeEmpty        = Smk.MakeSymbol("EMPTY-STRING")







|







81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
	SymRefStateInvalid  = Smk.MakeSymbol("INVALID")
	SymRefStateZettel   = Smk.MakeSymbol("ZETTEL")
	SymRefStateSelf     = Smk.MakeSymbol("SELF")
	SymRefStateFound    = Smk.MakeSymbol("FOUND")
	SymRefStateBroken   = Smk.MakeSymbol("BROKEN")
	SymRefStateHosted   = Smk.MakeSymbol("HOSTED")
	SymRefStateBased    = Smk.MakeSymbol("BASED")
	SymRefStateQuery    = Smk.MakeSymbol("QUERY")
	SymRefStateExternal = Smk.MakeSymbol("EXTERNAL")
)

// Symbols for metadata types
var (
	SymTypeCredential   = Smk.MakeSymbol("CREDENTIAL")
	SymTypeEmpty        = Smk.MakeSymbol("EMPTY-STRING")

Changes to text/stext.go.

87
88
89
90
91
92
93
94
95
96
97
98

var builtins = []struct {
	sym     *sxpf.Symbol
	minArgs int
	fn      func(env *textEnvironment, args *sxpf.Pair)
}{
	{sexpr.SymText, 1, func(env *textEnvironment, args *sxpf.Pair) { env.WriteString(env.GetString(args)) }},
	{sexpr.SymTag, 1, func(env *textEnvironment, args *sxpf.Pair) { env.WriteString(env.GetString(args)) }},
	{sexpr.SymSpace, 0, func(env *textEnvironment, _ *sxpf.Pair) { env.WriteString(" ") }},
	{sexpr.SymSoft, 0, func(env *textEnvironment, _ *sxpf.Pair) { env.WriteString(" ") }},
	{sexpr.SymHard, 0, func(env *textEnvironment, _ *sxpf.Pair) { env.WriteString("\n") }},
}







<




87
88
89
90
91
92
93

94
95
96
97

var builtins = []struct {
	sym     *sxpf.Symbol
	minArgs int
	fn      func(env *textEnvironment, args *sxpf.Pair)
}{
	{sexpr.SymText, 1, func(env *textEnvironment, args *sxpf.Pair) { env.WriteString(env.GetString(args)) }},

	{sexpr.SymSpace, 0, func(env *textEnvironment, _ *sxpf.Pair) { env.WriteString(" ") }},
	{sexpr.SymSoft, 0, func(env *textEnvironment, _ *sxpf.Pair) { env.WriteString(" ") }},
	{sexpr.SymHard, 0, func(env *textEnvironment, _ *sxpf.Pair) { env.WriteString("\n") }},
}

Changes to zjson/const.go.

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
	TypeLiteralMath     = "Math"
	TypeLiteralZettel   = "Zettel"
	TypeMark            = "Mark"
	TypeParagraph       = "Para"
	TypePoem            = "Poem"
	TypeSpace           = "Space"
	TypeTable           = "Table"
	TypeTag             = "Tag"
	TypeText            = "Text"
	TypeTransclude      = "Transclude"
	TypeVerbatimCode    = "CodeBlock"
	TypeVerbatimComment = "CommentBlock"
	TypeVerbatimEval    = "EvalBlock"
	TypeVerbatimHTML    = "HTMLBlock"
	TypeVerbatimMath    = "MathBlock"
	TypeVerbatimZettel  = "ZettelBlock"
)

// Values to specify the state of a reference
const (
	RefStateBased    = "based"
	RefStateBroken   = "broken"
	RefStateExternal = "external"
	RefStateFound    = "found"
	RefStateHosted   = "local"
	RefStateInvalid  = "invalid"
	RefStateSearch   = "search"
	RefStateSelf     = "self"
	RefStateZettel   = "zettel"
)

// Values for table cell alignment
const (
	AlignDefault = ""
	AlignLeft    = "<"
	AlignCenter  = ":"
	AlignRight   = ">"
)







<


















|











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
	TypeLiteralMath     = "Math"
	TypeLiteralZettel   = "Zettel"
	TypeMark            = "Mark"
	TypeParagraph       = "Para"
	TypePoem            = "Poem"
	TypeSpace           = "Space"
	TypeTable           = "Table"

	TypeText            = "Text"
	TypeTransclude      = "Transclude"
	TypeVerbatimCode    = "CodeBlock"
	TypeVerbatimComment = "CommentBlock"
	TypeVerbatimEval    = "EvalBlock"
	TypeVerbatimHTML    = "HTMLBlock"
	TypeVerbatimMath    = "MathBlock"
	TypeVerbatimZettel  = "ZettelBlock"
)

// Values to specify the state of a reference
const (
	RefStateBased    = "based"
	RefStateBroken   = "broken"
	RefStateExternal = "external"
	RefStateFound    = "found"
	RefStateHosted   = "local"
	RefStateInvalid  = "invalid"
	RefStateQuery    = "query"
	RefStateSelf     = "self"
	RefStateZettel   = "zettel"
)

// Values for table cell alignment
const (
	AlignDefault = ""
	AlignLeft    = "<"
	AlignCenter  = ":"
	AlignRight   = ">"
)