From 20a5a58734fb43f030457dd82857d0420959739e Mon Sep 17 00:00:00 2001 From: rr- Date: Fri, 11 Nov 2016 21:52:07 +0100 Subject: [PATCH] client/markdown: recognize entity links --- client/js/util/markdown.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/client/js/util/markdown.js b/client/js/util/markdown.js index 7270fc0..f69df7c 100644 --- a/client/js/util/markdown.js +++ b/client/js/util/markdown.js @@ -1,6 +1,7 @@ 'use strict'; const marked = require('marked'); +const config = require('../config.js'); class BaseMarkdownWrapper { preprocess(text) { @@ -62,6 +63,17 @@ class TagPermalinkFixWrapper extends BaseMarkdownWrapper { //post, user and tags permalinks class EntityPermalinkWrapper extends BaseMarkdownWrapper { preprocess(text) { + // URL-based permalinks + let baseUrl = config.baseUrl.replace(/\/+$/, ''); + text = text.replace( + new RegExp('\\b' + baseUrl + '/post/(\\d+)/?\\b', 'g'), '@$1'); + text = text.replace( + new RegExp('\\b' + baseUrl + '/tag/([a-zA-Z0-9_-]+?)/?', 'g'), + '#$1'); + text = text.replace( + new RegExp('\\b' + baseUrl + '/user/([a-zA-Z0-9_-]+?)/?', 'g'), + '+$1'); + text = text.replace( /(^|^\(|(?:[^\]])\(|[\s<>\[\]\)])([+#@][a-zA-Z0-9_-]+)/g, '$1[$2]($2)');