decap-cms icon indicating copy to clipboard operation
decap-cms copied to clipboard

Toolbar button for inserting a horizontal rule

Open papandreou opened this issue 7 years ago • 7 comments

- Do you want to request a feature or report a bug?

feature

- What is the current behavior?

There is no way to add a horizontal rule (---) using the markdown widget in rich text mode, except by implementing it as a custom editor widget. I would like to have that so I can use it as a structural divider for some content that I'm managing via netlify-cms.

The editor does have good support for the horizontal rule as soon as it's there, though. It's rendered as a horizontal line that goes all the way across the editor, and it compiles to an <hr> element.

- What is the expected behavior?

That there is a toolbar button with an "—" icon or similar that inserts a --- on an empty line into the markdown.

It seems like slate.js does not have this built in, but we could probably upstream that.

papandreou avatar May 24 '18 07:05 papandreou

Agreed. Related to #1324.

erquhart avatar May 24 '18 13:05 erquhart

Hi, agreed too. (did you build the custom editor widget, and if yes, could you provide the code? thx in advance)

PaulEibensteiner avatar Jun 07 '18 21:06 PaulEibensteiner

@PaulEibensteiner, sure. I'm not too proud of it:

CMS.registerEditorComponent({
  id: 'separator',
  label: '---',
  // A bogus field so that the component doesn't look weird when rendered:
  fields: [{ label: 'Separator', widget: 'select', options: ['---'], default: '---' }],
  // Never match anything so that the separator will be recognized as a horizontal rule when the document is reloaded:
  pattern: /.^/,
  toBlock(obj) {
    return '---';
  },
  toPreview(obj) {
    return '<hr>';
  }
});

papandreou avatar Jun 07 '18 21:06 papandreou

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 29 '19 15:10 stale[bot]

is this still not available? I'm looking for this kind of feature.

Lester016 avatar Sep 16 '20 05:09 Lester016

Would love to see this. It seems to recognize thematic breaks, but can't create them.

jboolean avatar Feb 21 '21 01:02 jboolean

We would happily accept a contribution for this

erezrokah avatar Feb 21 '21 09:02 erezrokah