aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--lib/render-msg.js12
-rw-r--r--lib/render.js10
-rw-r--r--lib/serve.js2
-rw-r--r--package.json1
5 files changed, 24 insertions, 2 deletions
diff --git a/README.md b/README.md
index 9f108ac..deb1fa2 100644
--- a/README.md
+++ b/README.md
@@ -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",