client/markdown: recognize entity links
This commit is contained in:
parent
c0d484689b
commit
20a5a58734
|
@ -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)');
|
||||
|
|
Loading…
Reference in New Issue