mirror of
https://github.com/wassname/template.git
synced 2026-07-04 22:13:37 +08:00
Add support for external bibtex files
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const path = require('path');
|
||||
const program = require('commander');
|
||||
const jsdom = require('jsdom');
|
||||
const { JSDOM } = jsdom;
|
||||
@@ -20,6 +21,8 @@ JSDOM.fromFile(program.input, options).then(dom => {
|
||||
const document = window.document;
|
||||
|
||||
const data = new transforms.FrontMatter;
|
||||
data.inputHTMLPath = program.input; // may be needed to resolve relative links!
|
||||
data.inputDirectory = path.dirname(program.input);
|
||||
transforms.render(document, data);
|
||||
transforms.distillify(document, data);
|
||||
|
||||
|
||||
+2
-105
@@ -5,7 +5,7 @@
|
||||
|
||||
<d-front-matter>
|
||||
<script id='distill-front-matter' type="text/json">{
|
||||
"title": "Demo Title Attention and Augmented Recurrent Neural Networks",
|
||||
"title": "How to Use t-SNE Effectively",
|
||||
"published": "Jan 10, 2017",
|
||||
"authors": [
|
||||
{
|
||||
@@ -34,7 +34,6 @@
|
||||
|
||||
<body>
|
||||
<d-article>
|
||||
<h1>How to Use t-SNE Effectively</h1>
|
||||
<h2>Although extremely useful for visualizing high-dimensional data, t-SNE plots can sometimes be mysterious or misleading.</h2>
|
||||
<d-byline></d-byline>
|
||||
<!-- <d-abstract>
|
||||
@@ -124,109 +123,7 @@
|
||||
|
||||
<d-footnote-list></d-footnote-list>
|
||||
|
||||
<d-bibliography><script type="text/bibtex">
|
||||
|
||||
@article{gregor2015draw,
|
||||
title={DRAW: A recurrent neural network for image generation},
|
||||
author={Gregor, Karol and Danihelka, Ivo and Graves, Alex and Rezende, Danilo Jimenez and Wierstra, Daan},
|
||||
journal={arXiv preprint arXiv:1502.04623},
|
||||
year={2015},
|
||||
url ={https://arxiv.org/pdf/1502.04623.pdf}
|
||||
}
|
||||
@article{mercier2011humans,
|
||||
title={Why do humans reason? Arguments for an argumentative theory},
|
||||
author={Mercier, Hugo and Sperber, Dan},
|
||||
journal={Behavioral and brain sciences},
|
||||
volume={34},
|
||||
number={02},
|
||||
pages={57--74},
|
||||
year={2011},
|
||||
publisher={Cambridge Univ Press},
|
||||
doi={10.1017/S0140525X10000968}
|
||||
}
|
||||
|
||||
@article{dong2014image,
|
||||
title={Image super-resolution using deep convolutional networks},
|
||||
author={Dong, Chao and Loy, Chen Change and He, Kaiming and Tang, Xiaoou},
|
||||
journal={arXiv preprint arXiv:1501.00092},
|
||||
year={2014},
|
||||
url={https://arxiv.org/pdf/1501.00092.pdf}
|
||||
}
|
||||
|
||||
@article{dumoulin2016adversarially,
|
||||
title={Adversarially Learned Inference},
|
||||
author={Dumoulin, Vincent and Belghazi, Ishmael and Poole, Ben and Lamb, Alex and Arjovsky, Martin and Mastropietro, Olivier and Courville, Aaron},
|
||||
journal={arXiv preprint arXiv:1606.00704},
|
||||
year={2016},
|
||||
url={https://arxiv.org/pdf/1606.00704.pdf}
|
||||
}
|
||||
|
||||
@article{dumoulin2016guide,
|
||||
title={A guide to convolution arithmetic for deep learning},
|
||||
author={Dumoulin, Vincent and Visin, Francesco},
|
||||
journal={arXiv preprint arXiv:1603.07285},
|
||||
year={2016},
|
||||
url={https://arxiv.org/pdf/1603.07285.pdf}
|
||||
}
|
||||
|
||||
@article{gauthier2014conditional,
|
||||
title={Conditional generative adversarial nets for convolutional face generation},
|
||||
author={Gauthier, Jon},
|
||||
journal={Class Project for Stanford CS231N: Convolutional Neural Networks for Visual Recognition, Winter semester},
|
||||
volume={2014},
|
||||
year={2014},
|
||||
url={http://www.foldl.me/uploads/papers/tr-cgans.pdf}
|
||||
}
|
||||
|
||||
@article{johnson2016perceptual,
|
||||
title={Perceptual losses for real-time style transfer and super-resolution},
|
||||
author={Johnson, Justin and Alahi, Alexandre and Fei-Fei, Li},
|
||||
journal={arXiv preprint arXiv:1603.08155},
|
||||
year={2016},
|
||||
url={https://arxiv.org/pdf/1603.08155.pdf}
|
||||
}
|
||||
|
||||
@article{mordvintsev2015inceptionism,
|
||||
title={Inceptionism: Going deeper into neural networks},
|
||||
author={Mordvintsev, Alexander and Olah, Christopher and Tyka, Mike},
|
||||
journal={Google Research Blog},
|
||||
year={2015},
|
||||
url={https://research.googleblog.com/2015/06/inceptionism-going-deeper-into-neural.html}
|
||||
}
|
||||
|
||||
@misc{mordvintsev2016deepdreaming,
|
||||
title={DeepDreaming with TensorFlow},
|
||||
author={Mordvintsev, Alexander},
|
||||
year={2016},
|
||||
url={https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/tutorials/deepdream/deepdream.ipynb},
|
||||
}
|
||||
|
||||
@article{radford2015unsupervised,
|
||||
title={Unsupervised representation learning with deep convolutional generative adversarial networks},
|
||||
author={Radford, Alec and Metz, Luke and Chintala, Soumith},
|
||||
journal={arXiv preprint arXiv:1511.06434},
|
||||
year={2015},
|
||||
url={https://arxiv.org/pdf/1511.06434.pdf}
|
||||
}
|
||||
|
||||
@inproceedings{salimans2016improved,
|
||||
title={Improved techniques for training gans},
|
||||
author={Salimans, Tim and Goodfellow, Ian and Zaremba, Wojciech and Cheung, Vicki and Radford, Alec and Chen, Xi},
|
||||
booktitle={Advances in Neural Information Processing Systems},
|
||||
pages={2226--2234},
|
||||
year={2016},
|
||||
url={https://arxiv.org/pdf/1606.03498.pdf}
|
||||
}
|
||||
|
||||
@article{shi2016deconvolution,
|
||||
title={Is the deconvolution layer the same as a convolutional layer?},
|
||||
author={Shi, Wenzhe and Caballero, Jose and Theis, Lucas and Huszar, Ferenc and Aitken, Andrew and Ledig, Christian and Wang, Zehan},
|
||||
journal={arXiv preprint arXiv:1609.07009},
|
||||
year={2016},
|
||||
url={https://arxiv.org/pdf/1609.07009.pdf}
|
||||
}
|
||||
|
||||
</script></d-bibliography>
|
||||
<d-bibliography src="bibliography.bib"></d-bibliography>
|
||||
|
||||
<distill-appendix> </distill-appendix>
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
@article{gregor2015draw,
|
||||
title={DRAW: A recurrent neural network for image generation},
|
||||
author={Gregor, Karol and Danihelka, Ivo and Graves, Alex and Rezende, Danilo Jimenez and Wierstra, Daan},
|
||||
journal={arXivreprint arXiv:1502.04623},
|
||||
year={2015}
|
||||
journal={arXiv preprint arXiv:1502.04623},
|
||||
year={2015},
|
||||
url ={https://arxiv.org/pdf/1502.04623.pdf}
|
||||
}
|
||||
@article{mercier2011humans,
|
||||
title={Why do humans reason? Arguments for an argumentative theory},
|
||||
@@ -12,5 +13,87 @@
|
||||
number={02},
|
||||
pages={57--74},
|
||||
year={2011},
|
||||
publisher={Cambridge Univ Press}
|
||||
publisher={Cambridge Univ Press},
|
||||
doi={10.1017/S0140525X10000968}
|
||||
}
|
||||
|
||||
@article{dong2014image,
|
||||
title={Image super-resolution using deep convolutional networks},
|
||||
author={Dong, Chao and Loy, Chen Change and He, Kaiming and Tang, Xiaoou},
|
||||
journal={arXiv preprint arXiv:1501.00092},
|
||||
year={2014},
|
||||
url={https://arxiv.org/pdf/1501.00092.pdf}
|
||||
}
|
||||
|
||||
@article{dumoulin2016adversarially,
|
||||
title={Adversarially Learned Inference},
|
||||
author={Dumoulin, Vincent and Belghazi, Ishmael and Poole, Ben and Lamb, Alex and Arjovsky, Martin and Mastropietro, Olivier and Courville, Aaron},
|
||||
journal={arXiv preprint arXiv:1606.00704},
|
||||
year={2016},
|
||||
url={https://arxiv.org/pdf/1606.00704.pdf}
|
||||
}
|
||||
|
||||
@article{dumoulin2016guide,
|
||||
title={A guide to convolution arithmetic for deep learning},
|
||||
author={Dumoulin, Vincent and Visin, Francesco},
|
||||
journal={arXiv preprint arXiv:1603.07285},
|
||||
year={2016},
|
||||
url={https://arxiv.org/pdf/1603.07285.pdf}
|
||||
}
|
||||
|
||||
@article{gauthier2014conditional,
|
||||
title={Conditional generative adversarial nets for convolutional face generation},
|
||||
author={Gauthier, Jon},
|
||||
journal={Class Project for Stanford CS231N: Convolutional Neural Networks for Visual Recognition, Winter semester},
|
||||
volume={2014},
|
||||
year={2014},
|
||||
url={http://www.foldl.me/uploads/papers/tr-cgans.pdf}
|
||||
}
|
||||
|
||||
@article{johnson2016perceptual,
|
||||
title={Perceptual losses for real-time style transfer and super-resolution},
|
||||
author={Johnson, Justin and Alahi, Alexandre and Fei-Fei, Li},
|
||||
journal={arXiv preprint arXiv:1603.08155},
|
||||
year={2016},
|
||||
url={https://arxiv.org/pdf/1603.08155.pdf}
|
||||
}
|
||||
|
||||
@article{mordvintsev2015inceptionism,
|
||||
title={Inceptionism: Going deeper into neural networks},
|
||||
author={Mordvintsev, Alexander and Olah, Christopher and Tyka, Mike},
|
||||
journal={Google Research Blog},
|
||||
year={2015},
|
||||
url={https://research.googleblog.com/2015/06/inceptionism-going-deeper-into-neural.html}
|
||||
}
|
||||
|
||||
@misc{mordvintsev2016deepdreaming,
|
||||
title={DeepDreaming with TensorFlow},
|
||||
author={Mordvintsev, Alexander},
|
||||
year={2016},
|
||||
url={https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/tutorials/deepdream/deepdream.ipynb},
|
||||
}
|
||||
|
||||
@article{radford2015unsupervised,
|
||||
title={Unsupervised representation learning with deep convolutional generative adversarial networks},
|
||||
author={Radford, Alec and Metz, Luke and Chintala, Soumith},
|
||||
journal={arXiv preprint arXiv:1511.06434},
|
||||
year={2015},
|
||||
url={https://arxiv.org/pdf/1511.06434.pdf}
|
||||
}
|
||||
|
||||
@inproceedings{salimans2016improved,
|
||||
title={Improved techniques for training gans},
|
||||
author={Salimans, Tim and Goodfellow, Ian and Zaremba, Wojciech and Cheung, Vicki and Radford, Alec and Chen, Xi},
|
||||
booktitle={Advances in Neural Information Processing Systems},
|
||||
pages={2226--2234},
|
||||
year={2016},
|
||||
url={https://arxiv.org/pdf/1606.03498.pdf}
|
||||
}
|
||||
|
||||
@article{shi2016deconvolution,
|
||||
title={Is the deconvolution layer the same as a convolutional layer?},
|
||||
author={Shi, Wenzhe and Caballero, Jose and Theis, Lucas and Huszar, Ferenc and Aitken, Andrew and Ledig, Christian and Wang, Zehan},
|
||||
journal={arXiv preprint arXiv:1609.07009},
|
||||
year={2016},
|
||||
url={https://arxiv.org/pdf/1609.07009.pdf}
|
||||
}
|
||||
|
||||
@@ -36,13 +36,11 @@ export const templateString = `
|
||||
<h3>References</h3>
|
||||
<ol class='references' id='references-list' ></ol>
|
||||
`;
|
||||
const T = Template('d-bibliography', templateString);
|
||||
|
||||
export function parseBibliography(element) {
|
||||
if (element.firstElementChild && element.firstElementChild.tagName === 'SCRIPT') {
|
||||
const bibtex = element.firstElementChild.textContent;
|
||||
const bibliography = parseBibtex(bibtex);
|
||||
return bibliography;
|
||||
return parseBibtex(bibtex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +61,7 @@ export function renderBibliography(element, entries) {
|
||||
}
|
||||
}
|
||||
|
||||
const T = Template('d-bibliography', templateString);
|
||||
export class Bibliography extends T(HTMLElement) {
|
||||
|
||||
constructor() {
|
||||
@@ -81,13 +80,20 @@ export class Bibliography extends T(HTMLElement) {
|
||||
}
|
||||
|
||||
parseIfPossible() {
|
||||
if (this.firstElementChild && this.firstElementChild.tagName === 'SCRIPT') {
|
||||
const newBibtex = this.firstElementChild.textContent;
|
||||
const scriptTag = this.querySelector('script');
|
||||
if (!scriptTag) return;
|
||||
if (scriptTag.type == 'text/bibtex') {
|
||||
const newBibtex = scriptTag.textContent;
|
||||
if (this.bibtex !== newBibtex) {
|
||||
this.bibtex = newBibtex;
|
||||
const bibliography = parseBibtex(this.bibtex);
|
||||
this.notify(bibliography);
|
||||
}
|
||||
} else if (scriptTag.type == 'text/json') {
|
||||
const bibliography = new Map(JSON.parse(scriptTag.textContent));
|
||||
this.notify(bibliography);
|
||||
} else {
|
||||
console.warn('Unsupported bibliography script tag type: ' + scriptTag.type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,4 +107,25 @@ export class Bibliography extends T(HTMLElement) {
|
||||
renderBibliography(this.root, newEntries);
|
||||
}
|
||||
|
||||
/* observe 'src' attribute */
|
||||
|
||||
static get observedAttributes() {
|
||||
return ['src'];
|
||||
}
|
||||
|
||||
receivedBibtex(event) {
|
||||
const bibliography = parseBibtex(event.target.response);
|
||||
this.notify(bibliography);
|
||||
}
|
||||
|
||||
attributeChangedCallback(name, oldValue, newValue) {
|
||||
var oReq = new XMLHttpRequest();
|
||||
oReq.onload = (e) => this.receivedBibtex(e);
|
||||
oReq.onerror = () => console.warn(`Could not load Bibtex! (tried ${newValue})`);
|
||||
oReq.responseType = 'text';
|
||||
oReq.open('GET', newValue, true);
|
||||
oReq.send();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// import ymlParse from 'js-yaml';
|
||||
|
||||
export function parseFrontmatter(element) {
|
||||
const scriptTag = element.querySelector('script');
|
||||
if (scriptTag) {
|
||||
|
||||
+4
-3
@@ -22,10 +22,10 @@ import Meta from './transforms/meta';
|
||||
import { makeStyleTag } from './styles/styles';
|
||||
import TOC from './transforms/toc';
|
||||
import Typeset from './transforms/typeset';
|
||||
// import Bibliography from './transforms/bibliography';
|
||||
import Bibliography from './transforms/bibliography';
|
||||
|
||||
const transforms = [
|
||||
HTML, makeStyleTag, TOC, Byline, Polyfills, Mathematics, Meta, Typeset//, Bibliography
|
||||
HTML, makeStyleTag, TOC, Byline, Polyfills, Mathematics, Meta, Typeset, Bibliography
|
||||
];
|
||||
|
||||
/* Distill Transforms */
|
||||
@@ -42,11 +42,12 @@ const distillTransforms = [
|
||||
export function render(dom, data) {
|
||||
// first, we collect static data from the dom
|
||||
for (const extract of extractors) {
|
||||
// console.warn('Running extractor: ', extract);
|
||||
console.warn('Running extractor...');
|
||||
extract(dom, data);
|
||||
}
|
||||
// secondly we use it to transform parts of the dom
|
||||
for (const transform of transforms) {
|
||||
console.warn('Running transform...');
|
||||
// console.warn('Running transform: ', transform);
|
||||
transform(dom, data);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,39 @@
|
||||
import { renderBibliography, templateString } from '../components/d-bibliography';
|
||||
import { parseBibtex } from '../helpers/bibtex';
|
||||
import fs from 'fs';
|
||||
|
||||
export default function(dom, data) {
|
||||
const bibliographyTag = dom.querySelector('d-bibliography');
|
||||
if (!bibliographyTag) {
|
||||
console.warn('No bibliography tag found!');
|
||||
console.warn('No bibliography tag present!');
|
||||
return;
|
||||
}
|
||||
|
||||
const bibliographyEntries = new Map(data.citations.map( citationKey => {
|
||||
const entry = data.bibliography.get(citationKey);
|
||||
return [citationKey, entry];
|
||||
}));
|
||||
|
||||
const prerenderedBibliography = dom.createElement('d-bibliography-prerendered');
|
||||
|
||||
const template = dom.createElement('template');
|
||||
template.innerHTML = templateString;
|
||||
const clone = dom.importNode(template.content, true);
|
||||
prerenderedBibliography.innerHTML = template.content;
|
||||
renderBibliography(prerenderedBibliography, bibliographyEntries, dom);
|
||||
|
||||
bibliographyTag.parentElement.insertBefore(bibliographyTag, prerenderedBibliography);
|
||||
bibliographyTag.parentElement.removeChild(bibliographyTag);
|
||||
const src = bibliographyTag.getAttribute('src');
|
||||
if (src) {
|
||||
const path = data.inputDirectory + '/' + src;
|
||||
const text = fs.readFileSync(path, 'utf-8');
|
||||
const bibliography = parseBibtex(text);
|
||||
const scriptTag = dom.createElement('script');
|
||||
scriptTag.type = 'text/json';
|
||||
scriptTag.textContent = JSON.stringify([...bibliography]);
|
||||
bibliographyTag.appendChild(scriptTag);
|
||||
bibliographyTag.removeAttribute('src');
|
||||
}
|
||||
// const bibliographyEntries = new Map(data.citations.map( citationKey => {
|
||||
// const entry = data.bibliography.get(citationKey);
|
||||
// return [citationKey, entry];
|
||||
// }));
|
||||
//
|
||||
// const prerenderedBibliography = dom.createElement('d-bibliography-prerendered');
|
||||
//
|
||||
// const template = dom.createElement('template');
|
||||
// template.innerHTML = templateString;
|
||||
// const clone = dom.importNode(template.content, true);
|
||||
// prerenderedBibliography.innerHTML = template.content;
|
||||
// renderBibliography(prerenderedBibliography, bibliographyEntries, dom);
|
||||
//
|
||||
// bibliographyTag.parentElement.insertBefore(bibliographyTag, prerenderedBibliography);
|
||||
// bibliographyTag.parentElement.removeChild(bibliographyTag);
|
||||
|
||||
}
|
||||
|
||||
@@ -42,11 +42,5 @@ export default function render(dom) {
|
||||
polyfillScriptTag.id = 'polyfills';
|
||||
|
||||
// insert at appropriate position--before any other script tag
|
||||
const head = dom.querySelector('head');
|
||||
const firstScriptTag = dom.querySelector('script');
|
||||
if (firstScriptTag) {
|
||||
head.insertBefore(polyfillScriptTag, firstScriptTag);
|
||||
} else {
|
||||
head.appendChild(polyfillScriptTag);
|
||||
}
|
||||
dom.head.insertBefore(polyfillScriptTag, dom.head.firstChild);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@ import { renderTOC } from '../components/d-toc';
|
||||
export default function(dom) {
|
||||
const article = dom.querySelector('d-article');
|
||||
const toc = dom.querySelector('d-toc');
|
||||
const headings = article.querySelectorAll('h2, h3');
|
||||
renderTOC(toc, headings);
|
||||
toc.setAttribute('prerendered', 'true');
|
||||
if (toc) {
|
||||
const headings = article.querySelectorAll('h2, h3');
|
||||
renderTOC(toc, headings);
|
||||
toc.setAttribute('prerendered', 'true');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user