@@ -3,6 +3,29 @@ 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 ) {
19+ return text ;
20+ }
21+
22+ const pattern = new RegExp (
23+ `(?:###|\\/\\/\\/)\\s*\\[${ fragment } \\]([\\s\\S]*?)(?:###|\\/\\/\\/)\\s*\\[${ fragment } \\]` ,
24+ ) ;
25+ const match = text . match ( pattern ) ;
26+ return stripIndent ( ( match || [ ] ) [ 1 ] || '' ) . trim ( ) ;
27+ }
28+
629function walkFetchEmbed ( { embedTokens, compile, fetch } , cb ) {
730 let token ;
831 let step = 0 ;
@@ -44,14 +67,14 @@ function walkFetchEmbed({ embedTokens, compile, fetch }, cb) {
4467 text = $docsify . frontMatter . parseMarkdown ( text ) ;
4568 }
4669
70+ if ( currentToken . embed . fragment ) {
71+ text = extractFragmentContent ( text , currentToken . embed . fragment ) ;
72+ }
73+
4774 embedToken = compile . lexer ( text ) ;
4875 } else if ( currentToken . embed . type === 'code' ) {
4976 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 ( ) ;
77+ text = extractFragmentContent ( text , currentToken . embed . fragment ) ;
5578 }
5679
5780 embedToken = compile . lexer (
0 commit comments