# Input rules for wrapping marks

**URL:** https://discuss.prosemirror.net/t/input-rules-for-wrapping-marks/537
**Category:** Uncategorized
**Created:** [December 21, 2016, 8:31am UTC](https://discuss.prosemirror.net/t/input-rules-for-wrapping-marks/537 "2016-12-21T08:31:25Z")
**Posts on this page:** 1
**Showing post:** 11

<div class="post-metadata">

### Author: ![ncphillips](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/ncphillips/32/387_2.png) [@ncphillips](https://discuss.prosemirror.net/u/ncphillips)
#### Post date: [September 23, 2017, 6:17pm UTC](https://discuss.prosemirror.net/t/input-rules-for-wrapping-marks/537/11 "2017-09-23T18:17:58Z")

</div>

@marijn I got it working so the mark is not applied to the new text! It’s your implementation exactly, except for the second last line

```auto
function markInputRule(regexp, markType, getAttrs) {
  return new InputRule(regexp, (state, match, start, end) => {
    let attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs
    let tr = state.tr
    if (match[1]) {
      let textStart = start + match[0].indexOf(match[1])
      let textEnd = textStart + match[1].length
      if (textEnd < end) tr.delete(textEnd, end)
      if (textStart > start) tr.delete(start, textStart)
      end = start + match[1].length
    }
    tr.addMark(start, end, markType.create(attrs))
    tr.removeStoredMark(markType) // Do not continue with mark.
    return tr
  })
}

```

---

_[View the full topic](https://discuss.prosemirror.net/t/input-rules-for-wrapping-marks/537)._
