diff --git a/README.md b/README.md index 5d806ff..01cf1bd 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,17 @@ -# go-typst +# go-typst [![test](https://github.com/Dadido3/go-typst/actions/workflows/test.yml/badge.svg)](https://github.com/Dadido3/go-typst/actions/workflows/test.yml) A library to generate documents and reports by utilizing the command line version of [typst]. -Features include: +## Features - Encoder to convert go objects into typst objects which then can be injected into typst documents. -- Parsing of returned errors into go error objects. +- Parsing of stderr into an go error object. - Uses stdio; No temporary files need to be created. -- Test coverage of most features. +- Good test coverage of features. ## Installation -1. Use `go get github.com/Dadido3/go-typst` inside of your module to add this library to your project. +1. Use `go get github.com/Dadido3/go-typst` inside of your project to add this module to your project. 2. Install typst by following [the instructions in the typst repository]. ## Runtime requirements @@ -21,7 +21,40 @@ You can install it by following [the instructions in the typst repository]. ## Usage -ToDo +Here we will create a simple PDF document by passing a reader with typst markup into `typstCLI.Render` and then let it write the resulting PDF data into a file: + +```go +func main() { + r := bytes.NewBufferString(`#set page(width: 100mm, height: auto, margin: 5mm) += go-typst + +A library to generate documents and reports by utilizing the command line version of typst. +#footnote[https://typst.app/] + +== Features + +- Encoder to convert go objects into typst objects which then can be injected into typst documents. +- Parsing of returned errors into go error objects. +- Uses stdio; No temporary files need to be created. +- Test coverage of most features.`) + + typstCLI := typst.CLI{} + + f, err := os.Create("output.pdf") + if err != nil { + t.Fatalf("Failed to create output file: %v.", err) + } + defer f.Close() + + if err := typstCLI.Render(r, f, nil); err != nil { + t.Fatalf("Failed to render document: %v.", err) + } +} +``` + +The resulting document will look like this: + +![readme-1.svg](documentation/images/readme-1.svg) [the instructions in the typst repository]: https://github.com/typst/typst?tab=readme-ov-file#installation [typst]: https://typst.app/ diff --git a/documentation/images/readme-1.svg b/documentation/images/readme-1.svg new file mode 100644 index 0000000..b10055f --- /dev/null +++ b/documentation/images/readme-1.svg @@ -0,0 +1,581 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/readme_test.go b/readme_test.go new file mode 100644 index 0000000..0cd0c52 --- /dev/null +++ b/readme_test.go @@ -0,0 +1,36 @@ +package typst_test + +import ( + "bytes" + "os" + "testing" + + "github.com/Dadido3/go-typst" +) + +func TestREADME1(t *testing.T) { + r := bytes.NewBufferString(`#set page(width: 100mm, height: auto, margin: 5mm) += go-typst + +A library to generate documents and reports by utilizing the command line version of typst. +#footnote[https://typst.app/] + +== Features + +- Encoder to convert go objects into typst objects which then can be injected into typst documents. +- Parsing of returned errors into go error objects. +- Uses stdio; No temporary files need to be created. +- Test coverage of most features.`) + + typstCLI := typst.CLI{} + + f, err := os.Create("output.pdf") + if err != nil { + t.Fatalf("Failed to create output file: %v.", err) + } + defer f.Close() + + if err := typstCLI.Render(r, f, nil); err != nil { + t.Fatalf("Failed to render document: %v.", err) + } +}