The new in-game text editor is pretty nice, but comes with a problem for API Scripts that depend on reading information from one of the large text areas in the data set. This function helps with that. Given the text from a Graphic' s gmnotes property, or a Character' s bio or gmnotes property, or a Handout' s notes or gmnotes property, this will return a version with the auto-inserted editor formatting stripped out. const decodeEditorText = (t, o) = > {
let w = t;
o = Object . assign ({ separator: '\r\n' , asArray: false },o);
/* Token GM Notes */
if ( / ^%3Cp%3E / . test (w)){
w = unescape (w);
}
if ( / ^<p> / . test (w)){
let lines = w. match ( / <p>.*?< \/ p> / g )
. map ( l = > l. replace ( / ^<p>(.*?)< \/ p>$ / ,'$ 1 '));
return o.asArray ? lines : lines. join (o.separator);
}
/* neither */
return t;
}; The first argument is the text to process. const text = decodeEditorText (token. get ( 'gmnotes' )); By default, the lines of text will be separated by \r\n . The optional second argument is an object with options. separator -- specifies what to separate lines of text with. Default: \r\n const text = decodeEditorText (token. get ( 'gmnotes' ),{separator: '<BR>' }); asArray -- specifies to instead return the lines as an array. Default: false const text = decodeEditorText (token. get ( 'gmnotes' ),{asArray: true }); NOTE: Nested <p> tags will confuse and break the decoding. If you run into that problem and need help, PM The Aaron and he'll be happy to look at it. In the wiki here: <a href="https://wiki.roll20.net/API:Cookbook#decodeEditorText" rel="nofollow">https://wiki.roll20.net/API:Cookbook#decodeEditorText</a>