Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Transform text so that sentence case capitalizes after :, ?, ! Th... #402

Merged
merged 1 commit into from
Jan 14, 2014

Conversation

adam3smith
Copy link
Contributor

...is is in line with English usage and this function is principally useful for English titles.

@adam3smith
Copy link
Contributor Author

addresses #293

@adam3smith
Copy link
Contributor Author

any chance to get this into the next release? - seems small, low risk, & useful to me

var newVal = val.length ? val[0].toUpperCase()+val.substr(1).toLowerCase() : val;
//capitalize after :, ?, ! and remove space(s) before those analogous to capitalizeTitle function
var titleparts = val.split(/\s*([:\?!]\s?)/);
var fulltitle = new Array;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be [].

@dstillman
Copy link
Member

But before you address the above comments, can you just do this with a single regexp replace?
Something similar to this:

js -a

js> var foo = "Quick brown foxes:  do they really jump over lazy dogs?";
js> foo.replace(/([:]\s*[^\s])/g, function (x) { return x.replace(/\s+/m, " ").toUpperCase(); })
"Quick brown foxes: Do they really jump over lazy dogs?"

@adam3smith
Copy link
Contributor Author

done - looking much neater now.

@dstillman
Copy link
Member

Great, thanks. Can you rebase and squash this into a single commit?

… This is in line with English usage and this function is principally useful for English titles.

also deal with punctuation at the beginning of title

Also fix capitalizeTitle to work with quotation marks and Spanish beginning punctuation. Also adds ? and ! as punctuation after which it always capitalizes

switch sentence case conversion to a regex; I'm leaving capitalizeTitle as the substring routine, it's the same length and probably slightly more efficient.
@adam3smith
Copy link
Contributor Author

done

dstillman added a commit that referenced this pull request Jan 14, 2014
Change Transform text so that sentence case capitalizes after :, ?, ! Th...
@dstillman dstillman merged commit c1c2f6b into zotero:4.0 Jan 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants