diff options
author | Bob Zeleznik <zzzman@gmail.com> | 2020-01-28 23:43:53 -0500 |
---|---|---|
committer | Bob Zeleznik <zzzman@gmail.com> | 2020-01-28 23:43:53 -0500 |
commit | 1801e65b9fb84070a65e74766782099e1fb6832b (patch) | |
tree | 182a168bc11abc01aad5f4d165b3bfede7b81a8e /src/client/util/RichTextRules.ts | |
parent | 2ec1a14b2ea19bd66d5f7525619bb9cdd38d39bd (diff) |
added [[[doc:]?field]] to reference a doc field, and @@doc@@ for a hyperlink
Diffstat (limited to 'src/client/util/RichTextRules.ts')
-rw-r--r-- | src/client/util/RichTextRules.ts | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/client/util/RichTextRules.ts b/src/client/util/RichTextRules.ts index d56a6a5fe..cdf7831a9 100644 --- a/src/client/util/RichTextRules.ts +++ b/src/client/util/RichTextRules.ts @@ -75,22 +75,28 @@ export const inpRules = { new InputRule( new RegExp(/\[\[([a-zA-Z_ \-0-9]+)\]\]$/), (state, match, start, end) => { - const fieldKey = match[1]; - const fieldView = state.schema.nodes.dashField.create({ fieldKey: StrCast(fieldKey) }); + const fieldView = state.schema.nodes.dashField.create({ fieldKey: match[1] }); + return state.tr.deleteRange(start, end).insert(start, fieldView); + }), + // create a text display of a metadata field + new InputRule( + new RegExp(/\[\[([a-zA-Z_ \-0-9]+):([a-zA-Z_ \-0-9]+)\]\]$/), + (state, match, start, end) => { + const fieldView = state.schema.nodes.dashField.create({ fieldKey: match[2], docid: match[1] }); return state.tr.deleteRange(start, end).insert(start, fieldView); }), // create a hyperlink portal new InputRule( - new RegExp(/\[\[:([a-zA-Z_ \-0-9]+)\]\]$/), + new RegExp(/@@([a-zA-Z_ \-0-9]+)@@$/), (state, match, start, end) => { - const docId = match[1].substring(1); + const docId = match[1]; DocServer.GetRefField(docId).then(docx => { const target = ((docx instanceof Doc) && docx) || Docs.Create.FreeformDocument([], { title: docId, _width: 500, _height: 500, }, docId); DocUtils.Publish(target, docId, returnFalse, returnFalse); DocUtils.MakeLink({ doc: (schema as any).Document }, { doc: target }, "portal link", ""); }); const link = state.schema.marks.link.create({ href: Utils.prepend("/doc/" + docId), location: "onRight", title: docId, targetId: docId }); - return state.tr.addMark(start, end, link); + return state.tr.deleteRange(end - 1, end).deleteRange(start, start + 2).addMark(start, end - 3, link); }), // stop using active style new InputRule( |