andras-simonyi / citeproc-el

A CSL 1.0.2 Citation Processor for Emacs.
GNU General Public License v3.0
85 stars 9 forks source link

Example of rendering an isolated reference #48

Closed jkitchin closed 3 years ago

jkitchin commented 3 years ago

[Edit] This would be interesting to see, but as you can see in issue #49 and #50, I figured out a way to basically do what I needed, which is see how a standalone citation exports.

Is there an example of https://github.com/andras-simonyi/citeproc-el#rendering-isolated-references?

Something like


#+name: bib-json
#+BEGIN_EXAMPLE
{
   "citationItems": [
  {
    "DOI": "10.1371/journal.pone.0010676",
    "URL": "http://dx.doi.org/10.1371/journal.pone.0010676",
    "author": [
      {
        "family": "Williams",
        "given": "Jeffrey T."
      },
      {
        "family": "Carpenter",
        "given": "Kent E."
      },
      {
        "family": "Tassell",
        "given": "James L. Van"
      },
      {
        "family": "Hoetjes",
        "given": "Paul"
      },
      {
        "family": "Toller",
        "given": "Wes"
      },
      {
        "family": "Etnoyer",
        "given": "Peter"
      },
      {
        "family": "Smith",
        "given": "Michael"
      }
    ],
    "container-title": "PLoS ONE",
    "editor": [
      {
        "family": "Gratwicke",
        "given": "Brian"
      }
    ],
    "id": "Williams_2010",
    "issue": "5",
    "issued": {
      "date-parts": [
        [
          2010,
          5
        ]
      ]
    },
    "page": "e10676",
    "publisher": "Public Library of Science (PLoS)",
    "title": "Biodiversity Assessment of the Fishes of Saba Bank Atoll, Netherlands Antilles",
    "type": "article-journal",
    "volume": "5"
  }
]
}
#+END_EXAMPLE

#+BEGIN_SRC emacs-lisp :var data=bib-json
(let* ((proc (citeproc-create-style "csl-styles/apa-5th-edition.csl"
                    (citeproc-locale-getter-from-dir "csl-locales")))
       (item-data (json-parse-string data :object-type 'alist :array-type 'list)))

 (citeproc-render-item item-data proc 'cite 'plain))
#+END_SRC

#+RESULTS:
: n.d.
andras-simonyi commented 3 years ago

Actually your example is almost perfect, the only change needed is to have just the item's description in the JSON, without "citationItems":

#+name: bib-json
#+BEGIN_EXAMPLE
  {
      "DOI": "10.1371/journal.pone.0010676",
      "URL": "http://dx.doi.org/10.1371/journal.pone.0010676",
      "author": [
    {
      "family": "Williams",
      "given": "Jeffrey T."
    },
    {
      "family": "Carpenter",
      "given": "Kent E."
    },
    {
      "family": "Tassell",
      "given": "James L. Van"
    },
    {
      "family": "Hoetjes",
      "given": "Paul"
    },
    {
      "family": "Toller",
      "given": "Wes"
    },
    {
      "family": "Etnoyer",
      "given": "Peter"
    },
    {
      "family": "Smith",
      "given": "Michael"
    }
      ],
      "container-title": "PLoS ONE",
      "editor": [
    {
      "family": "Gratwicke",
      "given": "Brian"
    }
      ],
      "id": "Williams_2010",
      "issue": "5",
      "issued": {
    "date-parts": [
      [
        2010,
        5
      ]
    ]
      },
      "page": "e10676",
      "publisher": "Public Library of Science (PLoS)",
      "title": "Biodiversity Assessment of the Fishes of Saba Bank Atoll, Netherlands Antilles",
      "type": "article-journal",
      "volume": "5"
    }
#+END_EXAMPLE
jkitchin commented 3 years ago

Indeed, that does work, thanks!