# What should be the input rule to convert - - to horizontal rule?

**URL:** <https://discuss.prosemirror.net/t/what-should-be-the-input-rule-to-convert-to-horizontal-rule/3874>\
**Category:** Uncategorized\
**Created:** [June 30, 2021, 2:00pm UTC](https://discuss.prosemirror.net/t/what-should-be-the-input-rule-to-convert-to-horizontal-rule/3874 "2021-06-30T14:00:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![powerranger](https://discuss.prosemirror.net/letter_avatar_proxy/v4/letter/p/eada6e/32.png) [@powerranger](https://discuss.prosemirror.net/u/powerranger)\
**Post date:** [June 30, 2021, 2:00pm UTC](https://discuss.prosemirror.net/t/what-should-be-the-input-rule-to-convert-to-horizontal-rule/3874/1 "2021-06-30T14:00:44Z")

</div>

I want to convert ‘- -’ into a horizontal rule. Unable to understand which input rule to use.

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)\
**Post date:** [June 30, 2021, 2:25pm UTC](https://discuss.prosemirror.net/t/what-should-be-the-input-rule-to-convert-to-horizontal-rule/3874/2 "2021-06-30T14:25:51Z")

</div>

You’ll have to write one yourself, passing a function as second argument to the `InputRule` constructor.

---

<div class="post-metadata">

**Author:** ![kepta](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/kepta/32/1674_2.png) [@kepta](https://discuss.prosemirror.net/u/kepta)\
**Post date:** [June 30, 2021, 5:04pm UTC](https://discuss.prosemirror.net/t/what-should-be-the-input-rule-to-convert-to-horizontal-rule/3874/3 "2021-06-30T17:04:50Z")

</div>

Hey recently wrote something [similar](https://github.com/kepta/bangle-play/blob/bbeec38d8a6c4feb3e624d926158ab2e512fde4b/core/components/horizontal-rule.ts#L38) the code would be something like this:

```auto
new InputRule(
          /^(?:---|___\s|\*\*\*\s)$/,
          (state, match, start, end) => {
            if (!match[0]) {
              return null;
            }
            let tr = state.tr.replaceWith(start - 1, end, type.createChecked());
            // Find the paragraph that contains the "---" shortcut text, we need
            // it below for deciding whether to insert a new paragraph after the
            // hr.
            const $para = state.doc.resolve(start);

            let insertParaAfter = false;
            if ($para.end() != end) {
              // if the paragraph has more characters, e.g. "---abc", then no
              // need to insert a new paragraph
              insertParaAfter = false;
            } else if ($para.after() == $para.end(-1)) {
              // if the paragraph is the last child of its parent, then insert a
              // new paragraph
              insertParaAfter = true;
            } else {
              const nextNode = state.doc.resolve($para.after()).nodeAfter!;
              // if the next node is a hr, then insert a new paragraph
              insertParaAfter = nextNode.type === type;
            }
            return insertParaAfter
              ? safeInsert(
                  state.schema.nodes.paragraph.createChecked(),
                  tr.mapping.map($para.after()),
                )(tr)
              : tr;
          },
)

```
