This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/app/lib/quote.js
Jarek Radosz c3fd91670e
DEV: Update linting setup and fix issues (#17345)
Re-lands #16119 and #17298

* Update eslint-config-discourse
* Update linting workflow
* Prettier-ignore stuff
* Update template-lint config
* Auto-fix template issues
* Fix various template issues
  Mostly incorrect attributes and unused templates
* Prettier js files
* Fix template auto-fix regressions
* Small css tweak

Co-authored-by: Peter Wagenet <peter.wagenet@gmail.com>
2022-07-06 10:37:54 +02:00

42 lines
1.2 KiB
JavaScript

import { prioritizeNameFallback } from "discourse/lib/settings";
import { helperContext } from "discourse-common/lib/helpers";
export const QUOTE_REGEXP =
/\[quote=([^\]]*)\]((?:[\s\S](?!\[quote=[^\]]*\]))*?)\[\/quote\]/im;
// Build the BBCode quote around the selected text
export function buildQuote(post, contents, opts = {}) {
if (!post || !contents) {
return "";
}
let fullName = post.name;
// if the quote username data attr is present but it does not
// match the post username then fallback to the quote username instead of fetching
// the full name from the post
if (opts.username && opts.username !== post.username) {
fullName = null;
}
const name = prioritizeNameFallback(fullName, opts.username || post.username);
const params = [
name,
`post:${opts.post || post.post_number}`,
`topic:${opts.topic || post.topic_id}`,
];
if (opts.full) {
params.push("full:true");
}
if (
helperContext().siteSettings.display_name_on_posts &&
!helperContext().siteSettings.prioritize_username_in_ux &&
fullName
) {
params.push(`username:${opts.username || post.username}`);
}
return `[quote="${params.join(", ")}"]\n${contents.trim()}\n[/quote]\n\n`;
}