aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519>2020-05-28 11:34:25 -0400
committercel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519>2020-05-28 11:34:25 -0400
commitc8f96e2696d4d538e2b5e9afdec945c3091ce03c (patch)
tree374254b9f9f8e4de1db0b3dbb4ab7f086cf15254
parent891dd8e960425e52c64fecf78668cd115d9251f7 (diff)
downloadpatchfoo-c8f96e2696d4d538e2b5e9afdec945c3091ce03c.tar.gz
patchfoo-c8f96e2696d4d538e2b5e9afdec945c3091ce03c.zip
Truncate long link texts
-rw-r--r--lib/render.js13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/render.js b/lib/render.js
index a39ba73..57cc3b5 100644
--- a/lib/render.js
+++ b/lib/render.js
@@ -15,6 +15,18 @@ var Highlight = require('highlight.js')
var md = require('ssb-markdown')
var Diff = require('diff')
+var maxWordLength = 80
+var truncateWordsRe = new RegExp('[^\\s<>&"]{' + (maxWordLength+1) + ',}')
+function truncateWord(word) {
+ var len = maxWordLength - 5 // "…[##]"
+ var truncatedLength = word.length - len
+ return word.substr(0, len) + '…<sub>[' + truncatedLength + ']</sub>'
+}
+function truncateWords(text) {
+ // truncate long words to avoid horizontal scrollbar
+ return text.replace(truncateWordsRe, truncateWord)
+}
+
module.exports = Render
function MdRenderer(render) {
@@ -62,6 +74,7 @@ MdRenderer.prototype.link = function (ref, title, text) {
href: href !== false ? hrefToken : undefined,
title: title || undefined
})
+ text = truncateWords(text)
// text is already html-escaped
a.innerHTML = text
var html = a.outerHTML