Trial 3
- This version handles period when your title has two or three sentences
- It handles major/minor words (except verbs, nouns, adjectives with three or less characters)
- It handles hyphenated words (special tanks to @pmario, @Charlie_Veniot, @Scott_Sauyet, and @saqimtiaz: see Regexp Search and Replace for Words with Dash (Hyphen) - Discussion - Talk TW (tiddlywiki.org)
\define mytitle() Use it to keep your to-do list, to plan an essay or novel, or to organise your wedding. Record every thought that crosses your brain, or build a flexible and responsive website.
\define punc() . , ? ! ; :
\define major() [split[]]:except[enlist<punc>]:and[join[]length[]compare:number:gt[3]]
\define pat() \w+[-]+\w+(-\w*)?
\define hyphenated-major() [split[-]last[]split[]]:except[enlist<punc>]:and[join[]length[]compare:number:gt[3]]
\define hyphen()
[regexp<pat>filter<hyphenated-major>split[-]titlecase[]join[-]else{!!title}]
\end
\define handlewords()
[<currentTiddler>split[ ]first[]titlecase[]]
[<currentTiddler>split[ ]butfirst[]] :map[filter<major>titlecase[]else<currentTiddler>]
:map:flat[subfilter<hyphen>]
:and[join[ ]]
\end
\define apa-titlecase(title)
<!--
step 1: convert to lowercase
step 2: split on sentences (based on period)
step 3: handle words (based on major and minor and hyphen)
-->
<$text text={{{
[<__title__>lowercase[]split[.]]
:map[subfilter<handlewords>]
:and[join[.]]
}}}
/>
\end
!! Example
<$macrocall $name=apa-titlecase title=<<mytitle>> />
Lessons to learn: TiddlyWiki :map filter run prefix allows to run sequence of filter expressions and build pipeline (see Is it the Time to Have Pipeline in TiddlyWiki Filter Language? - Discussion - Talk TW)