Skip to content

Minimal code needed for declarative usage #247

Description

@abalter

This is somewhat unfair to ask, but if someone can help me, it would mean a huge amount. The citeproc-js library is pretty complex and using it requires creating other functions (retrieveItem, retrieveLocale) that don't fully make sense to me. The package is designed to be able to do a large number of things across a large number of use cases.

All I want to do is generate formatted citations given a CSL-JSON library, CSL stylesheet, and locale spec like this:

function getCitation({
  citationIds = [],  // Array of citation ids
  type = "",         // "in-text" or "full"
  sources = "",      // CSL-JSON string
  style = "",        // CSL stylesheet as JSON string
  locale = ""        // Locale XML as JSON string
}) {
  /**
   * Retrieve citations based on specified parameters.
   * 
   * @param {Array} citationIds - List of citation IDs
   * @param {String} type - Type of citation ("in-text" or "full")
   * @param {String} sources - CSL-JSON formatted string of sources
   * @param {String} style - CSL stylesheet converted to JSON
   * @param {String} locale - Locale XML file converted to JSON
   */
  
  // Assuming equivalent functions exist to parse the JSON, stylesheet, and XML
  const sources_object = JSON.parse(sources);
  const style_object = JSON.parse(style);
  const locale_object = JSON.parseL(locale);
  
  const selected_sources = sources_object.filter(source => citationIds.includes(source.id));
  
  if (type === "in-text") {
    return selected_sources.map(source => getShortCitation(source, style_object, locale_object));
  } else if (type === "full") {
    return selectedSources.map(source => getFullCitation(source, style_object , locale_object));
  } else {
    console.log("Invalid type: " + type);
    return false;
  }
}

Could someone guide me to the pertinent methods that I could use to build this simple application?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions