File tree 4 files changed +44
-13
lines changed
4 files changed +44
-13
lines changed Original file line number Diff line number Diff line change
1
+ ### test
2
+ 
Original file line number Diff line number Diff line change @@ -45,6 +45,17 @@ describe('Github tests', () => {
45
45
expect ( output . includes ( 'cml=png' ) ) . toBe ( true ) ;
46
46
} ) ;
47
47
48
+ test ( 'Publish image embedded in markdown' , async ( ) => {
49
+ const path = `${ __dirname } /../assets/test.md` ;
50
+ const title = 'my title' ;
51
+
52
+ const output = await new CML ( ) . publish ( { path, md : true , title } ) ;
53
+
54
+ expect ( output . startsWith ( `[${ title } ](https://` ) ) . toBe ( true ) ;
55
+ expect ( output . endsWith ( ')' ) ) . toBe ( true ) ;
56
+ expect ( output . includes ( 'cml=plain' ) ) . toBe ( true ) ;
57
+ } ) ;
58
+
48
59
test ( 'Publish a non image file in markdown' , async ( ) => {
49
60
const path = `${ __dirname } /../assets/logo.pdf` ;
50
61
const title = 'my title' ;
Original file line number Diff line number Diff line change @@ -220,21 +220,40 @@ class CML {
220
220
} ;
221
221
const visitor = async ( node ) => {
222
222
if ( node . url && ! isWatermark ( node ) ) {
223
- const absolutePath = path . resolve (
224
- path . dirname ( markdownFile ) ,
225
- node . url
226
- ) ;
227
- if ( ! triggerFile && watch ) watcher . add ( absolutePath ) ;
228
- try {
223
+ // Check for embedded images from dvclive
224
+ if ( node . url . startsWith ( 'data:image/' ) ) {
225
+ winston . debug (
226
+ `found already embedded image, head: ${ node . url . slice ( 0 , 25 ) } `
227
+ ) ;
228
+ const encodedData = node . url . slice ( node . url . indexOf ( ',' ) + 1 ) ;
229
+ const mimeType = node . url . slice (
230
+ node . url . indexOf ( ':' ) + 1 ,
231
+ node . url . indexOf ( ';' )
232
+ ) ;
233
+ const data = Buffer . from ( encodedData , 'base64' ) ;
229
234
node . url = await this . publish ( {
230
235
...opts ,
231
- path : absolutePath ,
236
+ mimeType : mimeType ,
237
+ buffer : data ,
232
238
url : publishUrl
233
239
} ) ;
234
- } catch ( err ) {
235
- if ( err . code === 'ENOENT' )
236
- winston . debug ( `file not found: ${ node . url } (${ absolutePath } )` ) ;
237
- else throw err ;
240
+ } else {
241
+ const absolutePath = path . resolve (
242
+ path . dirname ( markdownFile ) ,
243
+ node . url
244
+ ) ;
245
+ if ( ! triggerFile && watch ) watcher . add ( absolutePath ) ;
246
+ try {
247
+ node . url = await this . publish ( {
248
+ ...opts ,
249
+ path : absolutePath ,
250
+ url : publishUrl
251
+ } ) ;
252
+ } catch ( err ) {
253
+ if ( err . code === 'ENOENT' )
254
+ winston . debug ( `file not found: ${ node . url } (${ absolutePath } )` ) ;
255
+ else throw err ;
256
+ }
238
257
}
239
258
}
240
259
} ;
Original file line number Diff line number Diff line change @@ -71,7 +71,6 @@ const fetchUploadData = async (opts) => {
71
71
const size = path ? ( await fs . promises . stat ( path ) ) . size : buffer . length ;
72
72
const data = path ? fs . createReadStream ( path ) : buffer ;
73
73
const mime = mimeTypeIn || ( await mimeType ( opts ) ) ;
74
-
75
74
return { mime, size, data } ;
76
75
} ;
77
76
@@ -88,7 +87,6 @@ const upload = async (opts) => {
88
87
} ;
89
88
90
89
if ( session ) headers [ 'Content-Address-Seed' ] = `${ session } :${ path } ` ;
91
-
92
90
const response = await fetch ( url , { method : 'POST' , headers, body } ) ;
93
91
const uri = await response . text ( ) ;
94
92
You can’t perform that action at this time.
0 commit comments