{"version":3,"file":"transforms.v2.js","sources":["../src/front-matter.js","../src/components/d-front-matter.js","../src/extractors/front-matter.js","../node_modules/bibtex-parse-js/bibtexParse.js","../src/helpers/bibtex.js","../src/components/d-bibliography.js","../src/extractors/bibliography.js","../src/helpers/citation.js","../src/extractors/citations.js","../src/transforms/html.js","../src/components/d-byline.js","../src/transforms/byline.js","../src/transforms/optional-components.js","../node_modules/katex/dist/katex.js","../src/helpers/katex-auto-render.js","../src/transforms/mathematics.js","../node_modules/escape-html/index.js","../src/transforms/meta.js","../src/styles/styles.js","../src/components/d-toc.js","../src/transforms/toc.js","../src/transforms/typeset.js","../src/transforms/polyfills.js","../src/components/d-citation-list.js","../src/transforms/citation-list.js","../src/transforms/reorder.js","../src/distill-components/distill-header-template.js","../src/distill-transforms/distill-header.js","../src/distill-components/distill-appendix.js","../src/distill-transforms/distill-appendix.js","../src/distill-components/distill-footer-template.js","../src/distill-transforms/distill-footer.js","../src/transforms.js"],"sourcesContent":["// Copyright 2018 The Distill Template Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nconst days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];\nconst months = ['Jan.', 'Feb.', 'March', 'April', 'May', 'June', 'July', 'Aug.', 'Sept.', 'Oct.', 'Nov.', 'Dec.'];\nconst zeroPad = n => n < 10 ? '0' + n : n;\n\nconst RFC = function(date) {\n const day = days[date.getDay()].substring(0, 3);\n const paddedDate = zeroPad(date.getDate());\n const month = months[date.getMonth()].substring(0,3);\n const year = date.getFullYear().toString();\n const hours = date.getUTCHours().toString();\n const minutes = date.getUTCMinutes().toString();\n const seconds = date.getUTCSeconds().toString();\n return `${day}, ${paddedDate} ${month} ${year} ${hours}:${minutes}:${seconds} Z`;\n};\n\nconst objectFromMap = function(map) {\n const object = Array.from(map).reduce((object, [key, value]) => (\n Object.assign(object, { [key]: value }) // Be careful! Maps can have non-String keys; object literals can't.\n ), {});\n return object;\n};\n\nconst mapFromObject = function(object) {\n const map = new Map();\n for (var property in object) {\n if (object.hasOwnProperty(property)) {\n map.set(property, object[property]);\n }\n }\n return map;\n};\n\nclass Author {\n\n // constructor(name='', personalURL='', affiliation='', affiliationURL='') {\n // this.name = name; // 'Chris Olah'\n // this.personalURL = personalURL; // 'https://colah.github.io'\n // this.affiliation = affiliation; // 'Google Brain'\n // this.affiliationURL = affiliationURL; // 'https://g.co/brain'\n // }\n\n constructor(object) {\n this.name = object.author; // 'Chris Olah'\n this.personalURL = object.authorURL; // 'https://colah.github.io'\n this.affiliation = object.affiliation; // 'Google Brain'\n this.affiliationURL = object.affiliationURL; // 'https://g.co/brain'\n this.affiliations = object.affiliations || []; // new-style affiliations\n }\n\n // 'Chris'\n get firstName() {\n const names = this.name.split(' ');\n return names.slice(0, names.length - 1).join(' ');\n }\n\n // 'Olah'\n get lastName() {\n const names = this.name.split(' ');\n return names[names.length -1];\n }\n}\n\nexport function mergeFromYMLFrontmatter(target, source) {\n target.title = source.title;\n if (source.published) {\n if (source.published instanceof Date) {\n target.publishedDate = source.published;\n } else if (source.published.constructor === String) {\n target.publishedDate = new Date(source.published);\n }\n }\n if (source.publishedDate) {\n if (source.publishedDate instanceof Date) {\n target.publishedDate = source.publishedDate;\n } else if (source.publishedDate.constructor === String) {\n target.publishedDate = new Date(source.publishedDate);\n } else {\n console.error('Don\\'t know what to do with published date: ' + source.publishedDate);\n }\n }\n target.description = source.description;\n target.authors = source.authors.map( (authorObject) => new Author(authorObject));\n target.katex = source.katex;\n target.password = source.password;\n if (source.doi) {\n target.doi = source.doi;\n }\n}\n\nexport class FrontMatter {\n constructor() {\n this.title = 'unnamed article'; // 'Attention and Augmented Recurrent Neural Networks'\n this.description = ''; // 'A visual overview of neural attention...'\n this.authors = []; // Array of Author(s)\n\n this.bibliography = new Map();\n this.bibliographyParsed = false;\n // {\n // 'gregor2015draw': {\n // 'title': 'DRAW: A recurrent neural network for image generation',\n // 'author': 'Gregor, Karol and Danihelka, Ivo and Graves, Alex and Rezende, Danilo Jimenez and Wierstra, Daan',\n // 'journal': 'arXiv preprint arXiv:1502.04623',\n // 'year': '2015',\n // 'url': 'https://arxiv.org/pdf/1502.04623.pdf',\n // 'type': 'article'\n // },\n // }\n\n // Citation keys should be listed in the order that they are appear in the document.\n // Each key refers to a key in the bibliography dictionary.\n this.citations = []; // [ 'gregor2015draw', 'mercier2011humans' ]\n this.citationsCollected = false;\n\n //\n // Assigned from posts.csv\n //\n\n // publishedDate: 2016-09-08T07:00:00.000Z,\n // tags: [ 'rnn' ],\n // distillPath: '2016/augmented-rnns',\n // githubPath: 'distillpub/post--augmented-rnns',\n // doiSuffix: 1,\n\n //\n // Assigned from journal\n //\n this.journal = {};\n // journal: {\n // 'title': 'Distill',\n // 'full_title': 'Distill',\n // 'abbrev_title': 'Distill',\n // 'url': 'http://distill.pub',\n // 'doi': '10.23915/distill',\n // 'publisherName': 'Distill Working Group',\n // 'publisherEmail': 'admin@distill.pub',\n // 'issn': '2476-0757',\n // 'editors': [...],\n // 'committee': [...]\n // }\n // volume: 1,\n // issue: 9,\n\n this.katex = {};\n\n //\n // Assigned from publishing process\n //\n\n // githubCompareUpdatesUrl: 'https://github.com/distillpub/post--augmented-rnns/compare/1596e094d8943d2dc0ea445d92071129c6419c59...3bd9209e0c24d020f87cf6152dcecc6017cbc193',\n // updatedDate: 2017-03-21T07:13:16.000Z,\n // doi: '10.23915/distill.00001',\n this.doi = undefined;\n this.publishedDate = undefined;\n }\n\n // Example:\n // title: Demo Title Attention and Augmented Recurrent Neural Networks\n // published: Jan 10, 2017\n // authors:\n // - Chris Olah:\n // - Shan Carter: http://shancarter.com\n // affiliations:\n // - Google Brain:\n // - Google Brain: http://g.co/brain\n\n //\n // Computed Properties\n //\n\n // 'http://distill.pub/2016/augmented-rnns',\n set url(value) {\n this._url = value;\n }\n get url() {\n if (this._url) {\n return this._url;\n } else if (this.distillPath && this.journal.url) {\n return this.journal.url + '/' + this.distillPath;\n } else if (this.journal.url) {\n return this.journal.url;\n }\n }\n\n // 'https://github.com/distillpub/post--augmented-rnns',\n get githubUrl() {\n if (this.githubPath) {\n return 'https://github.com/' + this.githubPath;\n } else {\n return undefined;\n }\n }\n\n // TODO resolve differences in naming of URL/Url/url.\n // 'http://distill.pub/2016/augmented-rnns/thumbnail.jpg',\n set previewURL(value) {\n this._previewURL = value;\n }\n get previewURL() {\n return this._previewURL ? this._previewURL : this.url + '/thumbnail.jpg';\n }\n\n // 'Thu, 08 Sep 2016 00:00:00 -0700',\n get publishedDateRFC() {\n return RFC(this.publishedDate);\n }\n\n // 'Thu, 08 Sep 2016 00:00:00 -0700',\n get updatedDateRFC() {\n return RFC(this.updatedDate);\n }\n\n // 2016,\n get publishedYear() {\n return this.publishedDate.getFullYear();\n }\n\n // 'Sept',\n get publishedMonth() {\n return months[this.publishedDate.getMonth()];\n }\n\n // 8,\n get publishedDay() {\n return this.publishedDate.getDate();\n }\n\n // '09',\n get publishedMonthPadded() {\n return zeroPad(this.publishedDate.getMonth() + 1);\n }\n\n // '08',\n get publishedDayPadded() {\n return zeroPad(this.publishedDate.getDate());\n }\n\n get publishedISODateOnly() {\n return this.publishedDate.toISOString().split('T')[0];\n }\n\n get volume() {\n const volume = this.publishedYear - 2015;\n if (volume < 1) {\n throw new Error('Invalid publish date detected during computing volume');\n }\n return volume;\n }\n\n get issue() {\n return this.publishedDate.getMonth() + 1;\n }\n\n // 'Olah & Carter',\n get concatenatedAuthors() {\n if (this.authors.length > 2) {\n return this.authors[0].lastName + ', et al.';\n } else if (this.authors.length === 2) {\n return this.authors[0].lastName + ' & ' + this.authors[1].lastName;\n } else if (this.authors.length === 1) {\n return this.authors[0].lastName;\n }\n }\n\n // 'Olah, Chris and Carter, Shan',\n get bibtexAuthors() {\n return this.authors.map(author => {\n return author.lastName + ', ' + author.firstName;\n }).join(' and ');\n }\n\n // 'olah2016attention'\n get slug() {\n let slug = '';\n if (this.authors.length) {\n slug += this.authors[0].lastName.toLowerCase();\n slug += this.publishedYear;\n slug += this.title.split(' ')[0].toLowerCase();\n }\n return slug || 'Untitled';\n }\n\n get bibliographyEntries() {\n return new Map(this.citations.map( citationKey => {\n const entry = this.bibliography.get(citationKey);\n return [citationKey, entry];\n }));\n }\n\n set bibliography(bibliography) {\n if (bibliography instanceof Map) {\n this._bibliography = bibliography;\n } else if (typeof bibliography === 'object') {\n this._bibliography = mapFromObject(bibliography);\n }\n }\n\n get bibliography() {\n return this._bibliography;\n }\n\n static fromObject(source) {\n const frontMatter = new FrontMatter();\n Object.assign(frontMatter, source);\n return frontMatter;\n }\n\n assignToObject(target) {\n Object.assign(target, this);\n target.bibliography = objectFromMap(this.bibliographyEntries);\n target.url = this.url;\n target.doi = this.doi;\n target.githubUrl = this.githubUrl;\n target.previewURL = this.previewURL;\n if (this.publishedDate) {\n target.volume = this.volume;\n target.issue = this.issue;\n target.publishedDateRFC = this.publishedDateRFC;\n target.publishedYear = this.publishedYear;\n target.publishedMonth = this.publishedMonth;\n target.publishedDay = this.publishedDay;\n target.publishedMonthPadded = this.publishedMonthPadded;\n target.publishedDayPadded = this.publishedDayPadded;\n }\n if (this.updatedDate) {\n target.updatedDateRFC = this.updatedDateRFC;\n }\n target.concatenatedAuthors = this.concatenatedAuthors;\n target.bibtexAuthors = this.bibtexAuthors;\n target.slug = this.slug;\n }\n\n}\n","// Copyright 2018 The Distill Template Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport function _moveLegacyAffiliationFormatIntoArray(frontMatter) {\n // authors used to have propoerties \"affiliation\" and \"affiliationURL\".\n // We now encourage using an array for affiliations containing objects with\n // properties \"name\" and \"url\".\n for (let author of frontMatter.authors) {\n const hasOldStyle = Boolean(author.affiliation)\n const hasNewStyle = Boolean(author.affiliations)\n if (!hasOldStyle) continue;\n if (hasNewStyle) {\n console.warn(`Author ${author.author} has both old-style (\"affiliation\" & \"affiliationURL\") and new style (\"affiliations\") affiliation information!`)\n } else {\n let newAffiliation = {\n \"name\": author.affiliation\n }\n if (author.affiliationURL) newAffiliation.url = author.affiliationURL;\n author.affiliations = [newAffiliation];\n }\n }\n return frontMatter\n}\n\nexport function parseFrontmatter(element) {\n const scriptTag = element.firstElementChild;\n if (scriptTag) {\n const type = scriptTag.getAttribute('type');\n if (type.split('/')[1] == 'json') {\n const content = scriptTag.textContent;\n const parsed = JSON.parse(content);\n return _moveLegacyAffiliationFormatIntoArray(parsed);\n } else {\n console.error('Distill only supports JSON frontmatter tags anymore; no more YAML.');\n }\n } else {\n console.error('You added a frontmatter tag but did not provide a script tag with front matter data in it. Please take a look at our templates.');\n }\n return {};\n}\n\nexport class FrontMatter extends HTMLElement {\n\n static get is() { return 'd-front-matter'; }\n\n constructor() {\n super();\n\n const options = {childList: true, characterData: true, subtree: true};\n const observer = new MutationObserver( (entries) => {\n for (const entry of entries) {\n if (entry.target.nodeName === 'SCRIPT' || entry.type === 'characterData') {\n const data = parseFrontmatter(this);\n this.notify(data);\n }\n }\n });\n observer.observe(this, options);\n }\n\n notify(data) {\n const options = { detail: data, bubbles: true };\n const event = new CustomEvent('onFrontMatterChanged', options);\n document.dispatchEvent(event);\n }\n\n}\n","// Copyright 2018 The Distill Template Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { parseFrontmatter } from '../components/d-front-matter';\nimport { mergeFromYMLFrontmatter } from '../front-matter.js';\n\nexport default function(dom, data) {\n const frontMatterTag = dom.querySelector('d-front-matter');\n if (!frontMatterTag) {\n console.warn('No front matter tag found!');\n return;\n }\n const extractedData = parseFrontmatter(frontMatterTag);\n mergeFromYMLFrontmatter(data, extractedData);\n}\n","/* start bibtexParse 0.0.22 */\n\n//Original work by Henrik Muehe (c) 2010\n//\n//CommonJS port by Mikola Lysenko 2013\n//\n//Port to Browser lib by ORCID / RCPETERS\n//\n//Issues:\n//no comment handling within strings\n//no string concatenation\n//no variable values yet\n//Grammar implemented here:\n//bibtex -> (string | preamble | comment | entry)*;\n//string -> '@STRING' '{' key_equals_value '}';\n//preamble -> '@PREAMBLE' '{' value '}';\n//comment -> '@COMMENT' '{' value '}';\n//entry -> '@' key '{' key ',' key_value_list '}';\n//key_value_list -> key_equals_value (',' key_equals_value)*;\n//key_equals_value -> key '=' value;\n//value -> value_quotes | value_braces | key;\n//value_quotes -> '\"' .*? '\"'; // not quite\n//value_braces -> '{' .*? '\"'; // not quite\n(function(exports) {\n\n function BibtexParser() {\n \n this.months = [\"jan\", \"feb\", \"mar\", \"apr\", \"may\", \"jun\", \"jul\", \"aug\", \"sep\", \"oct\", \"nov\", \"dec\"];\n this.notKey = [',','{','}',' ','='];\n this.pos = 0;\n this.input = \"\";\n this.entries = new Array();\n\n this.currentEntry = \"\";\n\n this.setInput = function(t) {\n this.input = t;\n };\n\n this.getEntries = function() {\n return this.entries;\n };\n\n this.isWhitespace = function(s) {\n return (s == ' ' || s == '\\r' || s == '\\t' || s == '\\n');\n };\n\n this.match = function(s, canCommentOut) {\n if (canCommentOut == undefined || canCommentOut == null)\n canCommentOut = true;\n this.skipWhitespace(canCommentOut);\n if (this.input.substring(this.pos, this.pos + s.length) == s) {\n this.pos += s.length;\n } else {\n throw \"Token mismatch, expected \" + s + \", found \"\n + this.input.substring(this.pos);\n };\n this.skipWhitespace(canCommentOut);\n };\n\n this.tryMatch = function(s, canCommentOut) {\n if (canCommentOut == undefined || canCommentOut == null)\n canCommentOut = true;\n this.skipWhitespace(canCommentOut);\n if (this.input.substring(this.pos, this.pos + s.length) == s) {\n return true;\n } else {\n return false;\n };\n this.skipWhitespace(canCommentOut);\n };\n\n /* when search for a match all text can be ignored, not just white space */\n this.matchAt = function() {\n while (this.input.length > this.pos && this.input[this.pos] != '@') {\n this.pos++;\n };\n\n if (this.input[this.pos] == '@') {\n return true;\n };\n return false;\n };\n\n this.skipWhitespace = function(canCommentOut) {\n while (this.isWhitespace(this.input[this.pos])) {\n this.pos++;\n };\n if (this.input[this.pos] == \"%\" && canCommentOut == true) {\n while (this.input[this.pos] != \"\\n\") {\n this.pos++;\n };\n this.skipWhitespace(canCommentOut);\n };\n };\n\n this.value_braces = function() {\n var bracecount = 0;\n this.match(\"{\", false);\n var start = this.pos;\n var escaped = false;\n while (true) {\n if (!escaped) {\n if (this.input[this.pos] == '}') {\n if (bracecount > 0) {\n bracecount--;\n } else {\n var end = this.pos;\n this.match(\"}\", false);\n return this.input.substring(start, end);\n };\n } else if (this.input[this.pos] == '{') {\n bracecount++;\n } else if (this.pos >= this.input.length - 1) {\n throw \"Unterminated value\";\n };\n };\n if (this.input[this.pos] == '\\\\' && escaped == false)\n escaped = true;\n else\n escaped = false;\n this.pos++;\n };\n };\n\n this.value_comment = function() {\n var str = '';\n var brcktCnt = 0;\n while (!(this.tryMatch(\"}\", false) && brcktCnt == 0)) {\n str = str + this.input[this.pos];\n if (this.input[this.pos] == '{')\n brcktCnt++;\n if (this.input[this.pos] == '}')\n brcktCnt--;\n if (this.pos >= this.input.length - 1) {\n throw \"Unterminated value:\" + this.input.substring(start);\n };\n this.pos++;\n };\n return str;\n };\n\n this.value_quotes = function() {\n this.match('\"', false);\n var start = this.pos;\n var escaped = false;\n while (true) {\n if (!escaped) {\n if (this.input[this.pos] == '\"') {\n var end = this.pos;\n this.match('\"', false);\n return this.input.substring(start, end);\n } else if (this.pos >= this.input.length - 1) {\n throw \"Unterminated value:\" + this.input.substring(start);\n };\n }\n if (this.input[this.pos] == '\\\\' && escaped == false)\n escaped = true;\n else\n escaped = false;\n this.pos++;\n };\n };\n\n this.single_value = function() {\n var start = this.pos;\n if (this.tryMatch(\"{\")) {\n return this.value_braces();\n } else if (this.tryMatch('\"')) {\n return this.value_quotes();\n } else {\n var k = this.key();\n if (k.match(\"^[0-9]+$\"))\n return k;\n else if (this.months.indexOf(k.toLowerCase()) >= 0)\n return k.toLowerCase();\n else\n throw \"Value expected:\" + this.input.substring(start) + ' for key: ' + k;\n \n };\n };\n\n this.value = function() {\n var values = [];\n values.push(this.single_value());\n while (this.tryMatch(\"#\")) {\n this.match(\"#\");\n values.push(this.single_value());\n };\n return values.join(\"\");\n };\n\n this.key = function() {\n var start = this.pos;\n while (true) {\n if (this.pos >= this.input.length) {\n throw \"Runaway key\";\n };\n // а-яА-Я is Cyrillic\n //console.log(this.input[this.pos]);\n if (this.notKey.indexOf(this.input[this.pos]) >= 0) {\n return this.input.substring(start, this.pos);\n } else {\n this.pos++;\n \n };\n };\n };\n\n this.key_equals_value = function() {\n var key = this.key();\n if (this.tryMatch(\"=\")) {\n this.match(\"=\");\n var val = this.value();\n return [ key, val ];\n } else {\n throw \"... = value expected, equals sign missing:\"\n + this.input.substring(this.pos);\n };\n };\n\n this.key_value_list = function() {\n var kv = this.key_equals_value();\n this.currentEntry['entryTags'] = {};\n this.currentEntry['entryTags'][kv[0]] = kv[1];\n while (this.tryMatch(\",\")) {\n this.match(\",\");\n // fixes problems with commas at the end of a list\n if (this.tryMatch(\"}\")) {\n break;\n }\n ;\n kv = this.key_equals_value();\n this.currentEntry['entryTags'][kv[0]] = kv[1];\n };\n };\n\n this.entry_body = function(d) {\n this.currentEntry = {};\n this.currentEntry['citationKey'] = this.key();\n this.currentEntry['entryType'] = d.substring(1);\n this.match(\",\");\n this.key_value_list();\n this.entries.push(this.currentEntry);\n };\n\n this.directive = function() {\n this.match(\"@\");\n return \"@\" + this.key();\n };\n\n this.preamble = function() {\n this.currentEntry = {};\n this.currentEntry['entryType'] = 'PREAMBLE';\n this.currentEntry['entry'] = this.value_comment();\n this.entries.push(this.currentEntry);\n };\n\n this.comment = function() {\n this.currentEntry = {};\n this.currentEntry['entryType'] = 'COMMENT';\n this.currentEntry['entry'] = this.value_comment();\n this.entries.push(this.currentEntry);\n };\n\n this.entry = function(d) {\n this.entry_body(d);\n };\n\n this.bibtex = function() {\n while (this.matchAt()) {\n var d = this.directive();\n this.match(\"{\");\n if (d == \"@STRING\") {\n this.string();\n } else if (d == \"@PREAMBLE\") {\n this.preamble();\n } else if (d == \"@COMMENT\") {\n this.comment();\n } else {\n this.entry(d);\n }\n this.match(\"}\");\n };\n };\n };\n \n exports.toJSON = function(bibtex) {\n var b = new BibtexParser();\n b.setInput(bibtex);\n b.bibtex();\n return b.entries;\n };\n\n /* added during hackathon don't hate on me */\n exports.toBibtex = function(json) {\n var out = '';\n for ( var i in json) {\n out += \"@\" + json[i].entryType;\n out += '{';\n if (json[i].citationKey)\n out += json[i].citationKey + ', ';\n if (json[i].entry)\n out += json[i].entry ;\n if (json[i].entryTags) {\n var tags = '';\n for (var jdx in json[i].entryTags) {\n if (tags.length != 0)\n tags += ', ';\n tags += jdx + '= {' + json[i].entryTags[jdx] + '}';\n }\n out += tags;\n }\n out += '}\\n\\n';\n }\n return out;\n \n };\n\n})(typeof exports === 'undefined' ? this['bibtexParse'] = {} : exports);\n\n/* end bibtexParse */\n","// Copyright 2018 The Distill Template Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport bibtexParse from 'bibtex-parse-js';\n\nfunction normalizeTag(string) {\n return string\n .replace(/[\\t\\n ]+/g, ' ')\n .replace(/{\\\\[\"^`.'acu~Hvs]( )?([a-zA-Z])}/g, (full, x, char) => char)\n .replace(/{\\\\([a-zA-Z])}/g, (full, char) => char);\n}\n\nexport function parseBibtex(bibtex) {\n const bibliography = new Map();\n const parsedEntries = bibtexParse.toJSON(bibtex);\n for (const entry of parsedEntries) {\n // normalize tags; note entryTags is an object, not Map\n for (const [key, value] of Object.entries(entry.entryTags)) {\n entry.entryTags[key.toLowerCase()] = normalizeTag(value);\n }\n entry.entryTags.type = entry.entryType;\n // add to bibliography\n bibliography.set(entry.citationKey, entry.entryTags);\n }\n return bibliography;\n}\n\nexport function serializeFrontmatterToBibtex(frontMatter) {\n return `@article{${frontMatter.slug},\n author = {${frontMatter.bibtexAuthors}},\n title = {${frontMatter.title}},\n journal = {${frontMatter.journal.title}},\n year = {${frontMatter.publishedYear}},\n note = {${frontMatter.url}},\n doi = {${frontMatter.doi}}\n}`;\n}\n","// Copyright 2018 The Distill Template Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { parseBibtex } from '../helpers/bibtex';\n\nexport function parseBibliography(element) {\n const scriptTag = element.firstElementChild;\n if (scriptTag && scriptTag.tagName === 'SCRIPT') {\n if (scriptTag.type == 'text/bibtex') {\n const bibtex = element.firstElementChild.textContent;\n return parseBibtex(bibtex);\n } else if (scriptTag.type == 'text/json') {\n return new Map(JSON.parse(scriptTag.textContent));\n } else {\n console.warn('Unsupported bibliography script tag type: ' + scriptTag.type);\n }\n } else {\n console.warn('Bibliography did not have any script tag.');\n }\n}\n\nexport class Bibliography extends HTMLElement {\n\n static get is() { return 'd-bibliography'; }\n\n constructor() {\n super();\n\n // set up mutation observer\n const options = {childList: true, characterData: true, subtree: true};\n const observer = new MutationObserver( (entries) => {\n for (const entry of entries) {\n if (entry.target.nodeName === 'SCRIPT' || entry.type === 'characterData') {\n this.parseIfPossible();\n }\n }\n });\n observer.observe(this, options);\n }\n\n connectedCallback() {\n requestAnimationFrame(() => {\n this.parseIfPossible();\n });\n }\n\n parseIfPossible() {\n const scriptTag = this.querySelector('script');\n if (!scriptTag) return;\n if (scriptTag.type == 'text/bibtex') {\n const newBibtex = scriptTag.textContent;\n if (this.bibtex !== newBibtex) {\n this.bibtex = newBibtex;\n const bibliography = parseBibtex(this.bibtex);\n this.notify(bibliography);\n }\n } else if (scriptTag.type == 'text/json') {\n const bibliography = new Map(JSON.parse(scriptTag.textContent));\n this.notify(bibliography);\n } else {\n console.warn('Unsupported bibliography script tag type: ' + scriptTag.type);\n }\n }\n\n notify(bibliography) {\n const options = { detail: bibliography, bubbles: true };\n const event = new CustomEvent('onBibliographyChanged', options);\n this.dispatchEvent(event);\n }\n\n /* observe 'src' attribute */\n\n static get observedAttributes() {\n return ['src'];\n }\n\n receivedBibtex(event) {\n const bibliography = parseBibtex(event.target.response);\n this.notify(bibliography);\n }\n\n attributeChangedCallback(name, oldValue, newValue) {\n var oReq = new XMLHttpRequest();\n oReq.onload = (e) => this.receivedBibtex(e);\n oReq.onerror = () => console.warn(`Could not load Bibtex! (tried ${newValue})`);\n oReq.responseType = 'text';\n oReq.open('GET', newValue, true);\n oReq.send();\n }\n\n\n}\n","// Copyright 2018 The Distill Template Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { parseBibtex } from '../helpers/bibtex';\nimport fs from 'fs';\nimport { parseBibliography } from '../components/d-bibliography';\n\nexport default function(dom, data) {\n const bibliographyTag = dom.querySelector('d-bibliography');\n if (!bibliographyTag) {\n console.warn('No bibliography tag found!');\n return;\n }\n\n const src = bibliographyTag.getAttribute('src');\n if (src) {\n const path = data.inputDirectory + '/' + src;\n const text = fs.readFileSync(path, 'utf-8');\n const bibliography = parseBibtex(text);\n const scriptTag = dom.createElement('script');\n scriptTag.type = 'text/json';\n scriptTag.textContent = JSON.stringify([...bibliography]);\n bibliographyTag.appendChild(scriptTag);\n bibliographyTag.removeAttribute('src');\n }\n\n data.bibliography = parseBibliography(bibliographyTag);\n}\n","// Copyright 2018 The Distill Template Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport function collect_citations(dom = document) {\n const citations = new Set();\n const citeTags = dom.querySelectorAll(\"d-cite\");\n for (const tag of citeTags) {\n const keyString = tag.getAttribute(\"key\") || tag.getAttribute(\"bibtex-key\");\n const keys = keyString.split(\",\").map(k => k.trim());\n for (const key of keys) {\n citations.add(key);\n }\n }\n return [...citations];\n}\n\nexport function inline_cite_short(keys) {\n function cite_string(key) {\n if (key in data.bibliography) {\n var n = data.citations.indexOf(key) + 1;\n return \"\" + n;\n } else {\n return \"?\";\n }\n }\n return \"[\" + keys.map(cite_string).join(\", \") + \"]\";\n}\n\nexport function inline_cite_long(keys) {\n function cite_string(key) {\n if (key in data.bibliography) {\n var ent = data.bibliography[key];\n var names = ent.author.split(\" and \");\n names = names.map(name => name.split(\",\")[0].trim());\n var year = ent.year;\n if (names.length == 1) return names[0] + \", \" + year;\n if (names.length == 2) return names[0] + \" & \" + names[1] + \", \" + year;\n if (names.length > 2) return names[0] + \", et al., \" + year;\n } else {\n return \"?\";\n }\n }\n return keys.map(cite_string).join(\", \");\n}\n\nfunction author_string(ent, template, sep, finalSep) {\n if (ent.author == null) {\n return \"\";\n }\n var names = ent.author.split(\" and \");\n let name_strings = names.map(name => {\n name = name.trim();\n if (name.indexOf(\",\") != -1) {\n var last = name.split(\",\")[0].trim();\n var firsts = name.split(\",\")[1];\n } else if (name.indexOf(\" \") != -1) {\n var last = name\n .split(\" \")\n .slice(-1)[0]\n .trim();\n var firsts = name\n .split(\" \")\n .slice(0, -1)\n .join(\" \");\n } else {\n var last = name.trim();\n }\n var initials = \"\";\n if (firsts != undefined) {\n initials = firsts\n .trim()\n .split(\" \")\n .map(s => s.trim()[0]);\n initials = initials.join(\".\") + \".\";\n }\n return template\n .replace(\"${F}\", firsts)\n .replace(\"${L}\", last)\n .replace(\"${I}\", initials)\n .trim(); // in case one of first or last was empty\n });\n if (names.length > 1) {\n var str = name_strings.slice(0, names.length - 1).join(sep);\n str += (finalSep || sep) + name_strings[names.length - 1];\n return str;\n } else {\n return name_strings[0];\n }\n}\n\nfunction venue_string(ent) {\n var cite = ent.journal || ent.booktitle || \"\";\n if (\"volume\" in ent) {\n var issue = ent.issue || ent.number;\n issue = issue != undefined ? \"(\" + issue + \")\" : \"\";\n cite += \", Vol \" + ent.volume + issue;\n }\n if (\"pages\" in ent) {\n cite += \", pp. \" + ent.pages;\n }\n if (cite != \"\") cite += \". \";\n if (\"publisher\" in ent) {\n cite += ent.publisher;\n if (cite[cite.length - 1] != \".\") cite += \".\";\n }\n return cite;\n}\n\nfunction link_string(ent) {\n if (\"url\" in ent) {\n var url = ent.url;\n var arxiv_match = /arxiv\\.org\\/abs\\/([0-9\\.]*)/.exec(url);\n if (arxiv_match != null) {\n url = `http://arxiv.org/pdf/${arxiv_match[1]}.pdf`;\n }\n\n if (url.slice(-4) == \".pdf\") {\n var label = \"PDF\";\n } else if (url.slice(-5) == \".html\") {\n var label = \"HTML\";\n }\n return ` [${label || \"link\"}]`;\n } /* else if (\"doi\" in ent){\n return ` [DOI]`;\n }*/ else {\n return \"\";\n }\n}\nfunction doi_string(ent, new_line) {\n if (\"doi\" in ent) {\n return `${new_line ? \"
\" : \"\"} DOI: ${ent.doi}`;\n } else {\n return \"\";\n }\n}\n\nfunction title_string(ent) {\n return '' + ent.title + \" \";\n}\n\nexport function bibliography_cite(ent, fancy) {\n if (ent) {\n var cite = title_string(ent);\n cite += link_string(ent) + \"
\";\n if (ent.author) {\n cite += author_string(ent, \"${L}, ${I}\", \", \", \" and \");\n if (ent.year || ent.date) {\n cite += \", \";\n }\n }\n if (ent.year || ent.date) {\n cite += (ent.year || ent.date) + \". \";\n } else {\n cite += \". \";\n }\n cite += venue_string(ent);\n cite += doi_string(ent);\n return cite;\n /*var cite = author_string(ent, \"${L}, ${I}\", \", \", \" and \");\n if (ent.year || ent.date){\n cite += \", \" + (ent.year || ent.date) + \". \"\n } else {\n cite += \". \"\n }\n cite += \"\" + ent.title + \". \";\n cite += venue_string(ent);\n cite += doi_string(ent);\n cite += link_string(ent);\n return cite*/\n } else {\n return \"?\";\n }\n}\n\nexport function hover_cite(ent) {\n if (ent) {\n var cite = \"\";\n cite += \"\" + ent.title + \"\";\n cite += link_string(ent);\n cite += \"
\";\n\n var a_str = author_string(ent, \"${I} ${L}\", \", \") + \".\";\n var v_str =\n venue_string(ent).trim() + \" \" + ent.year + \". \" + doi_string(ent, true);\n\n if ((a_str + v_str).length < Math.min(40, ent.title.length)) {\n cite += a_str + \" \" + v_str;\n } else {\n cite += a_str + \"
\" + v_str;\n }\n return cite;\n } else {\n return \"?\";\n }\n}\n\n//https://scholar.google.com/scholar?q=allintitle%3ADocument+author%3Aolah\nfunction get_GS_URL(ent) {\n if (ent) {\n var names = ent.author.split(\" and \");\n names = names.map(name => name.split(\",\")[0].trim());\n var title = ent.title.split(\" \"); //.replace(/[,:]/, \"\")\n var url = \"http://search.labs.crossref.org/dois?\"; //\"\"https://scholar.google.com/scholar?\"\n url += uris({ q: names.join(\" \") + \" \" + title.join(\" \") });\n }\n}\n","// Copyright 2018 The Distill Template Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { collect_citations } from '../helpers/citation.js';\n\nexport default function(dom, data) {\n const citations = new Set(data.citations);\n const newCitations = collect_citations(dom);\n for (const citation of newCitations) {\n citations.add(citation);\n }\n data.citations = Array.from(citations);\n}\n","// Copyright 2018 The Distill Template Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport default function(dom) {\n\n const head = dom.querySelector('head');\n\n // set language to 'en'\n if (!dom.querySelector('html').getAttribute('lang')) {\n dom.querySelector('html').setAttribute('lang', 'en');\n }\n\n // set charset to 'utf-8'\n if (!dom.querySelector('meta[charset]')) {\n const meta = dom.createElement('meta');\n meta.setAttribute('charset', 'utf-8');\n head.appendChild(meta);\n }\n\n // set viewport\n if (!dom.querySelector('meta[name=viewport]')) {\n const meta = dom.createElement('meta');\n meta.setAttribute('name', 'viewport');\n meta.setAttribute('content', 'width=device-width, initial-scale=1');\n head.appendChild(meta);\n }\n}\n","// Copyright 2018 The Distill Template Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// import style from '../styles/d-byline.css';\n\nexport function bylineTemplate(frontMatter) {\n return `\n