Skip to content

No more then six levels of headers #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class MarkdownHeaderButtonElement extends MarkdownButtonElement {
super()

const level = parseInt(this.getAttribute('level') || 3, 10)
if (level > 6) {
return
}

const prefix = `${'#'.repeat(level)} `
styles.set(this, {
prefix
Expand Down
8 changes: 8 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ describe('markdown-toolbar-element', function() {
<md-bold>bold</md-bold>
<md-header>header</md-header>
<md-header level="1">h1</md-header>
<md-header level="10">h1</md-header>
<md-italic>italic</md-italic>
<md-quote>quote</md-quote>
<md-code>code</md-code>
Expand Down Expand Up @@ -497,11 +498,18 @@ describe('markdown-toolbar-element', function() {
clickToolbar('md-header')
assert.equal('### |title|', visualValue())
})

it('inserts header 1 syntax with cursor in description', function() {
setVisualValue('|title|')
clickToolbar('md-header[level="1"]')
assert.equal('# |title|', visualValue())
})

it('does not insert header for invalid level', function() {
setVisualValue('|title|')
clickToolbar('md-header[level="10"]')
assert.equal('|title|', visualValue())
})
})
})
})