summaryrefslogtreecommitdiff
path: root/client/js/util
diff options
context:
space:
mode:
authorHunternif <hunternif@gmail.com>2025-02-15 18:12:57 +0000
committerHunternif <hunternif@gmail.com>2025-02-15 18:12:57 +0000
commit6a5300502df8b4de9c8f269b444cd309f02b28ad (patch)
tree0cf2ba56bce802c94ad324f9eda7a31d37a42e2e /client/js/util
parent34e7c883808738871aed371948a3c9896a95905c (diff)
parent376f687c386f65522b2f65e98b998b21af26ee29 (diff)
Merge branch 'master' into hunternif
Diffstat (limited to 'client/js/util')
-rw-r--r--client/js/util/markdown.js23
-rw-r--r--client/js/util/views.js12
2 files changed, 10 insertions, 25 deletions
diff --git a/client/js/util/markdown.js b/client/js/util/markdown.js
index 22cdae5..e71e326 100644
--- a/client/js/util/markdown.js
+++ b/client/js/util/markdown.js
@@ -65,17 +65,6 @@ class TagPermalinkFixWrapper extends BaseMarkdownWrapper {
// post, user and tags permalinks
class EntityPermalinkWrapper extends BaseMarkdownWrapper {
preprocess(text) {
- // URL-based permalinks
- text = text.replace(new RegExp("\\b/post/(\\d+)/?\\b", "g"), "@$1");
- text = text.replace(
- new RegExp("\\b/tag/([a-zA-Z0-9_-]+?)/?", "g"),
- "#$1"
- );
- text = text.replace(
- new RegExp("\\b/user/([a-zA-Z0-9_-]+?)/?", "g"),
- "+$1"
- );
-
text = text.replace(
/(^|^\(|(?:[^\]])\(|[\s<>\[\]\)])([+#@][a-zA-Z0-9_-]+)/g,
"$1[$2]($2)"
@@ -136,12 +125,8 @@ function createRenderer() {
const renderer = new marked.Renderer();
renderer.image = (href, title, alt) => {
- let [
- _,
- url,
- width,
- height,
- ] = /^(.+?)(?:\s=\s*(\d*)\s*x\s*(\d*)\s*)?$/.exec(href);
+ let [_, url, width, height] =
+ /^(.+?)(?:\s=\s*(\d*)\s*x\s*(\d*)\s*)?$/.exec(href);
let res = '<img src="' + sanitize(url) + '" alt="' + sanitize(alt);
if (width) {
res += '" width="' + width;
@@ -174,7 +159,7 @@ function formatMarkdown(text) {
for (let wrapper of wrappers) {
text = wrapper.preprocess(text);
}
- text = marked(text, options);
+ text = marked.parse(text, options);
wrappers.reverse();
for (let wrapper of wrappers) {
text = wrapper.postprocess(text);
@@ -200,7 +185,7 @@ function formatInlineMarkdown(text) {
for (let wrapper of wrappers) {
text = wrapper.preprocess(text);
}
- text = marked.inlineLexer(text, [], options);
+ text = marked.parseInline(text, options);
wrappers.reverse();
for (let wrapper of wrappers) {
text = wrapper.postprocess(text);
diff --git a/client/js/util/views.js b/client/js/util/views.js
index cc0614b..9958c87 100644
--- a/client/js/util/views.js
+++ b/client/js/util/views.js
@@ -231,13 +231,13 @@ function makePostLink(id, includeHash) {
}
function makeTagLink(name, includeHash, includeCount, tag) {
- const category = tag ? tag.category : "unknown";
+ const category = tag && tag.category ? tag.category : "unknown";
let text = misc.getPrettyName(name);
if (includeHash === true) {
text = "#" + text;
}
if (includeCount === true) {
- text += " (" + (tag ? tag.postCount : 0) + ")";
+ text += " (" + (tag && tag.postCount ? tag.postCount : 0) + ")";
}
return api.hasPrivilege("tags:view")
? makeElement(
@@ -256,15 +256,15 @@ function makeTagLink(name, includeHash, includeCount, tag) {
}
function makePoolLink(id, includeHash, includeCount, pool, name) {
- const category = pool ? pool.category : "unknown";
+ const category = pool && pool.category ? pool.category : "unknown";
let text = misc.getPrettyName(
- name ? name : pool ? pool.names[0] : "unknown"
+ name ? name : pool && pool.names ? pool.names[0] : "pool " + id
);
if (includeHash === true) {
text = "#" + text;
}
if (includeCount === true) {
- text += " (" + (pool ? pool.postCount : 0) + ")";
+ text += " (" + (pool && pool.postCount ? pool.postCount : 0) + ")";
}
return api.hasPrivilege("pools:view")
? makeElement(
@@ -286,7 +286,7 @@ function makeUserLink(user) {
let text = makeThumbnail(user ? user.avatarUrl : null);
text += user && user.name ? misc.escapeHtml(user.name) : "Anonymous";
const link =
- user && api.hasPrivilege("users:view")
+ user && user.name && api.hasPrivilege("users:view")
? makeElement(
"a",
{ href: uri.formatClientLink("user", user.name) },