@@ -20,8 +20,8 @@ export function useMarkdown () {
20
20
return
21
21
}
22
22
23
- let markdownContent = `# ${ frontmatter . value ?. meta . title || 'Page Title' } \\n\ \n`
24
- markdownContent += `Source: ${ window . location . origin } ${ route . path } \\n\ \n`
23
+ let markdownContent = `# ${ frontmatter . value ?. meta . title || 'Page Title' } \n \n`
24
+ markdownContent += `Source: ${ window . location . origin } ${ route . path } \n \n`
25
25
26
26
try {
27
27
const path = `packages/docs/src/pages${ route . path . replace ( / \/ $ / , '' ) } .md`
@@ -35,7 +35,54 @@ export function useMarkdown () {
35
35
36
36
if ( response . data && 'content' in response . data ) {
37
37
const rawMd = atob ( response . data . content )
38
- const contentWithoutFrontmatter = rawMd . replace ( / - - - [ \\ s \\ S ] * ?- - - / , '' ) . trim ( )
38
+ let processedMd = rawMd
39
+
40
+ // Remove <ApiInline /> and <ExamplesUsage /> tags completely
41
+ processedMd = processedMd
42
+ . replace ( / < A p i I n l i n e [ \s \S ] * ?> ( [ \s \S ] * ?\/ > \n \n ) ? / g, '' )
43
+ . replace ( / < E x a m p l e s U s a g e [ \s \S ] * ?> ( [ \s \S ] * ?\/ > \n \n ) ? / g, '' )
44
+
45
+ // Replace every <ExamplesExample ...> tag with the raw Vue source of its file
46
+ if ( processedMd . includes ( '<ExamplesExample' ) ) {
47
+ const tagRegex = / < E x a m p l e s E x a m p l e \b ( [ ^ > ] * ?) > (?: [ \s \S ] * ?< \/ E x a m p l e s E x a m p l e > ) | < E x a m p l e s E x a m p l e \b ( [ ^ > ] * ?) \/ > / g
48
+ const matches = [ ...processedMd . matchAll ( tagRegex ) ]
49
+
50
+ for ( const m of matches ) {
51
+ const attrs = m [ 1 ] ?? m [ 2 ] ?? ''
52
+ const fileMatch = attrs . match ( / \b f i l e \s * = \s * " ( [ ^ " ] + ) " / )
53
+ if ( ! fileMatch ) {
54
+ // Remove tag if no file attribute
55
+ processedMd = processedMd . replace ( m [ 0 ] , '' )
56
+ continue
57
+ }
58
+
59
+ const filePath = fileMatch [ 1 ] . replace ( / \\ + / g, '/' ) . replace ( / \/ $ / , '' )
60
+ const pathExamples = `packages/docs/src/examples/${ filePath } .vue`
61
+
62
+ try {
63
+ const responseExamples = await octokit . request ( 'GET /repos/{owner}/{repo}/contents/{path}' , {
64
+ owner : 'vuetifyjs' ,
65
+ repo : 'vuetify' ,
66
+ path : pathExamples ,
67
+ ref : branch ,
68
+ } )
69
+
70
+ if ( responseExamples . data && 'content' in responseExamples . data ) {
71
+ const rawVue = atob ( responseExamples . data . content )
72
+ // Replace whole tag with fenced code block of the example source
73
+ processedMd = processedMd . replace ( m [ 0 ] , `\n\`\`\`vue\n${ rawVue } \n\`\`\`\n` )
74
+ } else {
75
+ // If fetch fails, strip the tag to avoid leaving placeholders
76
+ processedMd = processedMd . replace ( m [ 0 ] , '' )
77
+ }
78
+ } catch ( e ) {
79
+ console . error ( 'Error fetching example file' , filePath , e )
80
+ processedMd = processedMd . replace ( m [ 0 ] , '' )
81
+ }
82
+ }
83
+ }
84
+
85
+ const contentWithoutFrontmatter = processedMd . replace ( / - - - [ \s \S ] * ?- - - / , '' ) . trim ( )
39
86
markdownContent += contentWithoutFrontmatter
40
87
} else {
41
88
markdownContent += 'Could not fetch page content.'
0 commit comments