@@ -8,6 +8,8 @@ import type StateBlock from 'markdown-it/lib/rules_block/state_block.mjs'
88import type Token from 'markdown-it/lib/token.mjs'
99
1010const DETAILS_START_REGEX = / ^ < d e t a i l s > \s * $ /
11+ const DETAILS_AND_SUMMARY_START_REGEX =
12+ / (?< = ^ < d e t a i l s > \s * < s u m m a r y > ) .* (? = < \/ s u m m a r y > \s * $ ) /
1113const DETAILS_END_REGEX = / ^ < \/ d e t a i l s > \s * $ /
1214const SUMMARY_REGEX = / (?< = ^ < s u m m a r y > ) .* (? = < \/ s u m m a r y > \s * $ ) /
1315
@@ -28,8 +30,17 @@ function parseDetails(
2830 let start = state . bMarks [ startLine ] + state . tShift [ startLine ]
2931 let max = state . eMarks [ startLine ]
3032
31- // Details block start
32- if ( ! state . src . slice ( start , max ) . match ( DETAILS_START_REGEX ) ) {
33+ let detailsFound = false
34+ let detailsSummary = null
35+ let startLineCount = 2
36+
37+ const m = state . src . slice ( start , max ) . match ( DETAILS_AND_SUMMARY_START_REGEX )
38+ if ( m ) {
39+ // Details block start and summary in same line
40+ detailsSummary = m [ 0 ] . trim ( )
41+ startLineCount = 1
42+ } else if ( ! state . src . slice ( start , max ) . match ( DETAILS_START_REGEX ) ) {
43+ // Details block start in separate line
3344 return false
3445 }
3546
@@ -38,8 +49,6 @@ function parseDetails(
3849 return true
3950 }
4051
41- let detailsFound = false
42- let detailsSummary = null
4352 let nestedCount = 0
4453 let nextLine = startLine
4554 for ( ; ; ) {
@@ -112,7 +121,7 @@ function parseDetails(
112121
113122 token = state . push ( 'details_summary' , 'summary' , - 1 )
114123
115- state . md . block . tokenize ( state , startLine + 2 , nextLine )
124+ state . md . block . tokenize ( state , startLine + startLineCount , nextLine )
116125
117126 token = state . push ( 'details_close' , 'details' , - 1 )
118127 token . block = true
0 commit comments