A Go library for creating, manipulating, and validating H5P (HTML5 Package) content with support for the official H5P file format and schemas.
- 📦 Full H5P Package Support - Create and extract
.h5p
ZIP files - 🔒 Type-Safe Schema Implementation - Official H5P content type schemas
- 🏗️ Question Set Builder - Fluent API for building interactive content
- ✅ Validation - Built-in H5P compliance validation
- 🎯 Multiple Question Types - Support for various H5P content types
- 🔄 JSON Serialization - Complete marshaling/unmarshaling support
go get github.com/grokify/h5p-go
package main
import (
"fmt"
"log"
"github.com/grokify/h5p-go"
)
func main() {
// Create answers
answers := []h5p.Answer{
h5p.CreateAnswer("Paris", true),
h5p.CreateAnswer("London", false),
h5p.CreateAnswer("Berlin", false),
}
// Build question set
questionSet, err := h5p.NewQuestionSetBuilder().
SetTitle("Geography Quiz").
SetProgressType("textual").
SetPassPercentage(60).
AddMultipleChoiceQuestion("What is the capital of France?", answers).
Build()
if err != nil {
log.Fatal(err)
}
// Export to JSON
jsonData, _ := questionSet.ToJSON()
fmt.Printf("Generated H5P content:\n%s\n", string(jsonData))
}
import "github.com/grokify/h5p-go/schemas"
// Create strongly-typed content
params := &schemas.MultiChoiceParams{
Question: "What is 2 + 2?",
Answers: []schemas.AnswerOption{
{Text: "4", Correct: true},
{Text: "5", Correct: false},
},
Behaviour: &schemas.Behaviour{
Type: "single",
EnableRetry: true,
},
}
question := h5p.NewMultiChoiceQuestion(params)
- Installation Guide - Detailed setup instructions
- Quick Start Tutorial - Step-by-step examples
- API Reference - Complete API documentation
- Examples - Real-world usage examples
- Question Sets - Building interactive question collections
- Typed Questions - Using type-safe H5P schemas
- H5P Packages - Creating complete
.h5p
files - Semantics API - Working with H5P semantics format
h5p-go/
├── schemas/ # Official H5P content type schemas
├── semantics/ # Universal H5P semantics format
├── builder.go # Fluent API for content creation
├── questionset.go # Core question set functionality
└── h5p_package.go # Complete H5P package management
go test ./...
Run specific tests:
go test -v -run TestQuestionSet # Question set tests
go test -v -run TestTyped # Typed schema tests
go test -v -run TestH5PPackage # Package management tests
This library implements the official H5P specifications:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
See our Contributing Guide for detailed information.
This project is licensed under the MIT License - see the LICENSE file for details.
- H5P Group for the H5P framework and specifications
- The Go community for excellent tooling and libraries