~james/core

core/api/org_tangled/markupmarkdown.go -rw-r--r-- 3.2 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 hours ago
                                                                                
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
// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT.

package org_tangled

// schema: org.tangled.markup.markdown

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"

	"github.com/bluesky-social/indigo/lex/util"
	cbg "github.com/whyrusleeping/cbor-gen"
)

const (
	MarkupMarkdownNSID = "org.tangled.markup.markdown"
)

func init() {
	util.RegisterType("org.tangled.markup.markdown#main", &MarkupMarkdown{})
} // MarkupMarkdown is a "main" in the org.tangled.markup.markdown schema.
// Tangled Flavored Markdown format text
//
// RECORDTYPE: MarkupMarkdown
type MarkupMarkdown struct {
	LexiconTypeID string `json:"$type,const=org.tangled.markup.markdown" cborgen:"$type,const=org.tangled.markup.markdown"`
	// blobs: list of blobs referenced in markdown
	Blobs []*MarkupMarkdown_Blobs_Elem `json:"blobs,omitempty" cborgen:"blobs,omitempty"`
	// text: Final post-processed markdown content that will be rendered
	Text string `json:"text" cborgen:"text"`
}

type MarkupMarkdown_Blobs_Elem struct {
	MarkupEmbedImage *MarkupEmbedImage
	MarkupEmbedVideo *MarkupEmbedVideo
}

func (t *MarkupMarkdown_Blobs_Elem) MarshalJSON() ([]byte, error) {
	if t.MarkupEmbedImage != nil {
		t.MarkupEmbedImage.LexiconTypeID = "org.tangled.markup.embed.image"
		return json.Marshal(t.MarkupEmbedImage)
	}
	if t.MarkupEmbedVideo != nil {
		t.MarkupEmbedVideo.LexiconTypeID = "org.tangled.markup.embed.video"
		return json.Marshal(t.MarkupEmbedVideo)
	}
	return nil, fmt.Errorf("cannot marshal empty enum")
}
func (t *MarkupMarkdown_Blobs_Elem) UnmarshalJSON(b []byte) error {
	typ, err := util.TypeExtract(b)
	if err != nil {
		return err
	}

	switch typ {
	case "org.tangled.markup.embed.image":
		t.MarkupEmbedImage = new(MarkupEmbedImage)
		return json.Unmarshal(b, t.MarkupEmbedImage)
	case "org.tangled.markup.embed.video":
		t.MarkupEmbedVideo = new(MarkupEmbedVideo)
		return json.Unmarshal(b, t.MarkupEmbedVideo)

	default:
		return nil
	}
}

func (t *MarkupMarkdown_Blobs_Elem) MarshalCBOR(w io.Writer) error {

	if t == nil {
		_, err := w.Write(cbg.CborNull)
		return err
	}
	if t.MarkupEmbedImage != nil {
		return t.MarkupEmbedImage.MarshalCBOR(w)
	}
	if t.MarkupEmbedVideo != nil {
		return t.MarkupEmbedVideo.MarshalCBOR(w)
	}
	return fmt.Errorf("cannot cbor marshal empty enum")
}
func (t *MarkupMarkdown_Blobs_Elem) UnmarshalCBOR(r io.Reader) error {
	typ, b, err := util.CborTypeExtractReader(r)
	if err != nil {
		return err
	}

	switch typ {
	case "org.tangled.markup.embed.image":
		t.MarkupEmbedImage = new(MarkupEmbedImage)
		return t.MarkupEmbedImage.UnmarshalCBOR(bytes.NewReader(b))
	case "org.tangled.markup.embed.video":
		t.MarkupEmbedVideo = new(MarkupEmbedVideo)
		return t.MarkupEmbedVideo.UnmarshalCBOR(bytes.NewReader(b))

	default:
		return nil
	}
}

// MarkupMarkdown_Inline is a "inline" in the org.tangled.markup.markdown schema.
//
// Tangled Flavored Markdown format text (inline)
//
// RECORDTYPE: MarkupMarkdown_Inline
type MarkupMarkdown_Inline struct {
	LexiconTypeID string `json:"$type,const=org.tangled.markup.markdown#inline" cborgen:"$type,const=org.tangled.markup.markdown#inline"`
	// text: Final post-processed markdown content that will be rendered
	Text string `json:"text" cborgen:"text"`
}