PennController for IBEX › Forums › Support › preventing dashed sentence spillover / centering sentences › Reply To: preventing dashed sentence spillover / centering sentences
May 28, 2021 at 5:00 pm
#7010
Jeremy
Keymaster
I re-read your message and realized that you might want to print multiple sentences, but only one per line
Here’s a suggestion, it will split your string at every .
, ?
or !
followed by a space and print each sentence on a new, centered line:
dashed = (name,sentences) => [
newText(name,"").size("100vw","auto").center().css("text-align","center").print()
,
...sentences.split(/(?<=[\.!\?])[\s\t]/).map( (s,n) => [
newText(name+"-s"+n,"")
.css({display:'inline-block','line-height':'2em','white-space':'nowrap'})
.print(getText(name))
,
...s.split(/[\s\t]+/).map( (w,i) =>
newText(name+'-s'+n+"-"+i, w.replace(/([^.,?:;!\s])/g,"<span class='DashedSentence-ospan'><span class='DashedSentence-ispan'>$1</span></span>"))
.css("margin","0em 0.25em")
.print(getText(name+"-s"+n))
)
] ).flat()
,
newKey(name+'-start', " ").log().wait() // first keypress, to reveal first word
,
...sentences.split(/(?<=[\.!\?])[\s\t]/).map( (s,n) => [
...s.split(/[\s\t]+/).map((w,i)=>[
getText(name+'-s'+n+'-'+i).text(w) // reveal chunk
,
newKey('s'+n+'-'+i+"-"+w," ").log().wait() // wait for keypress
,
getText(name+'-s'+n+'-'+i).text(w.replace(/([^.,?:;!\s])/g,"<span class='DashedSentence-ospan'><span class='DashedSentence-ispan'>$1</span></span>")) // hide chunk
] ).flat()
] ).flat()
]
Jeremy