From 16f6a0e5fa4cafa1f2b369c11fe7c9b0982bf5de Mon Sep 17 00:00:00 2001 From: denkiwakame Date: Sun, 13 Jan 2019 00:11:05 +0900 Subject: [PATCH] Fix formatter (#7) * :bug: string formatting --- .gitignore | 2 ++ src/js/popup.js | 15 ++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b287ef3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +dist/* +packages/* diff --git a/src/js/popup.js b/src/js/popup.js index 4d63ee8..c905ec0 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -118,7 +118,7 @@ UI = { for (author of data.authors) { const templateStr = require('../html/_chip.html'); const compiled = _.template(templateStr); - const chipEl = self._str2elem( compiled({ tag: author.replace(/\ /g, '_') }) ); + const chipEl = self._str2elem( compiled({ tag: author.trim().replace(/\ +/g, '_') }) ); $(".mdc-chip-set").append(chipEl); self.chipSet.addChip(chipEl); } @@ -146,11 +146,12 @@ App = { }, getPaperInfo: function(url) { const self = this; -// const url_ = "http://openaccess.thecvf.com/content_ECCV_2018/papers/Martin_Sundermeyer_Implicit_3D_Orientation_ECCV_2018_paper.pdf"; -// self.getPDFInfo(url_); if (self.isArxivUrl(url)) return self.getArXivInfo(url); if (self.isPDF(url)) return self.getPDFInfo(url); }, + formatString: function(str) { + return str.trim().replace(/\n/g,' ').replace(/\ +/g, ' '); + }, getArXivInfo: function(url) { UI.showProgressBar(); const self = this; @@ -165,8 +166,8 @@ App = { statusCode: { 200: (data)=> { const $entry= $(data).find("entry"); - const paperTitle = $entry.find("title")[0].textContent.replace(/\n/g,' '); // FIXME - const abst = $entry.find("summary")[0].textContent.trim().replace(/\n/g,' '); // FIXME + const paperTitle = self.formatString($entry.find("title")[0].textContent); + const abst = self.formatString($entry.find("summary")[0].textContent); const authors = _.map($entry.find("author"), (a) => { return a.textContent.trim(); }); UI.setFormContents({ url : url, @@ -190,8 +191,8 @@ App = { const pdfLoading = pdfjsLib.getDocument(url); pdfLoading.promise.then((pdf)=>{ pdf.getMetadata().then((d)=>{ - const authors = d.info.Author.trim().replace("/ /_/g").split(","); - const paperTitle = d.info.Title.replace(/\n/g,' '); + const authors = d.info.Author.trim().split(","); + const paperTitle = self.formatString(d.info.Title); UI.setFormContents({ url : url, paperTitle : paperTitle,