@@ -3,6 +3,27 @@ import { get } from '../util/ajax.js';
33
44const cached = { } ;
55
6+ /**
7+ * Extracts the content between matching fragment markers in the text.
8+ *
9+ * Supported markers:
10+ * - ### [fragment] ... ### [fragment]
11+ * - /// [fragment] ... /// [fragment]
12+ *
13+ * @param {string } text - The input text that may contain embedded fragments.
14+ * @param {string } fragment - The fragment identifier to search for.
15+ * @returns {string } - The extracted and demented content, or an empty string if not found.
16+ */
17+ function extractFragmentContent ( text , fragment ) {
18+ if ( ! fragment ) { return text ; }
19+
20+ const pattern = new RegExp (
21+ `(?:###|\\/\\/\\/)\\s*\\[${ fragment } \\]([\\s\\S]*?)(?:###|\\/\\/\\/)\\s*\\[${ fragment } \\]` ,
22+ ) ;
23+ const match = text . match ( pattern ) ;
24+ return stripIndent ( ( match || [ ] ) [ 1 ] || '' ) . trim ( ) ;
25+ }
26+
627function walkFetchEmbed ( { embedTokens, compile, fetch } , cb ) {
728 let token ;
829 let step = 0 ;
@@ -44,14 +65,14 @@ function walkFetchEmbed({ embedTokens, compile, fetch }, cb) {
4465 text = $docsify . frontMatter . parseMarkdown ( text ) ;
4566 }
4667
68+ if ( currentToken . embed . fragment ) {
69+ text = extractFragmentContent ( text , currentToken . embed . fragment ) ;
70+ }
71+
4772 embedToken = compile . lexer ( text ) ;
4873 } else if ( currentToken . embed . type === 'code' ) {
4974 if ( currentToken . embed . fragment ) {
50- const fragment = currentToken . embed . fragment ;
51- const pattern = new RegExp (
52- `(?:###|\\/\\/\\/)\\s*\\[${ fragment } \\]([\\s\\S]*)(?:###|\\/\\/\\/)\\s*\\[${ fragment } \\]` ,
53- ) ;
54- text = stripIndent ( ( text . match ( pattern ) || [ ] ) [ 1 ] || '' ) . trim ( ) ;
75+ text = extractFragmentContent ( text , currentToken . embed . fragment ) ;
5576 }
5677
5778 embedToken = compile . lexer (
0 commit comments