DEV: Move pretty-text into an ember-addon format (#9689)

DEV: Move pretty-text into an ember-addon format (#9689)

diff --git a/app/assets/javascripts/markdown-it-bundle.js b/app/assets/javascripts/markdown-it-bundle.js
index 052891a..2299af2 100644
--- a/app/assets/javascripts/markdown-it-bundle.js
+++ b/app/assets/javascripts/markdown-it-bundle.js
@@ -1,20 +1,20 @@
 //= require markdown-it.js
-//= require ./pretty-text/engines/discourse-markdown/helpers
-//= require ./pretty-text/engines/discourse-markdown/mentions
-//= require ./pretty-text/engines/discourse-markdown/quotes
-//= require ./pretty-text/engines/discourse-markdown/emoji
-//= require ./pretty-text/engines/discourse-markdown/onebox
-//= require ./pretty-text/engines/discourse-markdown/bbcode-block
-//= require ./pretty-text/engines/discourse-markdown/bbcode-inline
-//= require ./pretty-text/engines/discourse-markdown/code
-//= require ./pretty-text/engines/discourse-markdown/category-hashtag
-//= require ./pretty-text/engines/discourse-markdown/censored
-//= require ./pretty-text/engines/discourse-markdown/table
-//= require ./pretty-text/engines/discourse-markdown/paragraph
-//= require ./pretty-text/engines/discourse-markdown/newline
-//= require ./pretty-text/engines/discourse-markdown/html-img
-//= require ./pretty-text/engines/discourse-markdown/text-post-process
-//= require ./pretty-text/engines/discourse-markdown/upload-protocol
-//= require ./pretty-text/engines/discourse-markdown/inject-line-number
-//= require ./pretty-text/engines/discourse-markdown/resize-controls
-//= require ./pretty-text/engines/discourse-markdown/d-wrap
+//= require ./pretty-text/addon/engines/discourse-markdown/helpers
+//= require ./pretty-text/addon/engines/discourse-markdown/mentions
+//= require ./pretty-text/addon/engines/discourse-markdown/quotes
+//= require ./pretty-text/addon/engines/discourse-markdown/emoji
+//= require ./pretty-text/addon/engines/discourse-markdown/onebox
+//= require ./pretty-text/addon/engines/discourse-markdown/bbcode-block
+//= require ./pretty-text/addon/engines/discourse-markdown/bbcode-inline
+//= require ./pretty-text/addon/engines/discourse-markdown/code
+//= require ./pretty-text/addon/engines/discourse-markdown/category-hashtag
+//= require ./pretty-text/addon/engines/discourse-markdown/censored
+//= require ./pretty-text/addon/engines/discourse-markdown/table
+//= require ./pretty-text/addon/engines/discourse-markdown/paragraph
+//= require ./pretty-text/addon/engines/discourse-markdown/newline
+//= require ./pretty-text/addon/engines/discourse-markdown/html-img
+//= require ./pretty-text/addon/engines/discourse-markdown/text-post-process
+//= require ./pretty-text/addon/engines/discourse-markdown/upload-protocol
+//= require ./pretty-text/addon/engines/discourse-markdown/inject-line-number
+//= require ./pretty-text/addon/engines/discourse-markdown/resize-controls
+//= require ./pretty-text/addon/engines/discourse-markdown/d-wrap
diff --git a/app/assets/javascripts/pretty-text-bundle.js b/app/assets/javascripts/pretty-text-bundle.js
index c964a71..a2adade 100644
--- a/app/assets/javascripts/pretty-text-bundle.js
+++ b/app/assets/javascripts/pretty-text-bundle.js
@@ -1,16 +1,16 @@
-//= require ./pretty-text/pretty-text
-//= require ./pretty-text/guid
-//= require ./pretty-text/censored-words
-//= require ./pretty-text/emoji/data
-//= require ./pretty-text/emoji/version
-//= require ./pretty-text/emoji
-//= require ./pretty-text/engines/discourse-markdown-it
+//= require ./pretty-text/addon/pretty-text
+//= require ./pretty-text/addon/guid
+//= require ./pretty-text/addon/censored-words
+//= require ./pretty-text/addon/emoji/data
+//= require ./pretty-text/addon/emoji/version
+//= require ./pretty-text/addon/emoji
+//= require ./pretty-text/addon/engines/discourse-markdown-it
 //= require xss.min
-//= require ./pretty-text/xss
-//= require ./pretty-text/white-lister
-//= require ./pretty-text/sanitizer
-//= require ./pretty-text/oneboxer
-//= require ./pretty-text/oneboxer-cache
-//= require ./pretty-text/context/inline-onebox-css-classes
-//= require ./pretty-text/inline-oneboxer
-//= require ./pretty-text/upload-short-url
+//= require ./pretty-text/addon/xss
+//= require ./pretty-text/addon/white-lister
+//= require ./pretty-text/addon/sanitizer
+//= require ./pretty-text/addon/oneboxer
+//= require ./pretty-text/addon/oneboxer-cache
+//= require ./pretty-text/addon/context/inline-onebox-css-classes
+//= require ./pretty-text/addon/inline-oneboxer
+//= require ./pretty-text/addon/upload-short-url
diff --git a/app/assets/javascripts/pretty-text/addon/censored-words.js b/app/assets/javascripts/pretty-text/addon/censored-words.js
new file mode 100644
index 0000000..4453e3f
--- /dev/null
+++ b/app/assets/javascripts/pretty-text/addon/censored-words.js
@@ -0,0 +1,26 @@
+export function censorFn(regexpString, replacementLetter) {
+  if (regexpString) {
+    let censorRegexp = new RegExp(regexpString, "ig");
+    replacementLetter = replacementLetter || "■";
+
+    return function(text) {
+      text = text.replace(censorRegexp, (fullMatch, ...groupMatches) => {
+        const stringMatch = groupMatches.find(g => typeof g === "string");
+        return fullMatch.replace(
+          stringMatch,
+          new Array(stringMatch.length + 1).join(replacementLetter)
+        );
+      });
+
+      return text;
+    };
+  }
+
+  return function(t) {
+    return t;
+  };
+}
+
+export function censor(text, censoredRegexp, replacementLetter) {
+  return censorFn(censoredRegexp, replacementLetter)(text);
+}
diff --git a/app/assets/javascripts/pretty-text/addon/context/inline-onebox-css-classes.js.erb b/app/assets/javascripts/pretty-text/addon/context/inline-onebox-css-classes.js.erb
new file mode 100644
index 0000000..a252fb2
--- /dev/null
+++ b/app/assets/javascripts/pretty-text/addon/context/inline-onebox-css-classes.js.erb
@@ -0,0 +1,5 @@
+export const INLINE_ONEBOX_LOADING_CSS_CLASS =
+  "<%= CookedPostProcessor::INLINE_ONEBOX_LOADING_CSS_CLASS %>";
+
+export const INLINE_ONEBOX_CSS_CLASS =
+  "<%= CookedPostProcessor::INLINE_ONEBOX_CSS_CLASS %>";
diff --git a/app/assets/javascripts/pretty-text/addon/emoji.js b/app/assets/javascripts/pretty-text/addon/emoji.js
new file mode 100644
index 0000000..74af3b9
--- /dev/null
+++ b/app/assets/javascripts/pretty-text/addon/emoji.js
@@ -0,0 +1,243 @@
+import {
+  emojis,
+  aliases,
+  searchAliases,
+  translations,
+  tonableEmojis,
+  replacements
+} from "pretty-text/emoji/data";
+import { IMAGE_VERSION } from "pretty-text/emoji/version";
+
+const extendedEmoji = {};
+
+export function registerEmoji(code, url, group) {
+  code = code.toLowerCase();
+  extendedEmoji[code] = { url, group };
+}
+
+export function extendedEmojiList() {
+  return extendedEmoji;
+}
+
+const emojiHash = {};
+
+export function buildReplacementsList(emojiReplacements) {
+  return Object.keys(emojiReplacements)
+    .sort()
+    .reverse()
+    .map(emoji => {
+      return emoji
+        .split("")
+        .map(chr => {
+          return (
+            "\\u" +
+            chr
+              .charCodeAt(0)
+              .toString(16)
+              .padStart(4, "0")
+          );
+        })
+        .join("");
+    })
+    .join("|");
+}
+
+let replacementListCache;
+const unicodeRegexpCache = {};
+
+function replacementList() {
+  if (replacementListCache === undefined) {
+    replacementListCache = buildReplacementsList(replacements);
+  }
+
+  return replacementListCache;
+}
+
+function unicodeRegexp(inlineEmoji) {
+  if (unicodeRegexpCache[inlineEmoji] === undefined) {
+    const emojiExpression = inlineEmoji
+      ? "|:[^\\s:]+(?::t\\d)?:?"
+      : "|\\B:[^\\s:]+(?::t\\d)?:?\\B";
+
+    unicodeRegexpCache[inlineEmoji] = new RegExp(
+      replacementList() + emojiExpression,
+      "g"
+    );
+  }
+
+  return unicodeRegexpCache[inlineEmoji];
+}
+
+// add all default emojis
+emojis.forEach(code => (emojiHash[code] = true));
+
+// and their aliases
+const aliasHash = {};
+Object.keys(aliases).forEach(name => {

[... diff too long, it was truncated ...]

GitHub sha: 79c64eae

This commit appears in #9689 which was merged by eviltrout.