Skip to content

Commit

Permalink
#20 Mendeley LW support for links to references
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy-1 committed Nov 14, 2020
1 parent 11df6f2 commit 0c230f1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/docx2jats/jats/Par.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@

class Par extends Element {

public function __construct(DataObject $dataObject)
{
public function __construct(DataObject $dataObject) {
parent::__construct($dataObject);

}

public function setContent() {

$prevTextRefs = [];
foreach ($this->getDataObject()->getContent() as $content) {
if (get_class($content) === 'docx2jats\objectModel\body\Field') {
// Write links to references
// Write links to references from Zotero and Mendeley plugin for MS Word
if ($content->getType() === Field::DOCX_FIELD_CSL) {
$lastKey = array_key_last($content->getRefIds());
foreach ($content->getRefIds() as $key => $id) {
Expand Down Expand Up @@ -54,8 +52,27 @@ public function setContent() {
$refEl->setAttribute('rid', Figure::JATS_FIGURE_ID_PREFIX . $figureIdRef);
}
}
$prevTextRefs = []; // restart track of refs from Mendeley LW plugin
} else {
JatsText::extractText($content, $this);
// Write links to references from Mendeley plugin for LibreOffice Writer
/* @var $content \docx2jats\objectModel\body\Text */
if ($content->hasCSLRefs) {
$currentRefs = $content->refIds;
foreach ($currentRefs as $currentRefId) {
if (!in_array($currentRefId, $prevTextRefs)) {
$refEl = $this->ownerDocument->createElement('xref', $currentRefId);
$this->appendChild($refEl);
$refEl->setAttribute('ref-type', 'bibr');
$refEl->setAttribute('rid', Reference::JATS_REF_ID_PREFIX . $currentRefId);
}
}
$prevTextRefs = $currentRefs;
}
// Write other text
else {
JatsText::extractText($content, $this);
$prevTextRefs = []; // restart track of refs from Mendeley LW plugin
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/docx2jats/objectModel/body/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ private function setBookmarks(): void {
}
}
}
$this->refIds = array_unique($this->refIds); // TODO explore why Mendeley LW plugin includes duplicates of refs into a single text run
}

/**
Expand Down

0 comments on commit 0c230f1

Please sign in to comment.