Skip to content

Commit f561560

Browse files
authored
Merge pull request #20 from mintbridge/patch-2
add attribute support for setting the heading level
2 parents 5cb0f70 + a315e88 commit f561560

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ class MarkdownButtonElement extends HTMLElement {
4343
class MarkdownHeaderButtonElement extends MarkdownButtonElement {
4444
constructor() {
4545
super()
46-
styles.set(this, {prefix: '### '})
46+
47+
const level = parseInt(this.getAttribute('level') || 3, 10)
48+
const prefix = `${'#'.repeat(level)} `
49+
styles.set(this, {
50+
prefix
51+
})
4752
}
4853
}
4954

test/test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ describe('markdown-toolbbar-element', function() {
7070
<markdown-toolbar for="textarea_id">
7171
<md-bold>bold</md-bold>
7272
<md-header>header</md-header>
73+
<md-header level="1">h1</md-header>
7374
<md-italic>italic</md-italic>
7475
<md-quote>quote</md-quote>
7576
<md-code>code</md-code>
@@ -489,5 +490,18 @@ describe('markdown-toolbbar-element', function() {
489490
assert.equal("GitHub's [homepage](|url|)", visualValue())
490491
})
491492
})
493+
494+
describe('header', function() {
495+
it('inserts header syntax with cursor in description', function() {
496+
setVisualValue('|title|')
497+
clickToolbar('md-header')
498+
assert.equal('### |title|', visualValue())
499+
})
500+
it('inserts header 1 syntax with cursor in description', function() {
501+
setVisualValue('|title|')
502+
clickToolbar('md-header[level="1"]')
503+
assert.equal('# |title|', visualValue())
504+
})
505+
})
492506
})
493507
})

0 commit comments

Comments
 (0)