@@ -65,27 +65,50 @@ object HtmlGen:
65
65
def elemListItem (level : Int , cls : String = " " )(et : ElemType )(after : String = " " ): String =
66
66
(" " * level) + s """ <li><span class=" $cls"> $et</span>: $after </li> """
67
67
68
- def renderHtmlBody (m : Model , level : Int ): String =
68
+ def renderHtmlBody (m : Model , level : Int , insertImagesWithLocation : Boolean , parent : Option [ Ent ] ): String =
69
69
val ind = (" " * level)
70
70
val lines : Vector [String ] = m.elems.map:
71
71
case Ent (t, id) => elemListItem(level, " entityColor" )(t)(id)
72
- case StrAttr (t, value) => elemListItem(level, " attributeColor" )(t)(value)
72
+
73
+ case StrAttr (t, value) =>
74
+ val imgTag : String =
75
+ parent.map: p =>
76
+ if p.t == Image && t == Location then
77
+ " \n " + (" " * level) + s """ <img src=" $value" alt=" ${p.t}: ${p.id} has $t: $value" class="imageLocation"> """
78
+ else " "
79
+ .getOrElse(" " )
80
+
81
+ if imgTag.nonEmpty then imgTag
82
+ else elemListItem(level, " attributeColor" )(t)(value)
83
+
73
84
case IntAttr (t, value) => elemListItem(level, " attributeColor" )(t)(value.toString)
85
+
74
86
case Undefined (t) => elemListItem(level, " attributeColor" )(t)(" ???" )
87
+
75
88
case Rel (e, t, sub) =>
76
- s """ $ind<li><span class="entityColor"> ${e.t}</span>: ${e.id}"""
77
- + s """ <span class="relationColor"> ${t.show}</span></li>\n """
78
- + (if sub.elems.nonEmpty then renderHtmlBody(sub, level + 1 ) else " " )
89
+ s """ $ind<li><span class="entityColor"> ${e.t}</span>: ${e.id}"""
90
+ + s """ <span class="relationColor"> ${t.show}</span></li>\n """
91
+ + (if sub.elems.nonEmpty then renderHtmlBody(sub, level + 1 , insertImagesWithLocation, Some (e)) else " " )
92
+
79
93
lines.mkString(s " $ind<ul> \n " ," \n " ,s " \n $ind</ul> " )
94
+ end renderHtmlBody
80
95
81
96
extension (m : Model )
82
- def toHtmlBody : String =
97
+ def toHtml : String = toHtml()
98
+ def toHtmlBody : String = toHtmlBody()
99
+
100
+ def toHtmlBody (
101
+ insertImagesWithLocation : Boolean = true ,
102
+ ): String =
83
103
if m.elems.isEmpty then " <ul><li>Empty Model</li></ul>"
84
- else renderHtmlBody(m, 0 )
104
+ else renderHtmlBody(m, 0 , insertImagesWithLocation, parent = None )
85
105
86
- def toHtml : String = toHtml()
87
106
88
- def toHtml (fallBackTitle : String = defaultTitle, style : String = defaultStyle): String =
107
+ def toHtml (
108
+ insertImagesWithLocation : Boolean = true ,
109
+ fallBackTitle : String = defaultTitle,
110
+ style : String = defaultStyle,
111
+ ): String =
89
112
s " ${preamble(m, fallBackTitle, style)}\n <body> \n ${m.toHtmlBody}\n </body> \n </html> \n "
90
113
91
114
end HtmlGen
0 commit comments