@@ -92,16 +92,16 @@ function normalizeIndent(content: string, state: EditorState) {
9292 return space + content . slice ( blank )
9393}
9494
95- /// This command, when invoked in Markdown context with cursor
96- /// selection(s), will create a new line with the markup for
97- /// blockquotes and lists that were active on the old line. If the
98- /// cursor was directly after the end of the markup for the old line,
99- /// trailing whitespace and list markers are removed from that line.
100- ///
101- /// The command does nothing in non-Markdown context, so it should
102- /// not be used as the only binding for Enter (even in a Markdown
103- /// document, HTML and code regions might use a different language).
104- export const insertNewlineContinueMarkup : StateCommand = ( { state, dispatch} ) => {
95+ /// Returns a command like
96+ /// [`insertNewlineContinueMarkup`](#lang-markdown.insertNewlineContinueMarkup),
97+ /// allowing further configuration.
98+ export const insertNewlineContinueMarkupCommand = ( config : {
99+ /// By default, when pressing enter in a blank second item in a
100+ /// tight (no blank lines between items) list, the command will
101+ /// insert a blank line above that item, starting a non-tight list.
102+ /// Set this to false to disable this behavior.
103+ nonTightLists ?: boolean
104+ } = { } ) : StateCommand => ( { state, dispatch} ) => {
105105 let tree = syntaxTree ( state ) , { doc} = state
106106 let dont = null , changes = state . changeByRange ( range => {
107107 if ( ! range . empty || ! markdownLanguage . isActiveAt ( state , range . from , - 1 ) && ! markdownLanguage . isActiveAt ( state , range . from , 1 ) )
@@ -119,7 +119,8 @@ export const insertNewlineContinueMarkup: StateCommand = ({state, dispatch}) =>
119119 let first = inner . node . firstChild ! , second = inner . node . getChild ( "ListItem" , "ListItem" )
120120 // Not second item or blank line before: delete a level of markup
121121 if ( first . to >= pos || second && second . to < pos ||
122- line . from > 0 && ! / [ ^ \s > ] / . test ( doc . lineAt ( line . from - 1 ) . text ) ) {
122+ line . from > 0 && ! / [ ^ \s > ] / . test ( doc . lineAt ( line . from - 1 ) . text ) ||
123+ config . nonTightLists === false ) {
123124 let next = context . length > 1 ? context [ context . length - 2 ] : null
124125 let delTo , insert = ""
125126 if ( next && next . item ) { // Re-add marker for the list at the next level
@@ -172,6 +173,17 @@ export const insertNewlineContinueMarkup: StateCommand = ({state, dispatch}) =>
172173 return true
173174}
174175
176+ /// This command, when invoked in Markdown context with cursor
177+ /// selection(s), will create a new line with the markup for
178+ /// blockquotes and lists that were active on the old line. If the
179+ /// cursor was directly after the end of the markup for the old line,
180+ /// trailing whitespace and list markers are removed from that line.
181+ ///
182+ /// The command does nothing in non-Markdown context, so it should
183+ /// not be used as the only binding for Enter (even in a Markdown
184+ /// document, HTML and code regions might use a different language).
185+ export const insertNewlineContinueMarkup = insertNewlineContinueMarkupCommand ( )
186+
175187function isMark ( node : SyntaxNode ) {
176188 return node . name == "QuoteMark" || node . name == "ListMark"
177189}
0 commit comments