@@ -528,5 +528,50 @@ func convertJekyllContent(m interface{}, content string) string {
528528 content = replace .re .ReplaceAllString (content , replace .replace )
529529 }
530530
531+ replaceListFunc := []struct {
532+ re * regexp.Regexp
533+ replace func (string ) string
534+ }{
535+ // Octopress image tag: http://octopress.org/docs/plugins/image-tag/
536+ {regexp .MustCompile (`{%\s+img\s*(.*?)\s*%}` ), replaceImageTag },
537+ }
538+
539+ for _ , replace := range replaceListFunc {
540+ content = replace .re .ReplaceAllStringFunc (content , replace .replace )
541+ }
542+
531543 return content
532544}
545+
546+ func replaceImageTag (match string ) string {
547+ r := regexp .MustCompile (`{%\s+img\s*(\p{L}*)\s+([\S]*/[\S]+)\s+(\d*)\s*(\d*)\s*(.*?)\s*%}` )
548+ result := bytes .NewBufferString ("{{< figure " )
549+ parts := r .FindStringSubmatch (match )
550+ // Index 0 is the entire string, ignore
551+ replaceOptionalPart (result , "class" , parts [1 ])
552+ replaceOptionalPart (result , "src" , parts [2 ])
553+ replaceOptionalPart (result , "width" , parts [3 ])
554+ replaceOptionalPart (result , "height" , parts [4 ])
555+ // title + alt
556+ part := parts [5 ]
557+ if len (part ) > 0 {
558+ splits := strings .Split (part , "'" )
559+ lenSplits := len (splits )
560+ if lenSplits == 1 {
561+ replaceOptionalPart (result , "title" , splits [0 ])
562+ } else if lenSplits == 3 {
563+ replaceOptionalPart (result , "title" , splits [1 ])
564+ } else if lenSplits == 5 {
565+ replaceOptionalPart (result , "title" , splits [1 ])
566+ replaceOptionalPart (result , "alt" , splits [3 ])
567+ }
568+ }
569+ result .WriteString (">}}" )
570+ return result .String ()
571+
572+ }
573+ func replaceOptionalPart (buffer * bytes.Buffer , partName string , part string ) {
574+ if len (part ) > 0 {
575+ buffer .WriteString (partName + "=\" " + part + "\" " )
576+ }
577+ }
0 commit comments