1
1
import Remarkable from 'remarkable' ;
2
2
import htmlparser from 'htmlparser2' ;
3
3
4
- import { getDims } from './imageDims.js' ;
4
+ import { getDims , updateImgTags } from './imageDims.js' ;
5
5
import { createAmpPage } from './templates.js' ;
6
6
7
7
const remarkable = new Remarkable ( 'full' ) ;
@@ -16,27 +16,12 @@ export const parse = (markdown, optsOrStyle, callback) => {
16
16
17
17
export const markdown2AmpHTML = ( opts , callback ) => {
18
18
const { markdown } = opts ;
19
- console . log ( opts , markdown ) ;
20
- console . log ( markdown ) ;
21
19
const htmlRaw = remarkable . render ( markdown ) ;
22
- parseHtml ( htmlRaw , ( html , data ) => {
23
- getDims ( data . urls , ( dimensions ) => {
24
- const imageTagRegex = / ( < i m g ) / ;
25
- let htmlAml = html ;
26
- let i = 0 ;
27
- // todo remove while loop
28
- while ( imageTagRegex . test ( htmlAml ) ) {
29
- const newTag = `
30
- <amp-img
31
- width="${ dimensions [ i ] . width } "
32
- height="${ dimensions [ i ] . height } "
33
- layout="responsive"` ;
34
- htmlAml = htmlAml . replace ( imageTagRegex , newTag ) ;
35
- i += 1 ;
36
- }
37
- callback ( htmlAml ) ;
38
- } ) ;
39
- } ) ;
20
+ parseHtml ( htmlRaw , ( html , { imageUrls } ) =>
21
+ getDims ( imageUrls , ( dimensions ) =>
22
+ callback ( updateImgTags ( html , dimensions ) )
23
+ )
24
+ ) ;
40
25
}
41
26
42
27
var attribStr = attribs => Object . keys ( attribs ) . map ( attribKey => (
@@ -47,7 +32,7 @@ var attribStr = attribs => Object.keys(attribs).map(attribKey => (
47
32
48
33
var createParseRules = ( ) => [
49
34
( urls => ( {
50
- label : "urls " ,
35
+ label : "imageUrls " ,
51
36
target : "img" ,
52
37
onOpenTag : attribs => urls . push ( attribs . src ) ,
53
38
getResults : ( ) => urls
0 commit comments