summaryrefslogtreecommitdiffstats
path: root/core/src/OCP/comments.js
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2019-01-29 14:50:05 +0100
committerChristoph Wurst <christoph@winzerhof-wurst.at>2019-01-30 13:56:01 +0100
commit9a46c9ed31785c66f3d89f4760452d66f9674321 (patch)
treeb5f3ca6bab9fb10b03c5ea7453cae2d1c1b47b8e /core/src/OCP/comments.js
parentfda74eb9b9e6e0da4dbe222d2d9a1ceddaf60d59 (diff)
downloadnextcloud-server-9a46c9ed31785c66f3d89f4760452d66f9674321.tar.gz
nextcloud-server-9a46c9ed31785c66f3d89f4760452d66f9674321.zip
Move OCP.AppCOnfig, OCP.Comments and OCP.WhatsNew to the server bundle
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'core/src/OCP/comments.js')
-rw-r--r--core/src/OCP/comments.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/core/src/OCP/comments.js b/core/src/OCP/comments.js
new file mode 100644
index 00000000000..1500e1937c3
--- /dev/null
+++ b/core/src/OCP/comments.js
@@ -0,0 +1,51 @@
+/**
+ * @copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ */
+
+import $ from 'jquery'
+
+/*
+ * Detects links:
+ * Either the http(s) protocol is given or two strings, basically limited to ascii with the last
+ * word being at least one digit long,
+ * followed by at least another character
+ *
+ * The downside: anything not ascii is excluded. Not sure how common it is in areas using different
+ * alphabets… the upside: fake domains with similar looking characters won't be formatted as links
+ */
+const urlRegex = /(\s|^)(https?:\/\/)?((?:[-A-Z0-9+_]+\.)+[-A-Z]+(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*)(\s|$)/ig;
+
+export function plainToRich (content) {
+ return this.formatLinksRich(content);
+}
+
+export function richToPlain (content) {
+ return this.formatLinksPlain(content);
+}
+
+export function formatLinksRich (content) {
+ return content.replace(urlRegex, function (_, leadingSpace, protocol, url, trailingSpace) {
+ let linkText = url;
+ if (!protocol) {
+ protocol = 'https://';
+ } else if (protocol === 'http://') {
+ linkText = protocol + url;
+ }
+
+ return leadingSpace + '<a class="external" target="_blank" rel="noopener noreferrer" href="' + protocol + url + '">' + linkText + '</a>' + trailingSpace;
+ });
+}
+
+export function formatLinksPlain (content) {
+ const $content = $('<div></div>').html(content);
+ $content.find('a').each(function () {
+ const $this = $(this);
+ $this.html($this.attr('href'));
+ });
+ return $content.html();
+}