File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -43,9 +43,16 @@ class MarkdownButtonElement extends HTMLElement {
4343class MarkdownHeaderButtonElement extends MarkdownButtonElement {
4444 constructor ( ) {
4545 super ( )
46+
47+ if ( ! this . hasAttribute ( 'level' ) ) {
48+ this . setAttribute ( 'level' , '3' )
49+ }
50+
51+ const level = parseInt ( this . getAttribute ( 'level' ) , 10 )
52+ const prefix = `${ '#' . repeat ( level ) } `
4653 styles . set ( this , {
47- prefix : '#' . repeat ( this . getAttribute ( 'level' ) || 3 ) . ' '
48- } ) ;
54+ prefix
55+ } )
4956 }
5057}
5158
Original file line number Diff line number Diff 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} )
You can’t perform that action at this time.
0 commit comments