Re: Line breaks are not displayed in emails

SanfordWhiteman
Level 10 - Community Moderator

Re: Line breaks are not displayed in emails

Your instance actually exports the newlines into Velocity? In my tests, line breaks are transformed into spaces (U+0020) before the value is exported, so there’s nothing to replace.

Jo_Pitts1
Level 10 - Community Advisor

Re: Line breaks are not displayed in emails

@Tyron_Pretorius ,

When I do a test using Person Notes I get this

Jo_Pitts1_0-1697011250014.png

Which when run through this velocity code (And I've deliberately done this very stepwise for clarity)

#set ( $myNotesStep0 = $lead.MktoPersonNotes )

#set ($myNotesStep1 = $myNotesStep0.replaceAll("\n","ZZZZ") )
#set ($myNotesStep2 = $myNotesStep1.replaceAll(" ","AAAA") )

Notes are here: ${myNotesStep2}

Yields

Jo_Pitts1_1-1697011341449.png

in my email.

 

This (I think?) conclusively shows the newline is getting converted to a space by the Marketo email processer before Velocity gets its mitts on the string.

 

Cheers

Jo

Jo_Pitts1
Level 10 - Community Advisor

Re: Line breaks are not displayed in emails

@Tyron_Pretorius ,

I went for broke on this and wrote some VTL to spit out each character in notes field.  Here is the output

Jo_Pitts1_1-1697016115874.png

 

Here is the (ugly) code. 

 

I wanted the output in decimal and hex, but I couldn't work out how to natively convert an integer to a hex string, so I wrote my own quick and dirty converter.

#set ( $hex = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"])
#set ( $myNotesStep0 = $lead.MktoPersonNotes )

#set ($myNotesStep1 = $myNotesStep0.replaceAll("\n","ZZZZ") )
#set ($myNotesStep2 = $myNotesStep1.replaceAll(" ","AAAA") )

Notes are here: ${myNotesStep2}<br><br>


#set ($myStr = $lead.MktoPersonNotes)

String Reader for ${myStr}<br>

#set($start = 0)
#set($end = $myStr.length() - 1)
#set($range = [$start..$end])
#foreach($i in $range)
  #set( $aVal = $myStr.codePointAt($i) )
  #set( $aChar = $myStr.substring($i,$math.add($i,1)) )
  #set( $hexPart1 = $math.toInteger( $math.div($aVal,16) ) )
  #set( $hexPart2 = $aVal % 16 )
  #set( $hexCharPart1 = $hex[$hexPart1] )
  #set( $hexCharPart2 = $hex[$hexPart2] )
  Char ${aChar} - Val ${aVal} ( ${hexCharPart1}${hexCharPart2} ) <br>
#end

 

If you're old like me, you'll automatically know that decimal 32 (hex 20)  is the Space character in ASCII.

 

Cheers

Jo

SanfordWhiteman
Level 10 - Community Moderator

Re: Line breaks are not displayed in emails


I wanted the output in decimal and hex, but I couldn't work out how to natively convert an integer to a hex string

#set( $myCharArray = $myString.toCharArray() )
#foreach( $char in $myCharArray )
#if( !$char.isLowSurrogate($char) )
#set( $cp = $char.codePointAt($myCharArray,$foreach.index) )
\u${cp.toHexString($cp).toUpperCase()} ##
#end
#end

 

Outputs the hex codepoints (don’t forget about HS/LS):

\u54 \u68 \u69 \u73 \u20 \u6F \u6E \u63 \u65 \u20 \u68 \u61 \u64 \u20 \u6E \u65 \u77 \u6C \u69 \u6E \u65 \u73 \u2E

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Line breaks are not displayed in emails


This (I think?) conclusively shows the newline is getting converted to a space by the Marketo email processer before Velocity gets its mitts on the string.


Exactly @Jo_Pitts1! You can’t convert something that isn’t there.

 

I recommend separating with an RS (U+001E) character instead of, or in addition to, a newline. The U+001E isn’t removed by Marketo, so you can replace that character with a <br>. About to publish a blog post on this.

Tyron_Pretorius
Level 8 - Champion

Re: Line breaks are not displayed in emails

@SanfordWhiteman @Jo_Pitts1 

 

Here is some more context about my use case and why the code works for me. My field does not contain actual line breaks it contains "\n" characters (or whatever characters I want ChatGPT to use to denote a line break) and then my code replaces these characters. The field is only intended to be viewed from emails where the script runs to tidy it up. It is not intended to be viewed in it's raw form

 

https://www.loom.com/share/5d03c6218d184236a00014dc11a5bc37?sid=ecc6f4d5-7b37-477c-aef5-31bea5f569d9

Tyron Pretorius
SanfordWhiteman
Level 10 - Community Moderator

Re: Line breaks are not displayed in emails

OK, that’s a very different use case. And also explains why you didn’t use the regex \n, because you aren’t using U+000A line breaks at all.

SanfordWhiteman
Level 10 - Community Moderator

Re: Line breaks are not displayed in emails

It'll work fine in an IFRAMEd LP.  Just use the whenReady event in an HTML block in place of the onReady.

MktoForms2.whenReady(function(form){

  form.onSubmit ...