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)');