a tool for shared writing and social publishing
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add markdown shortcuts for highlight and strikethrough

+33
+33
components/Blocks/TextBlock/inputRules.ts
··· 8 8 import { ReplicacheMutators } from "src/replicache"; 9 9 import { BlockProps, focusBlock } from "components/Blocks"; 10 10 import { schema } from "./schema"; 11 + import { useUIState } from "src/useUIState"; 11 12 export const inputrules = ( 12 13 propsRef: MutableRefObject<BlockProps & { entity_set: { set: string } }>, 13 14 repRef: MutableRefObject<Replicache<ReplicacheMutators> | null>, 14 15 ) => 15 16 inputRules({ 16 17 rules: [ 18 + new InputRule(/\~\~([^*]+)\~\~$/, (state, match, start, end) => { 19 + const [fullMatch, content] = match; 20 + const { tr } = state; 21 + if (content) { 22 + tr.replaceWith(start, end, state.schema.text(content)) 23 + .addMark( 24 + start, 25 + start + content.length, 26 + schema.marks.strikethrough.create(), 27 + ) 28 + .removeStoredMark(schema.marks.strikethrough); 29 + return tr; 30 + } 31 + return null; 32 + }), 33 + new InputRule(/\=\=([^*]+)\=\=$/, (state, match, start, end) => { 34 + const [fullMatch, content] = match; 35 + const { tr } = state; 36 + if (content) { 37 + tr.replaceWith(start, end, state.schema.text(content)) 38 + .addMark( 39 + start, 40 + start + content.length, 41 + schema.marks.highlight.create({ 42 + color: useUIState.getState().lastUsedHighlight || "1", 43 + }), 44 + ) 45 + .removeStoredMark(schema.marks.highlight); 46 + return tr; 47 + } 48 + return null; 49 + }), 17 50 new InputRule(/\*\*([^*]+)\*\*$/, (state, match, start, end) => { 18 51 const [fullMatch, content] = match; 19 52 const { tr } = state;