From 93ae75cda7a187277a905e6d57aded3a9c4ce787 Mon Sep 17 00:00:00 2001 From: Jim O'Donnell Date: Mon, 6 Nov 2023 12:07:05 +0000 Subject: [PATCH] Markdownz bugfixes - Fix a bug when `params.project` is undefined. - Remove `twemoji`. - Remove the old `Markdown` class. --- index.js | 7 +++-- lib/markdown.js | 67 ----------------------------------------------- package-lock.json | 1 - package.json | 1 - 4 files changed, 3 insertions(+), 73 deletions(-) delete mode 100644 lib/markdown.js diff --git a/index.js b/index.js index 9ebaf94..b2975fc 100644 --- a/index.js +++ b/index.js @@ -14,12 +14,11 @@ app.post('/html', function(req, res) { params = req.body; res.setHeader('Content-Type', 'text/html'); res.statusCode = 200; - html = utils.getHtml({ + const project = params.project ? { slug: params.project } : undefined; + const html = utils.getHtml({ baseURI: 'https://www.zooniverse.org', content: params.markdown, - project: { - slug: params.project - } + project }) res.end('
' + html + '
'); }); diff --git a/lib/markdown.js b/lib/markdown.js deleted file mode 100644 index 94bed40..0000000 --- a/lib/markdown.js +++ /dev/null @@ -1,67 +0,0 @@ -var MarkdownIt = require('markdown-it'); -var MarkdownItContainer = require('markdown-it-container'); -var twemoji = require('@twemoji/api'); - -var markdownIt = new MarkdownIt({ linkify: true, breaks: true }); - -markdownIt - .use(require('markdown-it-emoji')) - .use(require('markdown-it-sub')) - .use(require('markdown-it-sup')) - .use(require('markdown-it-footnote')) - .use(MarkdownItContainer, 'partners') - .use(MarkdownItContainer, 'attribution'); - -var host = { - production: 'https://www.zooniverse.org', - staging: 'http://demo.zooniverse.org/panoptes-front-end' -}[process.env.NODE_ENV] || 'http://localhost:3735'; - -function Markdown(input, project) { - this.input = input; - this.project = project; -} - -Markdown.prototype.customTags = function(input) { - var project = this.project; - - return input - .replace(/(^|[^\w])(\#([-\w\d]{3,40}))/g, function(fullMatch, boundary, fullTag, tagName) { - if(project) { - return boundary + '' + fullTag + ''; - } else { - return boundary + '' + fullTag + ''; - } - }) - .replace(/\^S0*(\d+)/g, function(fullMatch, subjectId) { - if(project) { - return '' + project + ' - Subject ' + subjectId + '' - } else { - return fullMatch; - } - }) - .replace(/@([\w-]+)\/([\w-]+)\^S0*(\d+)/g, '$1/$2 - Subject $3') - .replace(/\^C0*(\d+)/g, 'Collection $1') - .replace(/@([-\w\d]+)/g, function(fullMatch, username) { - var groups = ['admins', 'moderators', 'researchers', 'scientists', 'team']; - if(groups.indexOf(username) < 0) { - return '@' + username + ''; - } else { - return '@' + username; - } - }); -}; - -Markdown.prototype.emoji = function(input) { - return twemoji.parse(input); -}; - -Markdown.prototype.render = function(input) { - return markdownIt.render(input); -}; - -Markdown.prototype.html = function () { - return this.emoji(this.customTags(this.render(this.input))); -}; - -module.exports = Markdown; diff --git a/package-lock.json b/package-lock.json index 0f08f08..9565ca7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,6 @@ "version": "1.0.0", "license": "Apache-2.0", "dependencies": { - "@twemoji/api": "^14.1.2", "body-parser": "^1.20.2", "express": "^4.18.2", "markdownz": "^9.1.4", diff --git a/package.json b/package.json index 67672e7..3498498 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ "author": "The Zooniverse", "license": "Apache-2.0", "dependencies": { - "@twemoji/api": "^14.1.2", "body-parser": "^1.20.2", "express": "^4.18.2", "markdownz": "^9.1.4",