diff options
| author | Andy Rickert <andrew_rickert@brown.edu> | 2020-04-15 20:02:58 -0700 | 
|---|---|---|
| committer | Andy Rickert <andrew_rickert@brown.edu> | 2020-04-15 20:02:58 -0700 | 
| commit | 1d5c4510dff326a0f12b914868ac8614ab460e83 (patch) | |
| tree | 7173f465175c6eb6b5bbfe96c932b49fd621f0b0 /src/client/util/RichTextRules.ts | |
| parent | c7c146adbd0b188eba56139ab914edaf73774d3f (diff) | |
| parent | e0f16b89cba102a4fcd156bb3d4148432eca2ab7 (diff) | |
merge
Diffstat (limited to 'src/client/util/RichTextRules.ts')
| -rw-r--r-- | src/client/util/RichTextRules.ts | 32 | 
1 files changed, 17 insertions, 15 deletions
| diff --git a/src/client/util/RichTextRules.ts b/src/client/util/RichTextRules.ts index b0a124cb8..3746199ba 100644 --- a/src/client/util/RichTextRules.ts +++ b/src/client/util/RichTextRules.ts @@ -62,6 +62,17 @@ export class RichTextRules {              // ``` code block              textblockTypeInputRule(/^```$/, schema.nodes.code_block), +            // create an inline view of a tag stored under the '#' field +            new InputRule( +                new RegExp(/#([a-zA-Z_\-]+[a-zA-Z_\-0-9]*)\s$/), +                (state, match, start, end) => { +                    const tag = match[1]; +                    if (!tag) return state.tr; +                    this.Document[DataSym]["#"] = tag; +                    const fieldView = state.schema.nodes.dashField.create({ fieldKey: "#" }); +                    return state.tr.deleteRange(start, end).insert(start, fieldView); +                }), +              // # heading              textblockTypeInputRule(                  new RegExp(/^(#{1,6})\s$/), @@ -81,7 +92,7 @@ export class RichTextRules {              // create a text display of a metadata field on this or another document, or create a hyperlink portal to another document [[ <fieldKey> : <Doc>]]   // [[:Doc]] => hyperlink   [[fieldKey]] => show field   [[fieldKey:Doc]] => show field of doc              new InputRule( -                new RegExp(/\[\[([a-zA-Z_#@\? \-0-9]*)(=[a-zA-Z_#@\? \-0-9]*)?(:[a-zA-Z_#@\? \-0-9]+)?\]\]$/), +                new RegExp(/\[\[([a-zA-Z_@\? \-0-9]*)(=[a-zA-Z_@\? \-0-9]*)?(:[a-zA-Z_@\? \-0-9]+)?\]\]$/),                  (state, match, start, end) => {                      const fieldKey = match[1];                      const docid = match[3]?.substring(1); @@ -99,21 +110,12 @@ export class RichTextRules {                          return state.tr;                      }                      if (value !== "" && value !== undefined) { -                        this.Document[DataSym][fieldKey] = value === "true" ? true : value === "false" ? false : value; +                        const num = value.match(/^[0-9.]/); +                        this.Document[DataSym][fieldKey] = value === "true" ? true : value === "false" ? false : (num ? Number(value) : value);                      }                      const fieldView = state.schema.nodes.dashField.create({ fieldKey, docid });                      return state.tr.deleteRange(start, end).insert(start, fieldView);                  }), -            // create an inline view of a tag stored under the '#' field -            new InputRule( -                new RegExp(/#([a-zA-Z_\-0-9]+)\s$/), -                (state, match, start, end) => { -                    const tag = match[1]; -                    if (!tag) return state.tr; -                    this.Document[DataSym]["#"] = tag; -                    const fieldView = state.schema.nodes.dashField.create({ fieldKey: "#" }); -                    return state.tr.deleteRange(start, end).insert(start, fieldView); -                }),              // create an inline view of a document {{ <layoutKey> : <Doc> }}  // {{:Doc}} => show default view of document   {{<layout>}} => show layout for this doc   {{<layout> : Doc}} => show layout for another doc              new InputRule(                  new RegExp(/\{\{([a-zA-Z_ \-0-9]*)(\([a-zA-Z0-9…._\-]*\))?(:[a-zA-Z_ \-0-9]+)?\}\}$/), @@ -129,12 +131,12 @@ export class RichTextRules {                          }                      });                      const node = (state.doc.resolve(start) as any).nodeAfter; -                    const dashDoc = schema.nodes.dashDoc.create({ width: 75, height: 75, title: "dashDoc", docid, fieldKey: fieldKey + fieldParam, float: "right", alias: Utils.GenerateGuid() }); +                    const dashDoc = schema.nodes.dashDoc.create({ width: 75, height: 75, title: "dashDoc", docid, fieldKey: fieldKey + fieldParam, float: "unset", alias: Utils.GenerateGuid() });                      const sm = state.storedMarks || undefined;                      return node ? state.tr.replaceRangeWith(start, end, dashDoc).setStoredMarks([...node.marks, ...(sm ? sm : [])]) : state.tr;                  }),              new InputRule( -                new RegExp(/##$/), +                new RegExp(/>>$/),                  (state, match, start, end) => {                      const textDoc = this.Document[DataSym];                      const numInlines = NumCast(textDoc.inlineTextCount); @@ -146,7 +148,7 @@ export class RichTextRules {                      textDocInline.customTitle = true; // And make sure that it's 'custom' so that editing text doesn't change the title of the containing doc                      textDocInline.isTemplateForField = inlineFieldKey; // this is needed in case the containing text doc is converted to a template at some point                      textDocInline.proto = textDoc;  // make the annotation inherit from the outer text doc so that it can resolve any nested field references, e.g., [[field]] -                    textDocInline._textContext = ComputedField.MakeFunction(`copyField(this.${inlineFieldKey})`, { this: Doc.name }); +                    textDocInline._textContext = ComputedField.MakeFunction(`copyField(self.${inlineFieldKey})`);                      textDoc[inlineLayoutKey] = FormattedTextBox.LayoutString(inlineFieldKey); // create a layout string for the layout key that will render the annotation text                      textDoc[inlineFieldKey] = ""; // set a default value for the annotation                      const node = (state.doc.resolve(start) as any).nodeAfter; | 
