diff --git a/core/client/assets/vendor/to-title-case.js b/core/client/assets/vendor/to-title-case.js new file mode 100644 index 0000000000..cdb561e718 --- /dev/null +++ b/core/client/assets/vendor/to-title-case.js @@ -0,0 +1,22 @@ +/* + * To Title Case 2.0.1 – http://individed.com/code/to-title-case/ + * Copyright © 2008–2012 David Gouch. Licensed under the MIT License. + */ + +String.prototype.toTitleCase = function () { + var smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|of|on|or|the|to|vs?\.?|via)$/i; + + return this.replace(/([^\W_]+[^\s-]*) */g, function (match, p1, index, title) { + if (index > 0 && index + p1.length !== title.length && + p1.search(smallWords) > -1 && title.charAt(index - 2) !== ":" && + title.charAt(index - 1).search(/[^\s-]/) < 0) { + return match.toLowerCase(); + } + + if (p1.substr(1).search(/[A-Z]|\../) > -1) { + return match; + } + + return match.charAt(0).toUpperCase() + match.substr(1); + }); +}; \ No newline at end of file diff --git a/core/client/markdown-actions.js b/core/client/markdown-actions.js index 3c2325470b..bc8ce43cef 100644 --- a/core/client/markdown-actions.js +++ b/core/client/markdown-actions.js @@ -38,7 +38,7 @@ md = text.toLocaleLowerCase(); break; case "titlecase": - md = text.replace(/\w\S*/g, function (text) {return text.charAt(0).toUpperCase() + text.substr(1).toLowerCase(); }); + md = text.toTitleCase(); break; case "selectword": cursor = this.elem.getCursor(); diff --git a/core/server/views/default.hbs b/core/server/views/default.hbs index 51ac5ae425..67b1118cb0 100644 --- a/core/server/views/default.hbs +++ b/core/server/views/default.hbs @@ -44,6 +44,7 @@ +