MCPcopy Index your code
hub / github.com/resend/react-email / PrismPlugin

Function PrismPlugin

packages/editor/src/extensions/prism-plugin.ts:127–242  ·  view source on GitHub ↗
({
  name,
  defaultLanguage,
  defaultTheme,
}: {
  name: string;
  defaultLanguage: string;
  defaultTheme: string;
})

Source from the content-addressed store, hash-verified

125}
126
127export function PrismPlugin({
128 name,
129 defaultLanguage,
130 defaultTheme,
131}: {
132 name: string;
133 defaultLanguage: string;
134 defaultTheme: string;
135}) {
136 if (!defaultLanguage) {
137 throw Error('You must specify the defaultLanguage parameter');
138 }
139
140 const loadingLanguages = new Set<string>();
141 let pluginView: EditorView | null = null;
142
143 const onLanguageLoaded = (language: string) => {
144 if (pluginView) {
145 pluginView.dispatch(
146 pluginView.state.tr.setMeta(PRISM_LANGUAGE_LOADED_META, language),
147 );
148 }
149 };
150
151 const prismjsPlugin: Plugin<DecorationSet> = new Plugin({
152 key: new PluginKey('prism'),
153
154 view(view) {
155 pluginView = view;
156 return {
157 destroy() {
158 pluginView = null;
159 },
160 };
161 },
162
163 state: {
164 init: (_, { doc }) => {
165 return getDecorations({
166 doc,
167 name,
168 defaultLanguage,
169 defaultTheme,
170 loadingLanguages,
171 onLanguageLoaded,
172 });
173 },
174 apply: (transaction, decorationSet, oldState, newState) => {
175 const oldNodeName = oldState.selection.$head.parent.type.name;
176 const newNodeName = newState.selection.$head.parent.type.name;
177
178 const oldNodes = findChildren(
179 oldState.doc,
180 (node) => node.type.name === name,
181 );
182 const newNodes = findChildren(
183 newState.doc,
184 (node) => node.type.name === name,

Callers 1

addProseMirrorPluginsFunction · 0.90

Calls 1

getDecorationsFunction · 0.85

Tested by

no test coverage detected