citeproc_js_go

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2023 License: MIT Imports: 8 Imported by: 2

README

citeproc-js-go

citeproc-js-go is a wrapper for selected features of the citeproc-js library, running on Goja, a JavaScript interpreter for Go. The project provides a convenient and efficient way to use citeproc-js in a Go environment.

Getting Started

You can use go get to download citeproc-js-go and its dependencies:

go get github.com/sett17/citeproc-js-go

Usage

To use citeproc-js-go, you will need to provide it with your own citeproc-js library and style file. You can find a comprehensive list of citation styles and the corresponding style files here.

Once you have your citeproc-js library and style file, you can use the following code to initialize citeproc-js-go:

package main

import (
	"fmt"
	"github.com/sett17/citeproc-js-go/csljson"
	citeproc "github.com/sett17/citeproc-js-go"
	"io"
)

func main() {
	// Create a new Citeproc session
	session := citeproc.NewSession()

	// If no files or content is set manually, ieee.csl and locale-en-US.xml will be used by default
	// Load the CSL file and the locale file
	err := session.SetCslFile("path/to/csl/file.csl")
	if err != nil {
		fmt.Println("Error loading CSL file:", err)
		return
	}
	err = session.SetLocaleFile("path/to/locale/file.xml")
	if err != nil {
		fmt.Println("Error loading locale file:", err)
		return
	}

	// Initialize the Citeproc session
	err = session.Init()
	if err != nil {
		fmt.Println("Error initializing Citeproc session:", err)
		return
	}

	// Define the citation items
	var items []csljson.Item

	//TODO: Add items to the session

	// Add all items to the session
	err = session.AddCitation(items...)

	cluster := make([]csljson.Item, 0)
	//TODO add items to the cluster
	
	// Process a citation cluster
	citationCluster, err := session.ProcessCitationCluster(cluster...)
	if err != nil {
		fmt.Println("Error processing citation cluster:", err)
		return
	}

	// Print the resulting citation (this is what goes into the text, e.g. [1], [4])
	fmt.Println(citationCluster)

	// Make bibliography
	bibliography, err := session.MakeBibliography()
	if err != nil {
		fmt.Println("Error making bibliography:", err)
		return
	}

	// Print the resulting bibliography
	fmt.Println(bibliography)
}

Replace path/to/citeproc.js and path/to/style.csl with the actual paths to your citeproc-js library and style file, respectively.

Contributions

If you would like to contribute to citeproc-js-go, please fork the repository and create a pull request with your changes. Your contributions are always welcome!

License

citeproc-js-go is licensed under the MIT License.

Documentation

Overview

Package citeproc_js_go

Package citeproc_js_go implements the integration of citeproc-js with Go. Citeproc-js is a JavaScript implementation of the Citation Style Language (CSL) that is used to format bibliographic references.

The package allows the user to pass in a CSL file and a locales file, or if not provided, use the default files included in the package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session is a struct that stores information about the Citeproc session.

func NewSession

func NewSession() *Session

NewSession creates and returns a new Citeproc session.

func (*Session) AddCitation added in v1.0.0

func (s *Session) AddCitation(items ...csljson.Item) error

func (*Session) Init

func (s *Session) Init() (err error)

Init initializes the Citeproc session by loading required files and setting up the runtime.

func (*Session) MakeBibliography

func (s *Session) MakeBibliography() ([]string, error)

MakeBibliography processes the bibliography items stored in the current session and returns a slice of strings containing the formatted bibliography entries.

func (*Session) ProcessCitationCluster

func (s *Session) ProcessCitationCluster(items ...csljson.Item) (string, error)

ProcessCitationCluster processes a citation cluster and returns the resulting string that should be placed in the text at the place of the citation.

func (*Session) SetCslContent

func (s *Session) SetCslContent(cslContent string)

SetCslContent sets the content of the CSL file for the session.

func (*Session) SetCslFile

func (s *Session) SetCslFile(cslFilePath string) error

SetCslFile sets the content of the CSL file for the session.

func (*Session) SetLocaleContent

func (s *Session) SetLocaleContent(localeContent string)

SetLocaleContent sets the content of the locale file for the session.

func (*Session) SetLocaleFile

func (s *Session) SetLocaleFile(localeFilePath string) error

SetLocaleFile sets the content of the locale file for the session.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL