diff --git a/examples/article-no-citations.html b/examples/article-no-citations.html
new file mode 100644
index 0000000..c96701a
--- /dev/null
+++ b/examples/article-no-citations.html
@@ -0,0 +1,188 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Attention and Augmented Recurrent Neural Networks
+
+
+
+
+ This is the first paragraph of the article. Test a long — dash -- here it is.
+
+ This is the first paragraph of the article. Test a long — dash -- here it is.
+ Test for owner's possessive. Test for "quoting a passage." And another sentence. Or two. Some flopping fins; for diving.
+
+
+ Here's a test of an inline equation c = a^2 + b^2. And then there's a block equation:
+
+ c = \pm \sqrt{ \sum_{i=0}^{n}{a^{222} + b^2}}
+
+
+
+ | First | Second | Third |
+
+
+ | 23 | 654 | 23 |
+ | 14 | 54 | 34 |
+ | 234 | 54 | 23 |
+
+
+ Displaying code snippets
+ Some inline javascript:var x = 25;
+ Here's a javascript code block.
+
+ var x = 25;
+ function(x){
+ return x * x;
+ }
+
+ We also support python.
+
+ # Python 3: Fibonacci series up to n
+ def fib(n):
+ a, b = 0, 1
+ while a < n:
+ print(a, end=' ')
+ a, b = b, a+b
+
+ That's it for the example article!
+
+
+
+
+
+ Contributions
+ Some text describing who did what.
+ Reviewers
+ Some text with links describing who reviewed the article.
+
+
+
+
+
+
+
+
+
diff --git a/src/components/d-cite.js b/src/components/d-cite.js
index e0f6340..659a4dc 100644
--- a/src/components/d-cite.js
+++ b/src/components/d-cite.js
@@ -72,6 +72,12 @@ export class Cite extends T(HTMLElement) {
}
+ disconnectedCallback() {
+ const options = { detail: [this, this.keys], bubbles: true };
+ const event = new CustomEvent('onCiteKeyRemoved', options);
+ document.dispatchEvent(event);
+ }
+
/* Observed Attributes */
// renderCitationNumbers(citations) {
diff --git a/src/controller.js b/src/controller.js
index 09032d5..4b1fd66 100644
--- a/src/controller.js
+++ b/src/controller.js
@@ -17,14 +17,14 @@ export const Controller = {
const [citeTag, keys] = event.detail;
// ensure we have citations
- if (frontMatter.citations.length === 0) {
+ if (!frontMatter.citationsCollected) {
// console.debug('onCiteKeyCreated, but unresolved dependency ("citations"). Enqueing.');
Controller.waitingOn.citations.push(() => Controller.listeners.onCiteKeyCreated(event));
return;
}
// ensure we have a loaded bibliography
- if (frontMatter.bibliography.size === 0) {
+ if (!frontMatter.bibliographyParsed) {
// console.debug('onCiteKeyCreated, but unresolved dependency ("bibliography"). Enqueing.');
Controller.waitingOn.bibliography.push(() => Controller.listeners.onCiteKeyCreated(event));
return;
@@ -37,11 +37,12 @@ export const Controller = {
},
onCiteKeyChanged(event) {
- const [citeTag, keys] = event.detail;
+ // const [citeTag, keys] = event.detail;
// update citations
frontMatter.citations = collectCitations();
- for (const waitingCallback of Controller.waitingOn.citations) {
+ frontMatter.citationsCollected = true;
+ for (const waitingCallback of Controller.waitingOn.citations.slice()) {
waitingCallback();
}
@@ -61,10 +62,10 @@ export const Controller = {
citeTag.entries = entries;
}
- const numbers = keys.map( key => frontMatter.citations.indexOf(key) );
- citeTag.numbers = numbers;
- const entries = keys.map( key => frontMatter.bibliography.get(key) );
- citeTag.entries = entries;
+ },
+
+ onCiteKeyRemoved(event) {
+ Controller.listeners.onCiteKeyChanged(event);
},
onBibliographyChanged(event) {
@@ -72,12 +73,13 @@ export const Controller = {
const bibliography = event.detail;
frontMatter.bibliography = bibliography;
- for (const waitingCallback of Controller.waitingOn.bibliography) {
+ frontMatter.bibliographyParsed = true;
+ for (const waitingCallback of Controller.waitingOn.bibliography.slice()) {
waitingCallback();
}
// ensure we have citations
- if (frontMatter.citations.length === 0) {
+ if (!frontMatter.citationsCollected) {
Controller.waitingOn.citations.push( function() {
Controller.listeners.onBibliographyChanged({target: event.target, detail: event.detail});
});
@@ -87,6 +89,7 @@ export const Controller = {
const entries = new Map(frontMatter.citations.map( citationKey => {
return [citationKey, frontMatter.bibliography.get(citationKey)];
}));
+
bibliographyTag.entries = entries;
},
@@ -122,7 +125,8 @@ export const Controller = {
// console.debug('Resolving "citations" dependency due to initial DOM load.');
frontMatter.citations = collectCitations();
- for (const waitingCallback of Controller.waitingOn.citations) {
+ frontMatter.citationsCollected = true;
+ for (const waitingCallback of Controller.waitingOn.citations.slice()) {
waitingCallback();
}
diff --git a/src/front-matter.js b/src/front-matter.js
index 0bbf0e5..33f9a57 100644
--- a/src/front-matter.js
+++ b/src/front-matter.js
@@ -33,6 +33,7 @@ export class FrontMatter {
this.authors = []; // Array of Author(s)
this.bibliography = new Map();
+ this.bibliographyParsed = false;
// {
// "gregor2015draw": {
// "title": "DRAW: A recurrent neural network for image generation",
@@ -47,7 +48,7 @@ export class FrontMatter {
// Citation keys should be listed in the order that they are appear in the document.
// Each key refers to a key in the bibliography dictionary.
this.citations = []; // [ "gregor2015draw", "mercier2011humans" ]
-
+ this.citationsCollected = false;
//
// Assigned from posts.csv