aboutsummaryrefslogtreecommitdiff
path: root/src/client/util
diff options
context:
space:
mode:
authorbob <bcz@cs.brown.edu>2019-09-06 13:45:04 -0400
committerbob <bcz@cs.brown.edu>2019-09-06 13:45:04 -0400
commit173863d85ee590c276bf22b1cfe91e0d00986720 (patch)
tree3159c7b07af9ceb72d2db97228253cc2d566ebc8 /src/client/util
parent2707e0898d535cc143272b7bf3b80f829368c097 (diff)
added named target docs from rich text.
Diffstat (limited to 'src/client/util')
-rw-r--r--src/client/util/ProsemirrorExampleTransfer.ts16
-rw-r--r--src/client/util/RichTextSchema.tsx12
2 files changed, 20 insertions, 8 deletions
diff --git a/src/client/util/ProsemirrorExampleTransfer.ts b/src/client/util/ProsemirrorExampleTransfer.ts
index da26da4f9..cc2ae7d38 100644
--- a/src/client/util/ProsemirrorExampleTransfer.ts
+++ b/src/client/util/ProsemirrorExampleTransfer.ts
@@ -142,6 +142,11 @@ export default function buildKeymap<S extends Schema<any>>(schema: S, mapKeys?:
}
});
+ let splitMetadata = (marks: any, tx: Transaction) => {
+ marks && tx.ensureMarks(marks.filter((val: any) => val.type !== schema.marks.metadata && val.type !== schema.marks.metadataKey && val.type !== schema.marks.metadataVal));
+ marks && tx.setStoredMarks(marks.filter((val: any) => val.type !== schema.marks.metadata && val.type !== schema.marks.metadataKey && val.type !== schema.marks.metadataVal));
+ return tx;
+ }
bind("Enter", (state: EditorState<S>, dispatch: (tx: Transaction<S>) => void) => {
if (!keys["ACTIVE"]) {// hack to ignore an initial carriage return when creating a textbox from the action menu
dispatch(state.tr.setSelection(TextSelection.create(state.doc, state.selection.from - 1, state.selection.from)).deleteSelection());
@@ -150,8 +155,7 @@ export default function buildKeymap<S extends Schema<any>>(schema: S, mapKeys?:
var marks = state.storedMarks || (state.selection.$to.parentOffset && state.selection.$from.marks());
if (!splitListItem(schema.nodes.list_item)(state, (tx3: Transaction) => dispatch(tx3))) {
if (!splitBlockKeepMarks(state, (tx3: Transaction) => {
- marks && tx3.ensureMarks(marks.filter((val: any) => val.type !== schema.marks.metadata));
- marks && tx3.setStoredMarks(marks.filter((val: any) => val.type !== schema.marks.metadata));
+ splitMetadata(marks, tx3);
if (!liftListItem(schema.nodes.list_item)(tx3, dispatch as ((tx: Transaction<Schema<any, any>>) => void))) {
dispatch(tx3);
}
@@ -163,10 +167,7 @@ export default function buildKeymap<S extends Schema<any>>(schema: S, mapKeys?:
});
bind("Space", (state: EditorState<S>, dispatch: (tx: Transaction<S>) => void) => {
var marks = state.storedMarks || (state.selection.$to.parentOffset && state.selection.$from.marks());
- let tx = state.tr;
- marks && tx.ensureMarks(marks.filter((val: any) => val.type !== schema.marks.metadata));
- marks && tx.setStoredMarks(marks.filter((val: any) => val.type !== schema.marks.metadata));
- dispatch(tx);
+ dispatch(splitMetadata(marks, state.tr));
return false;
});
bind(":", (state: EditorState<S>, dispatch: (tx: Transaction<S>) => void) => {
@@ -180,7 +181,8 @@ export default function buildKeymap<S extends Schema<any>>(schema: S, mapKeys?:
let whitespace = text.length - 1;
for (; whitespace >= 0 && text[whitespace] !== " "; whitespace--) { }
if (text.endsWith(":")) {
- dispatch(state.tr.addMark(textsel.from + whitespace + 1, textsel.to, schema.marks.metadata.create() as any));
+ dispatch(state.tr.addMark(textsel.from + whitespace + 1, textsel.to, schema.marks.metadata.create() as any).
+ addMark(textsel.from + whitespace + 1, textsel.to - 2, schema.marks.metadataKey.create() as any));
}
return false;
});
diff --git a/src/client/util/RichTextSchema.tsx b/src/client/util/RichTextSchema.tsx
index 5ee445590..6bae63174 100644
--- a/src/client/util/RichTextSchema.tsx
+++ b/src/client/util/RichTextSchema.tsx
@@ -317,7 +317,17 @@ export const marks: { [index: string]: MarkSpec } = {
metadata: {
toDOM() {
- return ['span', { style: 'border-radius:5px; background:rgba(100, 100, 100, 0.1); box-shadow: black 1px 1px 1px' }];
+ return ['span', { style: 'font-size:75%; background:rgba(100, 100, 100, 0.2); ' }];
+ }
+ },
+ metadataKey: {
+ toDOM() {
+ return ['span', { style: 'font-style:italic; ' }];
+ }
+ },
+ metadataVal: {
+ toDOM() {
+ return ['span', { style: 'background:rgba(100, 100, 100, 0.1);' }];
}
},