[jira] [Comment Edited] (FREEMARKER-97) Header capitalization using standard styles

2018-07-16 Thread T X (JIRA)


[ 
https://issues.apache.org/jira/browse/FREEMARKER-97?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16545520#comment-16545520
 ] 

T X edited comment on FREEMARKER-97 at 7/16/18 5:40 PM:


Great question, [~ddekany]. The phrase _because of_, is commonly thought of as 
a preposition; by itself, _because_ is also considered by some to be a 
subordinating conjunction. The _Chicago Manual of Style_ doesn't capitalize any 
prepositions, as you pointed out, excepting at the start of a sentence. 
Additionally, conjunctions are not capitalized.

[http://www.businesswritingblog.com/business_writing/2010/02/words-to-capitalize-in-titles-and-headings.html]

This is a bit of a rabbit hole, though:

[http://www.slate.com/blogs/lexicon_valley/2014/01/16/because_why_the_word_is_not_a_conjunction_as_dictionaries_have_it_but_instead.html]

I'd suggest leaving both mid-line occurrences lowercase, which also simplifies 
the code. (Note that the other online converters always capitalize _because_, 
regardless of _of_.)

I've asked a few folks who have studied English grammar, specifically the CMS.


was (Author: thangalin):
Great question, [~ddekany]. The phrase _because of_, is commonly thought of as 
a preposition; by itself, _because_ is also considered by some to be a 
subordinating conjunction. The _Chicago Manual of Style_ doesn't capitalize any 
prepositions, as you pointed out, excepting at the start of a sentence. 
Additionally, conjunctions are not capitalized.

[http://www.businesswritingblog.com/business_writing/2010/02/words-to-capitalize-in-titles-and-headings.html]

This is a bit of a rabbit hole, though:

[http://www.slate.com/blogs/lexicon_valley/2014/01/16/because_why_the_word_is_not_a_conjunction_as_dictionaries_have_it_but_instead.html]

I'd suggest leaving both mid-line occurrences lowercase, which also simplifies 
the code. (Note that the other online converters always capitalize _because_, 
regardless of _of_.)

> Header capitalization using standard styles
> ---
>
> Key: FREEMARKER-97
> URL: https://issues.apache.org/jira/browse/FREEMARKER-97
> Project: Apache Freemarker
>  Issue Type: Wish
>  Components: engine
>Affects Versions: 2.3.28
>Reporter: T X
>Priority: Minor
>
> FreeMarker offers a couple of simple algorithms for changing the case of 
> titles:
>  * 
> [https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_cap_firs|https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_cap_first]
>  * 
> [https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_capitalizet|https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_cap_first]
> Neither of these capitalize the text in ways that adhere to various standard 
> styles:
>  * [Chicago Manual of 
> Style|https://en.wikipedia.org/wiki/The_Chicago_Manual_of_Style]
>  * [Associated Press|https://en.wikipedia.org/wiki/AP_Stylebook]
>  * [MLA Style Manual|https://en.wikipedia.org/wiki/MLA_Style_Manual]
>  * [APA Style|https://en.wikipedia.org/wiki/APA_style]
> Consider the following texts:
>  * On iPhone the Transcript Extends Outside of Screen Frame
>  * PEAR And GNA Report Performance
>  * BCMailPlusFTPClient Sends Document without Document ID
>  * JWebUnit: Non-PEN Orders main.xhtml Meta Refresh Tag Issue
> These are correct as written and must not be adjusted by an algorithm that 
> changes the text title. There are a couple of web sites that produce the 
> expected titles (note that the second site capitalizes the word "without," 
> which implies the algorithm does not use Chicago conventions):
>  * [https://titlecaseconverter.com/]
>  * [http://individed.com/code/to-title-case/]
> There are a variety of implementations that perform such a feat:
> * 
> [JavaScript|https://github.com/gouch/to-title-case/blob/master/to-title-case.js]
> * [Perl|https://gist.github.com/gruber/9f9e8650d68b13ce4d78]
> * [PHP|https://gist.github.com/HipsterJazzbo/2532c93a18db7451b0cec529c95b53c4]
> These implementations do not require a whitelist. (So "iPhone" and 
> "ClassName" will remain as given.) Apache Commons' {{WordUtils}} class does 
> not implement Chicago Style, and I suspect it is also a fairly simple 
> algorithm.
> Since {{?capitalize}} and {{?cap_first}} are taken, I propose {{?title_case}} 
> with an optional parameter (default is Chicago):
>  * chicago
>  * ap
>  * apa
>  * mla
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Comment Edited] (FREEMARKER-97) Header capitalization using standard styles

2018-06-12 Thread T X (JIRA)


[ 
https://issues.apache.org/jira/browse/FREEMARKER-97?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16509834#comment-16509834
 ] 

T X edited comment on FREEMARKER-97 at 6/12/18 4:35 PM:


David Gouch wrote:
{quote}It’s fine with me if you want to include my title case implementation or 
translate it to Java. In fact, I’m pretty sure the MIT license means you can do 
that whether I’m fine with it or not.
{quote}
Now we have permission to take the first JavaScript implementation shown, 
translate it to Java, put an Apache 2 License on it, and distribute it. For 
completeness, here's the permission request I wrote to David Gouch, John Resig, 
and John Gruber:
{quote}Regarding the following implementations:
 * [http://individed.com/code/to-title-case/] (David Gouch)
 * [https://daringfireball.net/2008/05/title_case] (John Gruber)
 * [https://johnresig.com/files/titleCaps.js] (John Resig)

Would it be permissible to re-license the (JavaScript) code under an Apache 2 
License for inclusion within Apache FreeMarker? (Translated to Java...)
{quote}
Only David Gouch has responded.


was (Author: thangalin):
David Gouch wrote:
{quote}It’s fine with me if you want to include my title case implementation or 
translate it to Java. In fact, I’m pretty sure the MIT license means you can do 
that whether I’m fine with it or not.
{quote}
Now we have permission to take the first JavaScript implementation shown, 
translate it to Java, put an Apache 2 License on it, and distribute it. For 
completeness, here's what I wrote to David Gouch, John Resig, and John Gruber:
{quote}Regarding the following implementations:
 * [http://individed.com/code/to-title-case/] (David Gouch)
 * [https://daringfireball.net/2008/05/title_case] (John Gruber)
 * [https://johnresig.com/files/titleCaps.js] (John Resig)

Would it be permissible to re-license the (JavaScript) code under an Apache 2 
License for inclusion within Apache FreeMarker? (Translated to Java...)
{quote}
Only David Gouch has responded.

> Header capitalization using standard styles
> ---
>
> Key: FREEMARKER-97
> URL: https://issues.apache.org/jira/browse/FREEMARKER-97
> Project: Apache Freemarker
>  Issue Type: Wish
>  Components: engine
>Affects Versions: 2.3.28
>Reporter: T X
>Priority: Minor
>
> FreeMarker offers a couple of simple algorithms for changing the case of 
> titles:
>  * 
> [https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_cap_firs|https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_cap_first]
>  * 
> [https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_capitalizet|https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_cap_first]
> Neither of these capitalize the text in ways that adhere to various standard 
> styles:
>  * [Chicago Manual of 
> Style|https://en.wikipedia.org/wiki/The_Chicago_Manual_of_Style]
>  * [Associated Press|https://en.wikipedia.org/wiki/AP_Stylebook]
>  * [MLA Style Manual|https://en.wikipedia.org/wiki/MLA_Style_Manual]
>  * [APA Style|https://en.wikipedia.org/wiki/APA_style]
> Consider the following texts:
>  * On iPhone the Transcript Extends Outside of Screen Frame
>  * PEAR And GNA Report Performance
>  * BCMailPlusFTPClient Sends Document without Document ID
>  * JWebUnit: Non-PEN Orders main.xhtml Meta Refresh Tag Issue
> These are correct as written and must not be adjusted by an algorithm that 
> changes the text title. There are a couple of web sites that produce the 
> expected titles (note that the second site capitalizes the word "without," 
> which implies the algorithm does not use Chicago conventions):
>  * [https://titlecaseconverter.com/]
>  * [http://individed.com/code/to-title-case/]
> There are a variety of implementations that perform such a feat:
> * 
> [JavaScript|https://github.com/gouch/to-title-case/blob/master/to-title-case.js]
> * [Perl|https://gist.github.com/gruber/9f9e8650d68b13ce4d78]
> * [PHP|https://gist.github.com/HipsterJazzbo/2532c93a18db7451b0cec529c95b53c4]
> These implementations do not require a whitelist. (So "iPhone" and 
> "ClassName" will remain as given.) Apache Commons' {{WordUtils}} class does 
> not implement Chicago Style, and I suspect it is also a fairly simple 
> algorithm.
> Since {{?capitalize}} and {{?cap_first}} are taken, I propose {{?title_case}} 
> with an optional parameter (default is Chicago):
>  * chicago
>  * ap
>  * apa
>  * mla
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Comment Edited] (FREEMARKER-97) Header capitalization using standard styles

2018-06-12 Thread T X (JIRA)


[ 
https://issues.apache.org/jira/browse/FREEMARKER-97?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16509834#comment-16509834
 ] 

T X edited comment on FREEMARKER-97 at 6/12/18 4:34 PM:


David Gouch wrote:
{quote}It’s fine with me if you want to include my title case implementation or 
translate it to Java. In fact, I’m pretty sure the MIT license means you can do 
that whether I’m fine with it or not.
{quote}
Now we have permission to take the first JavaScript implementation shown, 
translate it to Java, put an Apache 2 License on it, and distribute it. For 
completeness, here's what I wrote to David Gouch, John Resig, and John Gruber:
{quote}Regarding the following implementations:
 * [http://individed.com/code/to-title-case/] (David Gouch)
 * [https://daringfireball.net/2008/05/title_case] (John Gruber)
 * [https://johnresig.com/files/titleCaps.js] (John Resig)

Would it be permissible to re-license the (JavaScript) code under an Apache 2 
License for inclusion within Apache FreeMarker? (Translated to Java...)
{quote}
Only David Gouch has responded.


was (Author: thangalin):
David Gouch wrote:
{quote}It’s fine with me if you want to include my title case implementation or 
translate it to Java. In fact, I’m pretty sure the MIT license means you can do 
that whether I’m fine with it or not.
{quote}
Now we have permission to take the first JavaScript implementation shown, 
translate it to Java, put an Apache 2 License on it, and distribute it. For 
completeness, here's what I wrote to David Gouch, John Resig, and John Gruber:
{quote}Regarding the following implementations:
 * [http://individed.com/code/to-title-case/] (David Gouch)
 * [https://daringfireball.net/2008/05/title_case] (John Gruber)
 * [https://johnresig.com/files/titleCaps.js] (John Resig)

Would it be permissible to re-license the (JavaScript) code under an Apache 2 
License for inclusion within Apache FreeMarker? (Translated to Java; see issue 
tracker for details.)
{quote}
Only David Gouch has responded.

> Header capitalization using standard styles
> ---
>
> Key: FREEMARKER-97
> URL: https://issues.apache.org/jira/browse/FREEMARKER-97
> Project: Apache Freemarker
>  Issue Type: Wish
>  Components: engine
>Affects Versions: 2.3.28
>Reporter: T X
>Priority: Minor
>
> FreeMarker offers a couple of simple algorithms for changing the case of 
> titles:
>  * 
> [https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_cap_firs|https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_cap_first]
>  * 
> [https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_capitalizet|https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_cap_first]
> Neither of these capitalize the text in ways that adhere to various standard 
> styles:
>  * [Chicago Manual of 
> Style|https://en.wikipedia.org/wiki/The_Chicago_Manual_of_Style]
>  * [Associated Press|https://en.wikipedia.org/wiki/AP_Stylebook]
>  * [MLA Style Manual|https://en.wikipedia.org/wiki/MLA_Style_Manual]
>  * [APA Style|https://en.wikipedia.org/wiki/APA_style]
> Consider the following texts:
>  * On iPhone the Transcript Extends Outside of Screen Frame
>  * PEAR And GNA Report Performance
>  * BCMailPlusFTPClient Sends Document without Document ID
>  * JWebUnit: Non-PEN Orders main.xhtml Meta Refresh Tag Issue
> These are correct as written and must not be adjusted by an algorithm that 
> changes the text title. There are a couple of web sites that produce the 
> expected titles (note that the second site capitalizes the word "without," 
> which implies the algorithm does not use Chicago conventions):
>  * [https://titlecaseconverter.com/]
>  * [http://individed.com/code/to-title-case/]
> There are a variety of implementations that perform such a feat:
> * 
> [JavaScript|https://github.com/gouch/to-title-case/blob/master/to-title-case.js]
> * [Perl|https://gist.github.com/gruber/9f9e8650d68b13ce4d78]
> * [PHP|https://gist.github.com/HipsterJazzbo/2532c93a18db7451b0cec529c95b53c4]
> These implementations do not require a whitelist. (So "iPhone" and 
> "ClassName" will remain as given.) Apache Commons' {{WordUtils}} class does 
> not implement Chicago Style, and I suspect it is also a fairly simple 
> algorithm.
> Since {{?capitalize}} and {{?cap_first}} are taken, I propose {{?title_case}} 
> with an optional parameter (default is Chicago):
>  * chicago
>  * ap
>  * apa
>  * mla
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Comment Edited] (FREEMARKER-97) Header capitalization using standard styles

2018-06-04 Thread T X (JIRA)


[ 
https://issues.apache.org/jira/browse/FREEMARKER-97?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16500684#comment-16500684
 ] 

T X edited comment on FREEMARKER-97 at 6/4/18 6:32 PM:
---

The JavaScript implementation translates into Java code reasonably easily, and 
essentially implements the Chicago Manual of Style, which would be suitable as 
the base implementation:

{code:javascript}
/* 
  * To Title Case 2.1 – http://individed.com/code/to-title-case/
  * Copyright © 2008–2013 David Gouch. Licensed under the MIT License.
 */

String.prototype.toTitleCase = function(){
  var smallWords = 
/^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|vs?\.?|via)$/i;

  return this.replace(/[A-Za-z0-9\u00C0-\u00FF]+[^\s-]*/g, function(match, 
index, title){
if (index > 0 && index + match.length !== title.length &&
  match.search(smallWords) > -1 && title.charAt(index - 2) !== ":" &&
  (title.charAt(index + match.length) !== '-' || title.charAt(index - 1) 
=== '-') &&
  title.charAt(index - 1).search(/[^\s-]/) < 0) {
  return match.toLowerCase();
}

if (match.substr(1).search(/[A-Z]|\../) > -1) {
  return match;
}

return match.charAt(0).toUpperCase() + match.substr(1);
  });
};
{code}

Alternatively, there is John Gruber's and John Resig's [JavaScript 
implementation|https://johnresig.com/files/titleCaps.js]:

{code:javascript}
/*
 * Title Caps
 * 
 * Ported to JavaScript By John Resig - http://ejohn.org/ - 21 May 2008
 * Original by John Gruber - http://daringfireball.net/ - 10 May 2008
 * License: http://www.opensource.org/licenses/mit-license.php
 */

(function(){
var small = 
"(a|an|and|as|at|but|by|en|for|if|in|of|on|or|the|to|v[.]?|via|vs[.]?)";
var punct = "([!\"#$%&'()*+,./:;<=>?@[\\]^_`{|}~-]*)";
  
this.titleCaps = function(title){
var parts = [], split = /[:.;?!] |(?: |^)["Ò]/g, index = 0;

while (true) {
var m = split.exec(title);

parts.push( title.substring(index, m ? m.index : 
title.length)
.replace(/\b([A-Za-z][a-z.'Õ]*)\b/g, 
function(all){
return /[A-Za-z]\.[A-Za-z]/.test(all) ? 
all : upper(all);
})
.replace(RegExp("\\b" + small + "\\b", "ig"), 
lower)
.replace(RegExp("^" + punct + small + "\\b", 
"ig"), function(all, punct, word){
return punct + upper(word);
})
.replace(RegExp("\\b" + small + punct + "$", 
"ig"), upper));

index = split.lastIndex;

if ( m ) parts.push( m[0] );
else break;
}

return parts.join("").replace(/ V(s?)\. /ig, " v$1. ")
.replace(/(['Õ])S\b/ig, "$1s")
.replace(/\b(AT|Q)\b/ig, function(all){
return all.toUpperCase();
});
};

function lower(word){
return word.toLowerCase();
}

function upper(word){
  return word.substr(0,1).toUpperCase() + word.substr(1);
}
})();
{code}

[~ddekany] wrote:

{quote}Then there's the slight problem that if we support, say, English, French 
and Spanish out of the box, then why not language X... people can read things 
into that.{quote}

Be open and honest. It takes time, skill, and multi-lingual fluency to develop 
software that operates on multiple human languages. People are welcome to 
contribute. It's a good idea to ensure that the implementation is pluggable so 
that writing different converters is easy. (Also, {{title_case}} isn't 
applicable to every language -- some writing systems have no concept of upper 
case and lower case.)


was (Author: thangalin):
The JavaScript implementation translates into Java code reasonably easily, and 
essentially implements the Chicago Manual of Style, which would be suitable as 
the base implementation:

{code:javascript}
/* 
  * To Title Case 2.1 – http://individed.com/code/to-title-case/
  * Copyright © 2008–2013 David Gouch. Licensed under the MIT License.
 */

String.prototype.toTitleCase = function(){
  var smallWords = 
/^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|vs?\.?|via)$/i;

  return this.replace(/[A-Za-z0-9\u00C0-\u00FF]+[^\s-]*/g, function(match, 
index, title){
if (index > 0 && index + match.length !== title.length &&
  match.search(smallWords) > -1 && title.charAt(index - 2) !== ":" &&
  (title.charAt(index + match.length) !== '-' || title.charAt(index - 1) 
=== '-') &&
  title.charAt(index - 

[jira] [Comment Edited] (FREEMARKER-97) Header capitalization using standard styles

2018-06-04 Thread T X (JIRA)


[ 
https://issues.apache.org/jira/browse/FREEMARKER-97?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16500684#comment-16500684
 ] 

T X edited comment on FREEMARKER-97 at 6/4/18 6:31 PM:
---

The JavaScript implementation translates into Java code reasonably easily, and 
essentially implements the Chicago Manual of Style, which would be suitable as 
the base implementation:

{code:javascript}
/* 
  * To Title Case 2.1 – http://individed.com/code/to-title-case/
  * Copyright © 2008–2013 David Gouch. Licensed under the MIT License.
 */

String.prototype.toTitleCase = function(){
  var smallWords = 
/^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|vs?\.?|via)$/i;

  return this.replace(/[A-Za-z0-9\u00C0-\u00FF]+[^\s-]*/g, function(match, 
index, title){
if (index > 0 && index + match.length !== title.length &&
  match.search(smallWords) > -1 && title.charAt(index - 2) !== ":" &&
  (title.charAt(index + match.length) !== '-' || title.charAt(index - 1) 
=== '-') &&
  title.charAt(index - 1).search(/[^\s-]/) < 0) {
  return match.toLowerCase();
}

if (match.substr(1).search(/[A-Z]|\../) > -1) {
  return match;
}

return match.charAt(0).toUpperCase() + match.substr(1);
  });
};
{code}

Alternatively, there is John Gruber's and John Resig's [JavaScript 
implementation|https://johnresig.com/files/titleCaps.js]:

{code:javascript}
/*
 * Title Caps
 * 
 * Ported to JavaScript By John Resig - http://ejohn.org/ - 21 May 2008
 * Original by John Gruber - http://daringfireball.net/ - 10 May 2008
 * License: http://www.opensource.org/licenses/mit-license.php
 */

(function(){
var small = 
"(a|an|and|as|at|but|by|en|for|if|in|of|on|or|the|to|v[.]?|via|vs[.]?)";
var punct = "([!\"#$%&'()*+,./:;<=>?@[\\]^_`{|}~-]*)";
  
this.titleCaps = function(title){
var parts = [], split = /[:.;?!] |(?: |^)["Ò]/g, index = 0;

while (true) {
var m = split.exec(title);

parts.push( title.substring(index, m ? m.index : 
title.length)
.replace(/\b([A-Za-z][a-z.'Õ]*)\b/g, 
function(all){
return /[A-Za-z]\.[A-Za-z]/.test(all) ? 
all : upper(all);
})
.replace(RegExp("\\b" + small + "\\b", "ig"), 
lower)
.replace(RegExp("^" + punct + small + "\\b", 
"ig"), function(all, punct, word){
return punct + upper(word);
})
.replace(RegExp("\\b" + small + punct + "$", 
"ig"), upper));

index = split.lastIndex;

if ( m ) parts.push( m[0] );
else break;
}

return parts.join("").replace(/ V(s?)\. /ig, " v$1. ")
.replace(/(['Õ])S\b/ig, "$1s")
.replace(/\b(AT|Q)\b/ig, function(all){
return all.toUpperCase();
});
};

function lower(word){
return word.toLowerCase();
}

function upper(word){
  return word.substr(0,1).toUpperCase() + word.substr(1);
}
})();
{code}

{quote}Then there's the slight problem that if we support, say, English, French 
and Spanish out of the box, then why not language X... people can read things 
into that.{quote}

Be open and honest. It takes time, skill, and multi-lingual fluency to develop 
software that operates on multiple human languages. People are welcome to 
contribute. It's a good idea to ensure that the implementation is pluggable so 
that writing different converters is easy. (Also, {{title_case}} isn't 
applicable to every language -- some writing systems have no concept of upper 
case and lower case.)


was (Author: thangalin):
The JavaScript implementation translates into Java code reasonably easily, and 
essentially implements the Chicago Manual of Style, which would be suitable as 
the base implementation:

{code:javascript}
/* 
  * To Title Case 2.1 – http://individed.com/code/to-title-case/
  * Copyright © 2008–2013 David Gouch. Licensed under the MIT License.
 */

String.prototype.toTitleCase = function(){
  var smallWords = 
/^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|vs?\.?|via)$/i;

  return this.replace(/[A-Za-z0-9\u00C0-\u00FF]+[^\s-]*/g, function(match, 
index, title){
if (index > 0 && index + match.length !== title.length &&
  match.search(smallWords) > -1 && title.charAt(index - 2) !== ":" &&
  (title.charAt(index + match.length) !== '-' || title.charAt(index - 1) 
=== '-') &&
  title.charAt(index - 1).search(/[^\s-]/)