Closed wapp-its closed 3 years ago
Hi @wapp-its! Since citeproc-php is used for very different purposes, I have decided to generate links not automatically. In order to generate links anyway, you can use the feature of the Lambda functions as described here.
<?php
include "vendor/autoload.php";
use Seboettg\CiteProc\StyleSheet;
use Seboettg\CiteProc\CiteProc;
$data = '[
{
"author": [
{
"family": "Einstein",
"given": "Albert"
}
],
"id": "ITEM-3",
"type": "article-journal",
"title": "This is a DOI test",
"DOI": "10.1016/j.baae.2020.04.003"
}
]';
$style = StyleSheet::loadStyleSheet("ieee");
$linkDOI = function($citationItem, $renderedText) {
if (isset($citationItem->DOI)) {
return '<a href="https://doi.org/' . $citationItem->DOI . '">' . $renderedText . '</a>';
}
return $renderedText;
};
$citeProc = new CiteProc($style, "en-US", ['DOI' => $linkDOI]);
echo $citeProc->render(json_decode($data), "bibliography");
Result
<div class="csl-bib-body">
<div class="csl-entry"><div class="csl-left-margin">[1]</div><div class="csl-right-inline">A. Einstein, “This is a DOI test”, doi: <a href="https://doi.org/10.1016/j.baae.2020.04.003">10.1016/j.baae.2020.04.003</a>.</div></div>
</div>
According to https://github.com/citation-style-language/documentation/blob/master/specification.rst#appendix-vi-links (clickable) links should be rendered by the csl processor. You can read the discussion that lead to this specification here.
This is not implemented with php-citeproc.
PS the CSL schmema was moved to https://github.com/citation-style-language/schema/blob/master/schemas/input/csl-data.json the issue template still links to (https://github.com/citation-style-language/schema/blob/master/csl-data.json
Used CSL stylesheet:
For example "apa"
Used CSL metadata