aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2019-11-08 14:39:07 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2019-11-08 14:46:09 -1000
commita989374f143a885920e640296902d5bbf4fe8086 (patch)
treefdc67fabd09a199980ed426551c58da033cb9e80 /lib
parentc9f375a151cc8caa74c341f054e8a3e0cdc96b52 (diff)
downloadpatchfoo-a989374f143a885920e640296902d5bbf4fe8086.tar.gz
patchfoo-a989374f143a885920e640296902d5bbf4fe8086.zip
Add dualMarkdownPreview option
Diffstat (limited to 'lib')
-rw-r--r--lib/render-msg.js12
-rw-r--r--lib/render.js10
-rw-r--r--lib/serve.js2
3 files changed, 22 insertions, 2 deletions
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) {