Skip to content
This repository has been archived by the owner on Mar 29, 2021. It is now read-only.

Commit

Permalink
4.7.2 (#234)
Browse files Browse the repository at this point in the history
* chore: convert to ts-loader due to breaking api changes in the other

* fix: use https pubmed url rather than http to avoid redirects

Closes #230

* fix: Prevent images just prior to bib/footnotes from being deleted

Closes #226

* fix: vastly improve citation insertion performance.

This commit fixes several issues:

- Fix problem causing citations to not be able to be inserted in image
caption boxes.
- Fix issue causing the carat to be moved to the end of the paragraph
upon inserting a citation.

Closes #224

* chore: update type defs + adjust webpack configs

* chore: update webpack config

* fix: prevent footnotes from being inserted with an empty list

* test: fix failed tests

* chore: update styles

Styles Added:
- Bulletin de la Société Entomologique de France
- Herpetologica
- Presses Universitaires de Rennes - Archéologie et Culture (French)

* chore: update citeproc

* chore: build version 4.7.2
  • Loading branch information
dsifford authored Nov 16, 2016
1 parent c374843 commit c16a7b6
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 134 deletions.
2 changes: 1 addition & 1 deletion ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Please use this template for all bug reports.
Before submitting an issue, please try disabling all other plugins to ensure issue is isolated within ABT
-->

**ABT Version:** 4.7.1
**ABT Version:** 4.7.2

<!-- Which version of PHP are you using with your WordPress installation? -->
**PHP Version:** 5.6
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "academic-bloggers-toolkit",
"version": "4.7.1",
"version": "4.7.2",
"description": "A plugin extending the functionality of WordPress for Academic Blogging.",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -32,7 +32,6 @@
"autoprefixer": "^6.5.1",
"awesome-typescript-loader": "^2.2.4",
"babel-core": "^6.17.0",
"babel-loader": "^6.2.5",
"babel-polyfill": "^6.16.0",
"babel-preset-es2015": "^6.16.0",
"babel-preset-react": "^6.16.0",
Expand All @@ -44,7 +43,7 @@
"eslint": "^3.8.1",
"eslint-config-airbnb-base": "^9.0.0",
"eslint-plugin-import": "^2.0.1",
"gulp": "github:gulpjs/gulp#4.0",
"gulp": "gulpjs/gulp#4.0",
"gulp-replace": "^0.5.4",
"gulp-sort": "^2.0.0",
"gulp-sourcemaps": "^2.1.1",
Expand Down
4 changes: 2 additions & 2 deletions src/academic-bloggers-toolkit.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
* Plugin Name: Academic Blogger's Toolkit
* Plugin URI: https://wordpress.org/plugins/academic-bloggers-toolkit/
* Description: A plugin extending the functionality of Wordpress for academic blogging
* Version: 4.7.1
* Version: 4.7.2
* Author: Derek P Sifford
* Author URI: https://github.com/dsifford
* License: GPL3 or later
* Text Domain: academic-bloggers-toolkit
*/

define('ABT_VERSION', '4.7.1');
define('ABT_VERSION', '4.7.2');

/**
* Load plugin translations
Expand Down
6 changes: 3 additions & 3 deletions src/academic-bloggers-toolkit.pot
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright (C) 2016 Academic Blogger's Toolkit 4.7.1
# This file is distributed under the same license as the Academic Blogger's Toolkit 4.7.1 package.
# Copyright (C) 2016 Academic Blogger's Toolkit 4.7.2
# This file is distributed under the same license as the Academic Blogger's Toolkit 4.7.2 package.
msgid ""
msgstr ""
"Project-Id-Version: Academic Blogger's Toolkit 4.7.1\n"
"Project-Id-Version: Academic Blogger's Toolkit 4.7.2\n"
"Report-Msgid-Bugs-To: https://github.com/dsifford/academic-bloggers-toolkit/issues\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down
3 changes: 2 additions & 1 deletion src/lib/js/reference-list/components/ReferenceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export class ReferenceList extends React.Component<{store: Store}, {}> {
* from it and push it to data.
*/
const selection = this.editor.selection.getContent({ format: 'html' });
if (/<span id="([\d\w]+)" class="(?:abt-citation|abt_cite) ?.+<\/span>/.test(selection)) {
if (/<span.+class="(?:abt-citation|abt_cite).+?<\/span>/.test(selection)) {
const re = /&quot;(\w+?)&quot;/g;
let m: RegExpExecArray;
while ((m = re.exec(selection)) !== null) { // tslint:disable-line:no-conditional-assignment
Expand Down Expand Up @@ -317,6 +317,7 @@ export class ReferenceList extends React.Component<{store: Store}, {}> {

preprocess.then((data) => {

if (data.length === 0) return;
this.props.store.citations.addItems(data);

data = data.reduce((prev, curr) => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/js/tinymce/components/pubmed-window/ResultList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class ResultList extends React.PureComponent<ResultListProps, {}> {
<div children={result.authors.slice(0, 3).map(el => el.name).join(', ') /* tslint:disable-line */} />
<div>
<a
href={`http://www.ncbi.nlm.nih.gov/pubmed/${result.uid}`}
href={`https://www.ncbi.nlm.nih.gov/pubmed/${result.uid}`}
target="_blank"
rel="noopener noreferrer"
style={{paddingLeft: 8, paddingRight: 8}}
Expand Down
8 changes: 4 additions & 4 deletions src/lib/js/utils/HelperFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ export function parseReferenceURL(
case 'PMID': {
return linkedHtml +
`<span class="abt-url"> ` +
`[<a href="http://www.ncbi.nlm.nih.gov/pubmed/${id.value}" target="_blank">PubMed</a>]` +
`[<a href="https://www.ncbi.nlm.nih.gov/pubmed/${id.value}" target="_blank">PubMed</a>]` +
`</span>`;
}
case 'DOI': {
Expand All @@ -338,7 +338,7 @@ export function parseReferenceURL(
case 'PMCID': {
return linkedHtml +
`<span class="abt-url"> ` + // tslint:disable-next-line
`[<a href="http://www.ncbi.nlm.nih.gov/pmc/articles/${id.value}" target="_blank">PMC</a>]` +
`[<a href="https://www.ncbi.nlm.nih.gov/pmc/articles/${id.value}" target="_blank">PMC</a>]` +
`</span>`;
}
case 'URL':
Expand All @@ -353,13 +353,13 @@ export function parseReferenceURL(
case 'always-full-surround': {
switch (id.kind) {
case 'PMID': {
return `<a href="http://www.ncbi.nlm.nih.gov/pubmed/${id.value}" target="_blank">${html}</a>`;
return `<a href="https://www.ncbi.nlm.nih.gov/pubmed/${id.value}" target="_blank">${html}</a>`;
}
case 'DOI': {
return `<a href="https://dx.doi.org/${id.value}" target="_blank">${html}</a>`;
}
case 'PMCID': {
return `<a href="http://www.ncbi.nlm.nih.gov/pmc/articles/${id.value}" target="_blank">${html}</a>`;
return `<a href="https://www.ncbi.nlm.nih.gov/pmc/articles/${id.value}" target="_blank">${html}</a>`; // tslint:disable-line
}
case 'URL':
default: {
Expand Down
150 changes: 65 additions & 85 deletions src/lib/js/utils/TinymceFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ interface CitationPositions {
* @return Parsed citation data.
*/
export function getRelativeCitationPositions(editor: TinyMCE.Editor, validIds: string[]): CitationPositions {
const doc: Document = editor.dom.doc;
const doc = editor.getDoc();
const currentSelection = editor.selection.getContent({ format: 'html' });
const re = /<span id="([\d\w]+)" class="(?:abt-citation|abt_cite) .+<\/span>/;
const id = (currentSelection.match(re) || ['', 'CURSOR'])[1];

if (id === 'CURSOR') {
editor.insertContent(
editor.selection.setContent(
`<span id="CURSOR" class="abt-citation"></span>`
);
}
Expand Down Expand Up @@ -132,20 +132,22 @@ function parseFootnoteCitations(
citationByIndex: Citeproc.CitationByIndex,
): Promise<boolean> {
return new Promise(resolve => {
const doc = editor.dom.doc;
const exisingNote = doc.getElementById('abt-footnote');
const doc = editor.getDoc();
const existingNote = doc.getElementById('abt-footnote');
const existingBib = doc.querySelector('#abt-bibliography, #abt-smart-bib');

if (exisingNote) exisingNote.parentElement.removeChild(exisingNote);
if (existingNote) existingNote.parentElement.removeChild(existingNote);
if (existingBib) existingBib.parentElement.removeChild(existingBib);
if (clusters.length === 0) return resolve(true);

for (const [index, footnote, elementID] of clusters) {
const inlineText = `[${index + 1}]`;
const citation: HTMLSpanElement = editor.dom.doc.getElementById(elementID);
const citation: HTMLSpanElement = doc.getElementById(elementID);
const sortedItems: Citeproc.SortedItems = citationByIndex[index].sortedItems;
const idList: string = JSON.stringify(sortedItems.map(c => c[1].id));

if (!citation) {
editor.insertContent(
editor.selection.setContent(
`<span
id='${elementID}'
data-reflist='${idList}'
Expand All @@ -162,58 +164,42 @@ function parseFootnoteCitations(
citation.dataset['footnote'] = footnote;
}

const note = doc.createElement('div');
note.id = 'abt-footnote';
note.className = 'abt-footnote noselect mceNonEditable';
const bm = editor.selection.getBookmark();

const note = editor.dom.create<HTMLDivElement>('div', {
class: 'abt-footnote noselect mceNonEditable',
id: 'abt-footnote',
});
const heading = editor.dom.create<HTMLDivElement>('div', {
class: 'abt-footnote__heading',
}, top.ABT_i18n.misc.footnotes);

const heading = doc.createElement('div');
heading.className = 'abt-footnote__heading';
heading.innerText = top.ABT_i18n.misc.footnotes;
note.appendChild(heading);

const citations = <NodeListOf<HTMLSpanElement>>doc.querySelectorAll('.abt-citation, .abt_cite');

[...citations].forEach((c, i) => {
c.innerText = `[${i + 1}]`;

/**
* Iterate and set a new footnote box using stored html on the inline notes.
* "Isn't this really inefficient?". Yes. It's citeproc-js's fault.
*/
const div = doc.createElement('div');
div.className = 'abt-footnote__item';
div.innerHTML =
const noteItem = editor.dom.create<HTMLDivElement>('div', {
class: 'abt-footnote__item',
},
`<span class="abt-footnote__number">[${i + 1}]</span>` +
`<span class="abt-footnote__content">${c.dataset['footnote']}</span>`;
note.appendChild(div);
`<span class="abt-footnote__content">${c.dataset['footnote']}</span>`
);
note.appendChild(noteItem);
});
editor.getBody().appendChild(note);

const bib = doc.querySelector('#abt-bibliography, #abt-smart-bib');

// Save a reference to the current cursor location
const selection = editor.selection;
const cursor = editor.dom.create('span', { class: 'abt-citation', id: 'CURSOR' });
selection.getNode().appendChild(cursor);

// Do work
if (bib) bib.parentNode.removeChild(bib);

editor.setContent(editor.getContent() + note.outerHTML);

// Move cursor back to where it was & delete reference
const el = doc.getElementById('CURSOR');
if (el) {
editor.selection.select(el, true);
editor.selection.collapse(true);
el.parentElement.removeChild(el);
}

// Remove unnecessary &nbsp; from editor
const p = editor.dom.doc.getElementById('abt-footnote').previousElementSibling;
if (p.tagName === 'P' && p.textContent.trim() === '') {
while (
note.previousElementSibling
&& note.previousElementSibling.childNodes.length === 1
&& note.previousElementSibling.childNodes[0].nodeName === 'BR') {
const p = note.previousElementSibling;
p.parentNode.removeChild(p);
}
resolve(true);
editor.setContent(editor.getBody().innerHTML);
editor.selection.moveToBookmark(bm);

return resolve(true);
});
}

Expand All @@ -224,16 +210,16 @@ function parseInTextCitations(
): Promise<boolean> {
return new Promise(resolve => {
const doc = editor.dom.doc;
const exisingNote = doc.getElementById('abt-footnote');
if (exisingNote) exisingNote.parentElement.removeChild(exisingNote);
const existingNote = doc.getElementById('abt-footnote');
if (existingNote) existingNote.parentElement.removeChild(existingNote);

for (const [index, inlineText, elementID] of clusters) {
const citation: HTMLSpanElement = editor.dom.doc.getElementById(elementID);
const sortedItems: Citeproc.SortedItems = citationByIndex[index].sortedItems;
const idList: string = JSON.stringify(sortedItems.map(c => c[1].id));

if (!citation) {
editor.insertContent(
editor.selection.setContent(
`<span
id='${elementID}'
data-reflist='${idList}'
Expand Down Expand Up @@ -263,62 +249,56 @@ export function setBibliography(
bibliography: ABT.Bibliography|boolean,
options: {heading: string, style: 'fixed'|'toggle'}
): void {
const doc = editor.dom.doc;
const doc = editor.getDoc();
const existingBib = doc.querySelector('#abt-bibliography, #abt-smart-bib');
if (existingBib) existingBib.parentElement.removeChild(existingBib);

if (typeof bibliography === 'boolean') {
if (existingBib) existingBib.parentElement.removeChild(existingBib);
return;
}
if (typeof bibliography === 'boolean') return;

const bm = editor.selection.getBookmark();

const bib = doc.createElement('div');
bib.id = 'abt-bibliography';
bib.className = 'abt-bibliography noselect mceNonEditable';
const bib = editor.dom.create<HTMLDivElement>('div', {
class: 'abt-bibliography noselect mceNonEditable',
id: 'abt-bibliography',
});

const container = doc.createElement('div');
container.id = container.className = 'abt-bibliography__container';
const container = editor.dom.create<HTMLDivElement>('div', {
class: 'abt-bibliography__container',
id: 'abt-bibliography__container',
});

if (options.heading) {
const heading = doc.createElement('h3');
const heading = editor.dom.create<HTMLHeadingElement>('h3', {
class: 'abt-bibliography__heading',
});
heading.innerText = options.heading;
heading.classList.add('abt-bibliography__heading');
if (options.style === 'toggle') heading.classList.add('abt-bibliography__heading_toggle');
bib.appendChild(heading);
}

bib.appendChild(container);

for (const meta of bibliography) {
const item = doc.createElement('div');
item.id = meta.id;
item.innerHTML = meta.html;
const item = editor.dom.create<HTMLDivElement>('div', {
id: meta.id,
}, meta.html);
container.appendChild(item);
}

if (existingBib) existingBib.parentElement.removeChild(existingBib);
if (container.children.length === 0) return;

// Save a reference to the current cursor location
const selection = editor.selection;
const cursor = editor.dom.create('span', { class: 'abt-citation', id: 'CURSOR' });
selection.getNode().appendChild(cursor);

// Do work
editor.setContent(editor.getContent() + bib.outerHTML);

// Move cursor back to where it was & delete reference
const el = editor.dom.doc.getElementById('CURSOR');
if (el) {
editor.selection.select(el, true);
editor.selection.collapse(true);
el.parentElement.removeChild(el);
if (container.children.length > 0) {
editor.getBody().appendChild(bib);
}

// Remove unnecessary &nbsp; from editor
const p = editor.dom.doc.getElementById('abt-bibliography').previousElementSibling;
if (p.tagName === 'P' && p.textContent.trim() === '') {
while (
bib.previousElementSibling
&& bib.previousElementSibling.childNodes.length === 1
&& bib.previousElementSibling.childNodes[0].nodeName === 'BR') {
const p = bib.previousElementSibling;
p.parentNode.removeChild(p);
}
editor.setContent(editor.getBody().innerHTML);
editor.selection.moveToBookmark(bm);
}

export function reset(doc: HTMLDocument) {
Expand Down
Loading

0 comments on commit c16a7b6

Please sign in to comment.