Skip to content

Commit

Permalink
Merge pull request #38 from timlrx/no-cite
Browse files Browse the repository at this point in the history
No cite improvements and citation-js update
  • Loading branch information
timlrx authored Aug 11, 2024
2 parents 4e797f5 + 25af8de commit 7bbc999
Show file tree
Hide file tree
Showing 79 changed files with 1,445 additions and 3,282 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Required, path to file. Will be joined with `options.bibliography` and `options.
Type: `'apa'|'vancouver'|'harvard1'|'chicago'|'mla'|string`.
Default: `apa`.

For the main `rehypeCitation` plugin, one of 'apa', 'vancouver', 'harvard1', 'chicago', 'mla'. A local file path or URL to a valid CSL file is also accepted.
For the main `rehypeCitation` plugin, one of 'apa', 'vancouver', 'harvard1', 'chicago', 'mla'. A local file path or URL to a valid CSL file is also accepted. Can also be specified as a frontmatter option in the markdown file to override the default.

#### options.lang

Expand All @@ -141,7 +141,7 @@ Suppress bibliography? By default, biliography is inserted after the entire mark

Type: `string[]`.

Citation IDs (@item1) to include in the bibliography even if they are not cited in the document.
Citation IDs (@item1) to include in the bibliography even if they are not cited in the document. Can also be specified as a frontmatter option in the markdown file.

#### options.inlineClass

Expand Down
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@
},
"homepage": "https://github.com/timlrx/rehype-citation#readme",
"dependencies": {
"@citation-js/core": "^0.7.1",
"@citation-js/core": "^0.7.14",
"@citation-js/date": "^0.5.1",
"@citation-js/name": "^0.4.2",
"@citation-js/plugin-bibjson": "^0.7.2",
"@citation-js/plugin-bibtex": "^0.7.2",
"@citation-js/plugin-csl": "^0.7.2",
"@citation-js/plugin-bibjson": "^0.7.14",
"@citation-js/plugin-bibtex": "^0.7.14",
"@citation-js/plugin-csl": "^0.7.14",
"citeproc": "^2.4.63",
"cross-fetch": "^4.0.0",
"hast-util-from-dom": "^5.0.0",
Expand Down
19 changes: 0 additions & 19 deletions src/citation-js/core/Cite/async.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
// @ts-nocheck
/**
* @callback module:@citation-js/core.Cite~asyncCallback
* @param {Cite} data - Cite object
*/

/**
* @access public
* @memberof module:@citation-js/core.Cite
*
* @param {module:@citation-js/core~InputData} data - input data
* @param {module:@citation-js/core~InputOptions} [options={}] - cite options
* @param {module:@citation-js/core.Cite~asyncCallback} [callback] - if not given, function returns promise.
*
* @return {Promise<module:@citation-js/core.Cite>} if callback is omitted, returns a promise
*/
function async(data, options, callback) {
if (typeof options === 'function' && !callback) {
callback = options
options = undefined
}

const promise = new this().setAsync(data, options)

if (typeof callback === 'function') {
promise.then(callback)
return undefined
} else {
return promise
}
}

export default async
59 changes: 10 additions & 49 deletions src/citation-js/core/Cite/get.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,46 @@
// @ts-nocheck
import { validateOutputOptions as validate } from './validate.js'
import { format as formatData } from '../plugins/output.js'
import { clean as parseCsl } from '../plugins/input/csl.js'

/**
* Get a list of the data entry IDs, in the order of that list
*
* @access public
* @method getIds
* @memberof module:@citation-js/core.Cite#
*
* @return {Array<String>} List of IDs
*/
export function getIds() {
return this.data.map((entry) => entry.id)
}

/**
* Get formatted data from your object.
*
* @access public
* @method format
* @memberof module:@citation-js/core.Cite#
*
* @param {String} format - format module name
* @param {...*} options - module options (see relevant documentation)
*
* @return {String|Array<Object>} formatted data
*/
export function format(format, ...options) {
return formatData(format, parseCsl(this.data), ...options)
}

/**
* Get formatted data from your object.
*
* @access public
* @method get
* @memberof module:@citation-js/core.Cite#
* @tutorial output
* @deprecated use {@link module:@citation-js/core.Cite#format}
*
* @param {module:@citation-js/core~OutputOptions} [options={}] - Output options
*
* @return {String|Array<Object>} The formatted data
*/
/* istanbul ignore next: deprecated */
export function get(options = {}) {
validate(options)

const parsedOptions = Object.assign({}, this.defaultOptions, this._options.output, options)

const { type, style } = parsedOptions
const [styleType, styleFormat] = style.split('-')
const newStyle =
styleType === 'citation' ? 'bibliography' : styleType === 'csl' ? 'data' : styleType
const newType = type === 'string' ? 'text' : type === 'json' ? 'object' : type

let formatOptions

switch (newStyle) {
case 'bibliography': {
const { lang, append, prepend } = parsedOptions
formatOptions = { template: styleFormat, lang, format: newType, append, prepend }
formatOptions = {
template: styleFormat,
lang,
format: newType,
append,
prepend,
}
break
}

case 'data':
case 'bibtex':
case 'bibtxt':
case 'ndjson':
case 'ris':
formatOptions = { type: newType }
formatOptions = {
type: newType,
}
break

default:
throw new Error(`Invalid style "${newStyle}"`)
}

const result = this.format(newStyle, Object.assign(formatOptions, options._newOptions))

const { format } = parsedOptions
if (
format === 'real' &&
Expand Down
54 changes: 2 additions & 52 deletions src/citation-js/core/Cite/index.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,24 @@
//@ts-nocheck
// @ts-nocheck
import * as log from './log.js'
import * as options from './options.js'
import * as set from './set.js'
import * as sort from './sort.js'
import * as get from './get.js'
import * as staticMethods from './static.js'

/**
* Create a `Cite` object with almost any kind of data, and manipulate it with its default methods.
*
* @access public
* @constructor Cite
* @memberof module:@citation-js/core
*
* @param {module:@citation-js/core~InputData} data - Input data
* @param {module:@citation-js/core~InputOptions} [options={}] - Input options
*/
function Cite(data, options = {}) {
// Making it Scope-Safe
if (!(this instanceof Cite)) {
return new Cite(data, options)
}

/**
* The default options for the output. See [input options](../#cite.in.options)
*
* @access protected
* @memberof module:@citation-js/core.Cite#
*
* @var {module:@citation-js/core~InputOptions} _options
*/
this._options = options

/**
* The saved-images-log
*
* @access protected
* @memberof module:@citation-js/core.Cite#
*
* @var {Array<Array<String>>} log
*/
this.log = []

/**
* The parsed data
*
* @access protected
* @memberof module:@citation-js/core.Cite#
*
* @var {Array<module:@citation-js/core~CSL>} data
*/
this.data = []

// Modified citation-js to accept an array of objects
// Use add instead of set to retain previous data
data.forEach((d) => {
this.add(d, options)
})
// this.set(data, options)
this.set(data, options)
this.options(options)

return this
}

Object.assign(Cite.prototype, log, options, set, sort, get)

Cite.prototype[Symbol.iterator] = function* () {
yield* this.data
}

Object.assign(Cite, staticMethods)

export default Cite
44 changes: 0 additions & 44 deletions src/citation-js/core/Cite/log.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
// @ts-nocheck
/**
* @memberof module: @citation-js / core.Cite#
*
* @return {Number} The latest version of the object
*/
function currentVersion() {
return this.log.length
}

/**
* Returns an image of the object in the version specified.
*
* @memberof module:@citation-js/core.Cite#
*
* @param {Number} [versnum=1] - The number of the version you want to retrieve. Illegal numbers: numbers under or equal to zero, floats, numbers above the current version of the object.
*
* @return {module:@citation-js/core.Cite} The version of the object with the version number passed. `undefined` if an illegal number is passed.
*/
function retrieveVersion(versnum = 1) {
if (versnum <= 0 || versnum > this.currentVersion()) {
return null
Expand All @@ -27,42 +11,14 @@ function retrieveVersion(versnum = 1) {
return image
}
}

/**
* Returns the second to last saved image of the object.
*
* @memberof module:@citation-js/core.Cite#
*
* @param {Number} [number=1] - number of versions to go back.
*
* @return {module:@citation-js/core.Cite} The second to last version of the object. `undefined` if used on first version.
*/
function undo(number = 1) {
return this.retrieveVersion(this.currentVersion() - number)
}

/**
* Returns the last saved image of the object.
*
* @memberof module:@citation-js/core.Cite#
*
* @return {module:@citation-js/core.Cite} The last version of the object. `undefined` if used on first version.
*/
function retrieveLastVersion() {
return this.retrieveVersion(this.currentVersion())
}

/**
* Save an image of the current version of the object.
*
* @memberof module:@citation-js/core.Cite#
*
* @return {module:@citation-js/core.Cite} The current version of the object.
*/
function save() {
this.log.push([JSON.stringify(this.data), JSON.stringify(this._options)])

return this
}

export { currentVersion, retrieveVersion, retrieveLastVersion, undo, save }
Loading

0 comments on commit 7bbc999

Please sign in to comment.