@@ -3,6 +3,29 @@ import { get } from '../util/ajax.js';
3
3
4
4
const cached = { } ;
5
5
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
+
6
29
function walkFetchEmbed ( { embedTokens, compile, fetch } , cb ) {
7
30
let token ;
8
31
let step = 0 ;
@@ -44,14 +67,14 @@ function walkFetchEmbed({ embedTokens, compile, fetch }, cb) {
44
67
text = $docsify . frontMatter . parseMarkdown ( text ) ;
45
68
}
46
69
70
+ if ( currentToken . embed . fragment ) {
71
+ text = extractFragmentContent ( text , currentToken . embed . fragment ) ;
72
+ }
73
+
47
74
embedToken = compile . lexer ( text ) ;
48
75
} else if ( currentToken . embed . type === 'code' ) {
49
76
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 ) ;
55
78
}
56
79
57
80
embedToken = compile . lexer (
0 commit comments