-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add optional support for showing typographic characters
- Loading branch information
Showing
8 changed files
with
64 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,3 +123,7 @@ | |
label:empty:has(+ .prose-editor) { | ||
display: none; | ||
} | ||
|
||
.prose-editor-nbsp { | ||
background: lightblue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Plugin which shows typographic characters (currently only non-breaking spaces) | ||
|
||
import { Plugin } from "prosemirror-state" | ||
import { Decoration, DecorationSet } from "prosemirror-view" | ||
|
||
const typographicDecorations = (doc) => { | ||
const decorations = [] | ||
doc.descendants((node, position) => { | ||
if (node.text) { | ||
for (const match of node.text.matchAll(/\u00A0/g)) { | ||
const from = position + (match.index || 0) | ||
decorations.push( | ||
Decoration.inline(from, from + 1, { | ||
class: "prose-editor-nbsp", | ||
}), | ||
) | ||
} | ||
} | ||
}) | ||
return DecorationSet.create(doc, decorations) | ||
} | ||
|
||
export const typographicPlugin = new Plugin({ | ||
state: { | ||
init(_, { doc }) { | ||
return typographicDecorations(doc) | ||
}, | ||
apply(tr, set) { | ||
// return set.map(tr.mapping, tr.doc) | ||
// I fear that's not very performant. Maybe improve this "later". | ||
return tr.docChanged ? typographicDecorations(tr.doc) : set | ||
}, | ||
}, | ||
props: { | ||
decorations(state) { | ||
return typographicPlugin.getState(state) | ||
}, | ||
}, | ||
}) |
6316b41
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nada sorry, ich konnte es nicht sein lassen.
6316b41
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😂😂 @matthiask Hahahahaha! Sehr schön.
Bei mir klemmt grad das Hauptprojekt....