Skip to content

Commit 6a7b35a

Browse files
committed
Add env max height for image
1 parent 09b3ebf commit 6a7b35a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

decorators.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package draftjs
22

3-
import "fmt"
3+
import (
4+
"fmt"
5+
"os"
6+
)
47

58
type Decorator interface {
69
RenderBeginning(data map[string]string) string
@@ -22,10 +25,15 @@ type ImageDecorator struct {
2225
}
2326

2427
func (decorator *ImageDecorator) RenderBeginning(data map[string]string) string {
28+
maxHeight := os.Getenv("IMAGE_MAX_HEIGHT")
29+
maxHeightStr := ""
30+
if maxHeight != "" {
31+
maxHeightStr = fmt.Sprintf(" style=\"max-height:%spx;\"", maxHeight)
32+
}
2533
if alt, ok := data["alt"]; ok {
26-
return fmt.Sprintf("<img src=\"%s\" alt=\"%s\">", data["data"], alt)
34+
return fmt.Sprintf("<img%s src=\"%s\" alt=\"%s\">", data["data"], maxHeightStr, alt)
2735
}
28-
return fmt.Sprintf("<img src=\"%s\">", data["data"])
36+
return fmt.Sprintf("<img%s src=\"%s\">", maxHeightStr, data["data"])
2937
}
3038

3139
func (decorator *ImageDecorator) RenderEnding(data map[string]string) string {

0 commit comments

Comments
 (0)