diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2019-11-08 14:39:07 -1000 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2019-11-08 14:46:09 -1000 |
commit | a989374f143a885920e640296902d5bbf4fe8086 (patch) | |
tree | fdc67fabd09a199980ed426551c58da033cb9e80 | |
parent | c9f375a151cc8caa74c341f054e8a3e0cdc96b52 (diff) | |
download | patchfoo-a989374f143a885920e640296902d5bbf4fe8086.tar.gz patchfoo-a989374f143a885920e640296902d5bbf4fe8086.zip |
Add dualMarkdownPreview option
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | lib/render-msg.js | 12 | ||||
-rw-r--r-- | lib/render.js | 10 | ||||
-rw-r--r-- | lib/serve.js | 2 | ||||
-rw-r--r-- | package.json | 1 |
5 files changed, 24 insertions, 2 deletions
@@ -134,6 +134,7 @@ To make config options persistent, set them in `~/.ssb/config`, e.g.: - `scriptDir: name of directory in patchfoo's directory (as set by `patchfoo.dir` config option above) to use for user scripts. default: `"script"`. - `draftsDir: name of directory in patchfoo's directory (as set by `patchfoo.dir` config option above) to use for message draft data. default: `"drafts"`. - `newLimit: limit of messages to show on `/new` page. Default: 500. Overridable with query string parameter `limit=...`. +- `dualMarkdownPreview`: Preview messages in composer in multiple SSB markdown implementations, `ssb-marked` and `ssb-markdown` >= 3. Overridable with query string parameter `dualMd=1`. ## TODO diff --git a/lib/render-msg.js b/lib/render-msg.js index 475965a..a29a21b 100644 --- a/lib/render-msg.js +++ b/lib/render-msg.js @@ -368,6 +368,18 @@ RenderMsg.prototype.encrypted = function (cb) { RenderMsg.prototype.markdown = function (cb) { if (this.opts.markdownSource) return this.markdownSource(this.c.text, this.c.mentions) + + if (this.opts.dualMarkdown) { + var self = this + return h('table', {style: 'width: 100%'}, h('tr', [ + h('td', {style: 'width: 50%'}, + {innerHTML: this.render.markdown(this.c.text, this.c.mentions)}), + h('td', {style: 'width: 50%'}, + {innerHTML: this.render.markdown(this.c.text, this.c.mentions, + {ssbcMd: true})}) + ])).outerHTML + } + return this.render.markdown(this.c.text, this.c.mentions) } diff --git a/lib/render.js b/lib/render.js index f3dcfe0..fc2407e 100644 --- a/lib/render.js +++ b/lib/render.js @@ -12,6 +12,7 @@ var u = require('./util') var multicb = require('multicb') var RenderMsg = require('./render-msg') var Highlight = require('highlight.js') +var md = require('ssb-markdown') module.exports = Render @@ -166,8 +167,9 @@ function fixSymbols(str) { } */ -Render.prototype.markdown = function (text, mentions) { +Render.prototype.markdown = function (text, mentions, opts) { if (!text) return '' + var ssbcMd = opts && opts.ssbcMd var mentionsObj = this._mentions = {} var mentionsByLink = this._mentionsByLink = {} if (Array.isArray(mentions)) mentions.forEach(function (link) { @@ -184,7 +186,11 @@ Render.prototype.markdown = function (text, mentions) { '?unbox=' + link.query.unbox.replace(/\s/g, '+') : '') + (link.key ? '#' + link.key : '')] = link }) - var out = marked(String(text), this.markedOpts) + var self = this + var out = ssbcMd ? md.block(String(text), { + toUrl: function (ref) { return self.toUrl(ref) }, + imageLink: function (ref) { return self.imageUrl(ref) } + }) : marked(String(text), this.markedOpts) delete this._mentions delete this._mentionsByLink return out //fixSymbols(out) diff --git a/lib/serve.js b/lib/serve.js index 7e0ee26..cd63905 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -3968,6 +3968,8 @@ Serve.prototype.composer = function (opts, cb) { self.app.unboxMessages(), self.app.render.renderFeeds({ raw: raw, + dualMarkdown: self.query.dualMd != null ? self.query.dualMd : + self.conf.dualMarkdownPreview, filter: self.query.filter, }), pull.drain(function (el) { diff --git a/package.json b/package.json index 4857a84..e6a5a42 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "pull-stream": "^3.5.0", "pull-utf8-decoder": "^1.0.2", "ssb-git": "^1.1.0", + "ssb-markdown": "^6.0.0", "ssb-marked": "^0.7.1", "ssb-mentions": "^0.5.0", "ssb-npm-registry": "^1.8.0", |