@@ -33,39 +33,42 @@ const linkTransformer = () => tree => {
3333}
3434/* eslint-enable no-param-reassign */
3535
36- module . exports = function markdownLoader ( content ) {
37- const callback = this . async ( )
38-
36+ const translateMarkdown = markdownSource =>
3937 remark ( )
4038 . use ( frontmatter )
4139 . use ( extract , { yaml } )
4240 . use ( imageFinder )
4341 . use ( linkTransformer )
4442 . use ( html )
45- . process ( content )
46- . then ( vfile => {
47- let output = `export default ${ JSON . stringify ( {
48- ...vfile . data ,
49- html : vfile . contents ,
50- } ) } ;`
43+ . process ( markdownSource )
5144
52- const imports = [ ]
45+ const markdownLoader = function ( content ) {
46+ const callback = this . async ( )
47+ translateMarkdown ( content ) . then ( vfile => {
48+ let output = `export default ${ JSON . stringify ( {
49+ ...vfile . data ,
50+ html : vfile . contents ,
51+ } ) } ;`
5352
54- output = output . replace ( / _ _ _ M D _ C O N T E N T _ I M A G E _ ( [ 0 - 9 ] + ) _ _ _ / g, ( match , p1 ) => {
55- const imageIndex = parseInt ( p1 , 10 )
56- const request = loaderUtils . stringifyRequest (
57- this ,
58- loaderUtils . urlToRequest ( vfile . images [ imageIndex ] )
59- )
60- imports . push ( `import ___MD_CONTENT_IMAGE_${ imageIndex } __ from ${ request } ` )
53+ const imports = [ ]
6154
62- return `" + ___MD_CONTENT_IMAGE_${ imageIndex } __ + "`
63- } )
55+ output = output . replace ( / _ _ _ M D _ C O N T E N T _ I M A G E _ ( [ 0 - 9 ] + ) _ _ _ / g, ( _match , p1 ) => {
56+ const imageIndex = parseInt ( p1 , 10 )
57+ const request = loaderUtils . stringifyRequest (
58+ this ,
59+ loaderUtils . urlToRequest ( vfile . images [ imageIndex ] )
60+ )
61+ imports . push ( `import ___MD_CONTENT_IMAGE_${ imageIndex } __ from ${ request } ` )
6462
65- if ( imports . length > 0 ) {
66- output = `${ imports . join ( ';' ) } ;${ output } `
67- }
63+ return `" + ___MD_CONTENT_IMAGE_${ imageIndex } __ + "`
64+ } )
6865
69- callback ( null , output )
70- } , callback )
66+ if ( imports . length > 0 ) {
67+ output = `${ imports . join ( ';' ) } ;${ output } `
68+ }
69+ callback ( null , output )
70+ } , callback )
7171}
72+
73+ module . exports = markdownLoader
74+ module . exports . translateMarkdown = translateMarkdown
0 commit comments