mirror of
https://github.com/Dadido3/go-typst.git
synced 2025-04-11 12:13:16 +00:00
- Rename MarshalVariable to MarshalValue - Rename NewVariableEncoder to NewValueEncoder - Rename VariableEncoder to ValueEncoder - Rename VariableMarshaler to ValueMarshaler - Rename MarshalTypstVariable to MarshalTypstValue There are now wrappers which ensure compatibility with code that still uses some of the old functions/types. - Improve image_test.go by adding an assertion - Rename all occurrences of Variable to Value - Remove "TODO: Handle images..." as that's already working with the image wrapper - Update README.md
38 lines
811 B
Go
38 lines
811 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/Dadido3/go-typst"
|
|
)
|
|
|
|
func main() {
|
|
// Convert a time.Time value into Typst markup.
|
|
date, err := typst.MarshalValue(time.Now())
|
|
if err != nil {
|
|
log.Panicf("Failed to marshal date into Typst markup: %v", err)
|
|
}
|
|
|
|
// Write Typst markup into buffer.
|
|
var markup bytes.Buffer
|
|
fmt.Fprintf(&markup, `= Hello world
|
|
|
|
This document was created at #%s.display() using typst-go.`, date)
|
|
|
|
// Compile the prepared markup with Typst and write the result it into `output.pdf`.
|
|
f, err := os.Create("output.pdf")
|
|
if err != nil {
|
|
log.Panicf("Failed to create output file: %v.", err)
|
|
}
|
|
defer f.Close()
|
|
|
|
typstCLI := typst.CLI{}
|
|
if err := typstCLI.Compile(&markup, f, nil); err != nil {
|
|
log.Panic("failed to compile document: %w", err)
|
|
}
|
|
}
|