Documentation
¶
Overview ¶
Package jplaw2epub converts Japanese Standard Law XML Schema (法令標準XMLスキーマ) into EPUB files.
This package provides functionality to convert Japanese legal documents in XML format into EPUB ebooks with proper formatting, Ruby annotations support, and Japanese-specific list styling.
Basic usage:
book, err := jplaw2epub.CreateEPUBFromXMLPath("law.xml")
if err != nil {
return err
}
return jplaw2epub.WriteEPUB(book, "output.epub")
Index ¶
- func AddCSSToEPUB(book *epub.Epub) error
- func CreateEPUBFromXMLFile(xmlFile io.Reader) (*epub.Epub, error)
- func CreateEPUBFromXMLFileWithOptions(xmlFile io.Reader, opts *EPUBOptions) (*epub.Epub, error)
- func CreateEPUBFromXMLPath(xmlPath string) (*epub.Epub, error)
- func CreateEPUBFromXMLPathWithOptions(xmlPath string, opts *EPUBOptions) (*epub.Epub, error)
- func ProcessStyleStructs(styles []jplaw.StyleStruct, imgProc ImageProcessorInterface) string
- func WriteEPUB(book *epub.Epub, destPath string) error
- type APIClient
- type EPUBOptions
- type ImageProcessor
- type ImageProcessorInterface
- type StyleProcessor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddCSSToEPUB ¶ added in v1.1.0
AddCSSToEPUB adds CSS stylesheet to the EPUB
func CreateEPUBFromXMLFile ¶
CreateEPUBFromXMLFile creates an EPUB file from a jplaw XML file reader.
This function reads XML data from the provided io.Reader, parses it as Japanese law data according to the Japanese Standard Law XML Schema, and creates an EPUB book with proper formatting and metadata.
Example:
xmlFile, err := os.Open("law.xml")
if err != nil {
return err
}
defer xmlFile.Close()
book, err := jplaw2epub.CreateEPUBFromXMLFile(xmlFile)
if err != nil {
return err
}
func CreateEPUBFromXMLFileWithOptions ¶ added in v1.1.0
CreateEPUBFromXMLFileWithOptions creates an EPUB file with image support
func CreateEPUBFromXMLPath ¶
CreateEPUBFromXMLPath creates an EPUB file from a jplaw XML file path.
This is a convenience function that opens the file at the given path and calls CreateEPUBFromXMLFile to process it. Images will be automatically downloaded and embedded if the filename contains a valid revision ID.
Example:
book, err := jplaw2epub.CreateEPUBFromXMLPath("law.xml")
if err != nil {
return err
}
func CreateEPUBFromXMLPathWithOptions ¶ added in v1.1.0
func CreateEPUBFromXMLPathWithOptions(xmlPath string, opts *EPUBOptions) (*epub.Epub, error)
CreateEPUBFromXMLPathWithOptions creates an EPUB file with image support
func ProcessStyleStructs ¶ added in v1.1.0
func ProcessStyleStructs(styles []jplaw.StyleStruct, imgProc ImageProcessorInterface) string
ProcessStyleStructs processes multiple StyleStructs
Types ¶
type APIClient ¶ added in v1.2.0
type APIClient interface {
GetAttachment(lawRevisionID string, params *lawapi.GetAttachmentParams) (*string, error)
}
APIClient defines the interface for the law API client
type EPUBOptions ¶ added in v1.1.0
type EPUBOptions struct {
// APIClient is the jplaw API client for downloading images
APIClient *lawapi.Client
// RevisionID is the revision ID for fetching attachments
RevisionID string
// MaxImageHeight is the maximum height for images (e.g., "300px", "80vh", "50%")
MaxImageHeight string
}
EPUBOptions contains options for EPUB creation
type ImageProcessor ¶ added in v1.1.0
type ImageProcessor struct {
// contains filtered or unexported fields
}
ImageProcessor handles image processing for EPUB
func NewImageProcessor ¶ added in v1.1.0
func NewImageProcessor(client APIClient, revisionID string, book *epub.Epub) *ImageProcessor
NewImageProcessor creates a new image processor
func (*ImageProcessor) ProcessFigStruct ¶ added in v1.1.0
func (ip *ImageProcessor) ProcessFigStruct(fig *jplaw.FigStruct) (string, error)
ProcessFigStruct processes a FigStruct and returns HTML
func (*ImageProcessor) SetMaxImageHeight ¶ added in v1.1.0
func (ip *ImageProcessor) SetMaxImageHeight(height string)
SetMaxImageHeight sets the maximum image height
type ImageProcessorInterface ¶ added in v1.2.0
type ImageProcessorInterface interface {
ProcessFigStruct(fig *jplaw.FigStruct) (string, error)
SetMaxImageHeight(height string)
}
ImageProcessorInterface defines the interface for image processing
type StyleProcessor ¶ added in v1.1.0
type StyleProcessor struct {
// contains filtered or unexported fields
}
StyleProcessor handles StyleStruct processing
func NewStyleProcessor ¶ added in v1.1.0
func NewStyleProcessor(imgProc ImageProcessorInterface) *StyleProcessor
NewStyleProcessor creates a new style processor
func (*StyleProcessor) ProcessStyleStruct ¶ added in v1.1.0
func (sp *StyleProcessor) ProcessStyleStruct(style *jplaw.StyleStruct) string
ProcessStyleStruct processes a StyleStruct and returns HTML