({ Node, Mark, Extension, Plugin, Decoration, DecorationSet })
| 147 | } |
| 148 | |
| 149 | function buildExtensions ({ Node, Mark, Extension, Plugin, Decoration, DecorationSet }) { |
| 150 | const blockNode = (name, tag, content, extra = {}) => Node.create({ |
| 151 | name, |
| 152 | group: 'block', |
| 153 | content: content || 'block+', |
| 154 | ...extra, |
| 155 | addAttributes () { |
| 156 | return { htmlAttrs: { default: {} } } |
| 157 | }, |
| 158 | parseHTML () { |
| 159 | return [{ tag, getAttrs: collectDomAttrs }] |
| 160 | }, |
| 161 | renderHTML ({ node }) { |
| 162 | return [tag, node.attrs.htmlAttrs, 0] |
| 163 | } |
| 164 | }) |
| 165 | |
| 166 | const attrsMark = (name, tag) => Mark.create({ |
| 167 | name, |
| 168 | addAttributes () { |
| 169 | return { htmlAttrs: { default: {} } } |
| 170 | }, |
| 171 | parseHTML () { |
| 172 | return [{ tag, getAttrs: collectDomAttrs }] |
| 173 | }, |
| 174 | renderHTML ({ mark }) { |
| 175 | return [tag, mark.attrs.htmlAttrs, 0] |
| 176 | } |
| 177 | }) |
| 178 | |
| 179 | const SpanMark = Mark.create({ |
| 180 | name: 'span', |
| 181 | excludes: '', |
| 182 | addAttributes () { |
| 183 | return { htmlAttrs: { default: {} } } |
| 184 | }, |
| 185 | parseHTML () { |
| 186 | return [{ tag: 'span', getAttrs: collectSpanDomAttrs }] |
| 187 | }, |
| 188 | renderHTML ({ mark }) { |
| 189 | return ['span', mark.attrs.htmlAttrs, 0] |
| 190 | } |
| 191 | }) |
| 192 | |
| 193 | const toggleMark = (name, renderTag, parseRules, shortcuts) => Mark.create({ |
| 194 | name, |
| 195 | parseHTML () { |
| 196 | return parseRules |
| 197 | }, |
| 198 | renderHTML () { |
| 199 | return [renderTag, 0] |
| 200 | }, |
| 201 | addCommands () { |
| 202 | const commandName = `toggle${name[0].toUpperCase()}${name.slice(1)}` |
| 203 | |
| 204 | return { |
| 205 | [commandName]: () => ({ commands }) => commands.toggleMark(name) |
| 206 | } |
no test coverage detected