dotfiles

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 83dafe1d2cdf7de7df2295165c16d12ba5599e7f (tree)
parent b2a0d7f0da09ad95925d05497efc5bfc371b65dc
Author: Motiejus Jakštys <desired.mta@gmail.com>
Date:   Fri,  5 Jun 2020 13:21:22 +0300

some parsing

Diffstat:
Msrc/joplin2site/internal/note/parse.go | 6+++---
Msrc/joplin2site/internal/note/parse_test.go | 8++++----
Msrc/joplin2site/internal/note/types.go | 12++++++------
3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/joplin2site/internal/note/parse.go b/src/joplin2site/internal/note/parse.go @@ -6,15 +6,15 @@ import ( "gopkg.in/yaml.v2" ) -func Parse(in string) (JoplinNote, error) { +func Parse(in string) (Note, error) { var title, body, params string titleIdx := strings.Index(in, "\n\n") paramsIdx := strings.LastIndex(in, "\n\n") title, body, params = in[0:titleIdx], in[min(titleIdx+2, paramsIdx):paramsIdx], in[paramsIdx:] - var note JoplinNote + var note Note if err := yaml.Unmarshal([]byte(params), &note); err != nil { - return JoplinNote{}, err + return Note{}, err } note.Title = title diff --git a/src/joplin2site/internal/note/parse_test.go b/src/joplin2site/internal/note/parse_test.go @@ -13,7 +13,7 @@ func TestParse(t *testing.T) { name string note string wantErr string - wantNote JoplinNote + wantNote Note }{ { name: "ok, has body", @@ -25,7 +25,7 @@ id: 4c7dd536ce1641afa4df349d87d9d29f parent_id: 9e651b478a5a43c196c31719300fee6e type_: 1 `, - wantNote: JoplinNote{ + wantNote: Note{ ID: "4c7dd536ce1641afa4df349d87d9d29f", Title: "Meta", Body: "Fonts: https://news.ycombinator.com/item?id=23381513", @@ -42,7 +42,7 @@ updated_time: 2020-06-04T16:07:19.930Z encryption_applied: 0 type_: 2 `, - wantNote: JoplinNote{ + wantNote: Note{ ID: "9e651b478a5a43c196c31719300fee6e", Title: "blog", Body: "", @@ -55,7 +55,7 @@ type_: 2 note: `blog bad yaml`, - wantErr: "yaml: unmarshal errors:\n line 3: cannot unmarshal !!str `bad yaml` into note.JoplinNote", + wantErr: "yaml: unmarshal errors:\n line 3: cannot unmarshal !!str `bad yaml` into note.Note", }, } diff --git a/src/joplin2site/internal/note/types.go b/src/joplin2site/internal/note/types.go @@ -2,8 +2,8 @@ package note import "time" -// JoplinNote is how Joplin understands the note. -type JoplinNote struct { +// Note is how Joplin understands the note. +type Note struct { ID string `yaml:"id"` ParentID string `yaml:"parent_id"` Title string `yaml:"-"` @@ -16,9 +16,9 @@ type JoplinNote struct { Altitude float64 `yaml:"altitude"` Author string `yaml:"author"` SourceUrl string `yaml:"source_url"` - IsTodo int `yaml:"is_todo"` - TodoDue int `yaml:"todo_due"` - TodoCompleted int `yaml:"todo_completed"` + IsTODO int `yaml:"is_todo"` + TODODue int `yaml:"todo_due"` + TODOCompleted int `yaml:"todo_completed"` Source string `yaml:"source"` SourceApplication string `yaml:"source_application"` ApplicationData string `yaml:"application_data"` @@ -29,7 +29,7 @@ type JoplinNote struct { EncryptionApplied int `yaml:"encryption_applied"` MarkupLanguage int `yaml:"markup_language"` IsShared int `yaml:"is_shared"` - BodyHtml string `yaml:"body_html"` + BodyHTML string `yaml:"body_html"` // BaseURL is if `body_html` is provided and contains relative URLs, provide the `base_url` parameter too so that all the URLs can be converted to absolute ones. The base URL is basically where the HTML was fetched from, minus the query (everything after the '?'). For example if the original page was `https://stackoverflow.com/search?q=%5Bjava%5D+test`, the base URL is `https://stackoverflow.com/search`. BaseUrl string `yaml:"base_url"` // ImageDataUrl contains an image to attach to the note, in [Data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) format.