Code Monkey home page Code Monkey logo

citeproc-js-go's Introduction

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.

citeproc-js-go's People

Contributors

sett17 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.