mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Improve title casing
This commit is contained in:
parent
9fd653738d
commit
f85bbd5422
3 changed files with 24 additions and 1 deletions
22
core/client/assets/vendor/to-title-case.js
vendored
Normal file
22
core/client/assets/vendor/to-title-case.js
vendored
Normal file
|
@ -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);
|
||||
});
|
||||
};
|
|
@ -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();
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
<script src="/public/vendor/showdown/extensions/ghostdown.js"></script>
|
||||
<script src="/public/vendor/shortcuts.js"></script>
|
||||
<script src="/public/vendor/countable.js"></script>
|
||||
<script src="/public/vendor/to-title-case.js"></script>
|
||||
<script src="/public/vendor/jquery/jquery-ui-1.10.3.custom.min.js"></script>
|
||||
<script src="/public/vendor/packery.pkgd.min.js"></script>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue