# Can InputRules match marks?

**URL:** <https://discuss.prosemirror.net/t/can-inputrules-match-marks/1724>\
**Category:** Uncategorized\
**Created:** [January 7, 2019, 7:24am UTC](https://discuss.prosemirror.net/t/can-inputrules-match-marks/1724 "2019-01-07T07:24:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alecyrus](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/alecyrus/32/842_2.png) [@Alecyrus](https://discuss.prosemirror.net/u/Alecyrus)\
**Post date:** [January 7, 2019, 7:24am UTC](https://discuss.prosemirror.net/t/can-inputrules-match-marks/1724/1 "2019-01-07T07:24:46Z")

</div>

## [possible solution #537](https://discuss.prosemirror.net/t/input-rules-for-wrapping-marks/537)

There is my solution

```auto
const ruleMarkTypes = [
  {
    name: 'subscript',
    rule: (markType) => {
      let getAttrs = {}
      return new InputRule(
        /\s_((?!_|\s).)+\s/,
        (state, match, start, end) => {
          let attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs
          let tr = state.tr
          end = start + match[0].length - 1

          tr.addMark(start, end, markType.create(attrs))
            .delete(start, start + 2)
            .removeStoredMark(markType)
          return tr
        })
    }
  },
  {
    name: 'superscript',
    rule: (markType) => {
      let getAttrs = {}
      return new InputRule(
        /\s\^((?!\^|\s).)+\s/,
        (state, match, start, end) => {
          let attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs
          let tr = state.tr
          end = start + match[0].length - 1

          tr.addMark(start, end, markType.create(attrs))
            .delete(start, start + 2)
            .removeStoredMark(markType)
          return tr
        })
    }
  },
  {
    name: 'strikethrough',
    rule: (markType) => {
      let getAttrs = {}
      return new InputRule(
        /\s~[\S\s]*~\s/,
        (state, match, start, end) => {
          let attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs
          let tr = state.tr
          end = start + match[0].length - 1

          tr.addMark(start, end, markType.create(attrs))
            .delete(end - 1, end)
            .delete(start, start + 2)
            .removeStoredMark(markType)
          return tr
        })
    }
  },
  {
    name: 'highlight',
    rule: (markType) => {
      let getAttrs = {}
      return new InputRule(
        /\s`[\S\s]*`\s/,
        (state, match, start, end) => {
          let attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs
          let tr = state.tr
          end = start + match[0].length - 1

          tr.addMark(start, end, markType.create(attrs))
            .delete(end - 1, end)
            .delete(start, start + 2)
            .removeStoredMark(markType)
          return tr
        })
    }
  },
  {
    name: 'em',
    rule: (markType) => {
      let getAttrs = {}
      return new InputRule(
        /\s\^[\S\s]*\^\s/,
        (state, match, start, end) => {
          let attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs
          let tr = state.tr
          end = start + match[0].length - 1

          tr.addMark(start, end, markType.create(attrs))
            .delete(end - 1, end)
            .delete(start, start + 2)
            .removeStoredMark(markType)
          return tr
        })
    }
  },
  {
    name: 'strong',
    rule: (markType) => {
      let getAttrs = {}
      return new InputRule(
        /\s\*[\S\s]*\*\s/,
        (state, match, start, end) => {
          let attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs
          let tr = state.tr
          end = start + match[0].length - 1

          tr.addMark(start, end, markType.create(attrs))
            .delete(end - 1, end)
            .delete(start, start + 2)
            .removeStoredMark(markType)
          return tr
        })
    }
  },
  {
    name: 'underline',
    rule: (markType) => {
      let getAttrs = {}
      return new InputRule(
        /\s_[\S\s]*_\s/,
        (state, match, start, end) => {
          let attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs
          let tr = state.tr
          end = start + match[0].length - 1

          tr.addMark(start, end, markType.create(attrs))
            .delete(end - 1, end)
            .delete(start, start + 2)
            .removeStoredMark(markType)
          return tr
        })
    }
  }
]

```

### Screenshot:

![Jan-08-2019%2012-59-30](https://discuss.prosemirror.net/uploads/secondsite/original/1X/2edd41a2347f66ad24c7fe92fc02513712643c5e.gif)

---

<div class="post-metadata">

**Author:** ![Alecyrus](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/alecyrus/32/842_2.png) [@Alecyrus](https://discuss.prosemirror.net/u/Alecyrus)\
**Post date:** [January 7, 2019, 10:32am UTC](https://discuss.prosemirror.net/t/can-inputrules-match-marks/1724/4 "2019-01-07T10:32:43Z")

</div>

@ [marijn](https://discuss.prosemirror.net/u/marijn)
