diff --git a/app/assets/javascripts/discourse-markdown-it/src/features/custom-typographer-replacements.js b/app/assets/javascripts/discourse-markdown-it/src/features/custom-typographer-replacements.js index 6d29476d961..2a3d6bc1e05 100644 --- a/app/assets/javascripts/discourse-markdown-it/src/features/custom-typographer-replacements.js +++ b/app/assets/javascripts/discourse-markdown-it/src/features/custom-typographer-replacements.js @@ -14,9 +14,9 @@ // (r) (R) → ® // (p) (P) -> § -let RARE_RE = /\+-|\.\.|\?\?\?\?|!!!!|,,|--|-->|<--|->|<-|<->|<-->/; +export const RARE_RE = /\+-|\.\.|\?\?\?\?|!!!!|,,|--|-->|<--|->|<-|<->|<-->/; -let SCOPED_ABBR_RE = /\((tm|pa)\)/gi; +export const SCOPED_ABBR_RE = /\((tm|pa)\)/gi; let SCOPED_ABBR = { pa: "¶", tm: "™", @@ -32,11 +32,37 @@ function replaceScoped(inlineTokens) { for (i = inlineTokens.length - 1; i >= 0; i--) { token = inlineTokens[i]; if (token.type === "text") { - token.content = token.content.replace(SCOPED_ABBR_RE, replaceFn); + token.content = replaceScopedStr(token.content.replace); } } } +export function replaceScopedStr(str) { + return str.replace(SCOPED_ABBR_RE, replaceFn); +} + +export function replaceRareStr(str) { + return ( + str + .replace(/\+-/g, "±") + // Custom arrows + .replace(/(^|\s)-{1,2}>(\s|$)/gm, "\u0020\u2192\u0020") + .replace(/(^|\s)<-{1,2}(\s|$)/gm, "\u0020\u2190\u0020") + .replace(/(^|\s)<-{1,2}>(\s|$)/gm, "\u0020\u2194\u0020") + // .., ..., ....... -> … + // but ?..... & !..... -> ?.. & !.. + .replace(/\.{2,}/g, "…") + .replace(/([?!])…/g, "$1..") + .replace(/([?!]){4,}/g, "$1$1$1") + .replace(/,{2,}/g, ",") + // em-dash + .replace(/(^|[^-])---(?=[^-]|$)/gm, "$1\u2014") + // en-dash + .replace(/(^|\s)--(?=\s|$)/gm, "$1\u2013") + .replace(/(^|[^-\s])--(?=[^-\s]|$)/gm, "$1\u2013") + ); +} + function replaceRare(inlineTokens) { let i, token, @@ -47,23 +73,7 @@ function replaceRare(inlineTokens) { if (token.type === "text" && !inside_autolink) { if (RARE_RE.test(token.content)) { - token.content = token.content - .replace(/\+-/g, "±") - // Custom arrows - .replace(/(^|\s)-{1,2}>(\s|$)/gm, "\u0020\u2192\u0020") - .replace(/(^|\s)<-{1,2}(\s|$)/gm, "\u0020\u2190\u0020") - .replace(/(^|\s)<-{1,2}>(\s|$)/gm, "\u0020\u2194\u0020") - // .., ..., ....... -> … - // but ?..... & !..... -> ?.. & !.. - .replace(/\.{2,}/g, "…") - .replace(/([?!])…/g, "$1..") - .replace(/([?!]){4,}/g, "$1$1$1") - .replace(/,{2,}/g, ",") - // em-dash - .replace(/(^|[^-])---(?=[^-]|$)/gm, "$1\u2014") - // en-dash - .replace(/(^|\s)--(?=\s|$)/gm, "$1\u2013") - .replace(/(^|[^-\s])--(?=[^-\s]|$)/gm, "$1\u2013"); + token.content = replaceRareStr(token.content); } } diff --git a/app/assets/javascripts/discourse/app/components/composer-container.hbs b/app/assets/javascripts/discourse/app/components/composer-container.hbs index 21782830dca..8270b60d128 100644 --- a/app/assets/javascripts/discourse/app/components/composer-container.hbs +++ b/app/assets/javascripts/discourse/app/components/composer-container.hbs @@ -298,15 +298,17 @@ {{/if}} - - {{d-icon "desktop"}} - + {{#if this.composer.allowPreview}} + + {{d-icon "desktop"}} + + {{/if}} {{#if this.composer.showPreview}} - {{#if this.site.desktopView}} + {{#if (and this.composer.allowPreview this.site.desktopView)}} +
+ +
+; + +export default ComposerToggleSwitch; diff --git a/app/assets/javascripts/discourse/app/components/d-editor.hbs b/app/assets/javascripts/discourse/app/components/d-editor.hbs index f509d8e73a9..d09e11a3bb6 100644 --- a/app/assets/javascripts/discourse/app/components/d-editor.hbs +++ b/app/assets/javascripts/discourse/app/components/d-editor.hbs @@ -8,7 +8,14 @@ {{if this.isEditorFocused 'in-focus'}}" >