diff options
author | Sam Wilkins <samwilkins333@gmail.com> | 2019-08-13 22:15:47 -0400 |
---|---|---|
committer | Sam Wilkins <samwilkins333@gmail.com> | 2019-08-13 22:15:47 -0400 |
commit | 2b829d1028a61869858ecd48e2f1801819e17488 (patch) | |
tree | 2140fff63d1308d7672b7fec173aa053ae44787a /src/new_fields/RichTextField.ts | |
parent | 2ed0c3e1203794ddaa0b17ed908432582d0198d1 (diff) |
robust google doc export api and cleanup
Diffstat (limited to 'src/new_fields/RichTextField.ts')
-rw-r--r-- | src/new_fields/RichTextField.ts | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/new_fields/RichTextField.ts b/src/new_fields/RichTextField.ts index 89799b2af..dc66813e0 100644 --- a/src/new_fields/RichTextField.ts +++ b/src/new_fields/RichTextField.ts @@ -9,6 +9,7 @@ import { scriptingGlobal } from "../client/util/Scripting"; export class RichTextField extends ObjectField { @serializable(true) readonly Data: string; + private Extractor = /,\"text\":\"([^\"\}]*)\"\}/g; constructor(data: string) { super(); @@ -22,4 +23,16 @@ export class RichTextField extends ObjectField { [ToScriptString]() { return `new RichTextField("${this.Data}")`; } + + plainText = () => { + let contents = ""; + let matches: RegExpExecArray | null; + let considering = this.Data; + while ((matches = this.Extractor.exec(considering)) !== null) { + contents += matches[1]; + considering = considering.substring(matches.index + matches[0].length); + this.Extractor.lastIndex = 0; + } + return contents.length ? contents : undefined; + } }
\ No newline at end of file |