Skip to content

Commit

Permalink
prose: inline-code input rule
Browse files Browse the repository at this point in the history
  • Loading branch information
mhuebert committed Jul 29, 2023
1 parent e74bea3 commit ed69945
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
25 changes: 24 additions & 1 deletion editor2/src/main/maria/editor/prosemirror/input_rules.cljs
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
(ns maria.editor.prosemirror.input-rules
(:require ["prosemirror-inputrules" :as rules]
(:require ["prosemirror-commands" :as pm.cmd]
["prosemirror-inputrules" :as rules]
["prosemirror-model" :as model]
[applied-science.js-interop :as j]
[applied-science.js-interop.alpha :refer [js]]
[maria.editor.prosemirror.schema :refer [schema]]))

;; An input rule defines a regular expression which, when matched on the current input,
;; invokes a command.



(defn toggle-mark-tr [state mark-name & [attrs]]
(let [sel (.-selection state)
mark-type (j/get-in schema [:marks (name mark-name)])
empty (.-empty sel)
$cursor (.-$cursor sel)
the-mark (.create mark-type attrs)
the-node (or (.-node sel) (.-parent (.-$from sel)))
tr (.-tr state)]
(when (and $cursor
(not (or (and empty (not $cursor))
(not (.-inlineContent the-node))
(not (.allowsMarks (.-type the-node) #js [the-mark])))))
(if (.isInSet mark-type (or (.-storedMarks state) (.marks $cursor)))
(.removeStoredMark tr mark-type)
(.addStoredMark tr the-mark)))))

(js
(def maria-rules*

Expand All @@ -15,6 +35,9 @@
code_block
heading]} :nodes} schema]
[~@rules/smartQuotes
(rules/InputRule. #"[^`\\]+`$"
(fn [state match start end]
(toggle-mark-tr state :code)))
rules/ellipsis
rules/emDash

Expand Down
4 changes: 4 additions & 0 deletions editor2/src/maria.cloud.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
@apply ml-5;
}

.ProseMirror code {
@apply bg-black/5 py-[2px] px-[2px];
}

.ProseMirror li {
@apply list-disc;
}
Expand Down

0 comments on commit ed69945

Please # to comment.