mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-29 09:05:30 +00:00
basic HTML transforms
This commit is contained in:
@@ -420,7 +420,7 @@
|
|||||||
{{- if not $piece.IsContinuation -}}
|
{{- if not $piece.IsContinuation -}}
|
||||||
{{- range $annotation := $piece.AnnotationNote.Annotations -}}
|
{{- range $annotation := $piece.AnnotationNote.Annotations -}}
|
||||||
<div class="italic text-sm mt-0.5 text-slate-600">
|
<div class="italic text-sm mt-0.5 text-slate-600">
|
||||||
{{ $annotation.Inner.InnerXML }}
|
{{ Safe $annotation.HTML }}
|
||||||
</div>
|
</div>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|||||||
@@ -34,6 +34,14 @@ type URL struct {
|
|||||||
Inner
|
Inner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HTML returns the HTML-transformed version of the URL text
|
||||||
|
func (u URL) HTML() string {
|
||||||
|
if u.Inner.InnerXML != "" {
|
||||||
|
return transformToHTML(u.Inner.InnerXML)
|
||||||
|
}
|
||||||
|
return u.Value.Chardata
|
||||||
|
}
|
||||||
|
|
||||||
type AnnotationNote struct {
|
type AnnotationNote struct {
|
||||||
Annotations []Annotation `xml:"anmerkung"`
|
Annotations []Annotation `xml:"anmerkung"`
|
||||||
Notes []Note `xml:"vermerk"`
|
Notes []Note `xml:"vermerk"`
|
||||||
@@ -57,18 +65,53 @@ func (an AnnotationNote) Readable() map[string]interface{} {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadableHTML returns HTML versions of annotations and notes
|
||||||
|
func (an AnnotationNote) ReadableHTML() map[string]interface{} {
|
||||||
|
ret := make(map[string]interface{})
|
||||||
|
annnotations := make([]string, len(an.Annotations))
|
||||||
|
for _, a := range an.Annotations {
|
||||||
|
annnotations = append(annnotations, a.HTML())
|
||||||
|
}
|
||||||
|
|
||||||
|
ret["AnnotationsHTML"] = annnotations
|
||||||
|
|
||||||
|
nots := make([]string, len(an.Notes))
|
||||||
|
for _, n := range an.Notes {
|
||||||
|
nots = append(nots, n.HTML())
|
||||||
|
}
|
||||||
|
|
||||||
|
ret["NotesHTML"] = nots
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
type Annotation struct {
|
type Annotation struct {
|
||||||
XMLName xml.Name `xml:"anmerkung"`
|
XMLName xml.Name `xml:"anmerkung"`
|
||||||
Value
|
Value
|
||||||
Inner
|
Inner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HTML returns the HTML-transformed version of the annotation
|
||||||
|
func (a Annotation) HTML() string {
|
||||||
|
if a.Inner.InnerXML != "" {
|
||||||
|
return transformToHTML(a.Inner.InnerXML)
|
||||||
|
}
|
||||||
|
return a.Value.Chardata
|
||||||
|
}
|
||||||
|
|
||||||
type Note struct {
|
type Note struct {
|
||||||
XMLName xml.Name `xml:"vermerk"`
|
XMLName xml.Name `xml:"vermerk"`
|
||||||
Value
|
Value
|
||||||
Inner
|
Inner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HTML returns the HTML-transformed version of the note
|
||||||
|
func (n Note) HTML() string {
|
||||||
|
if n.Inner.InnerXML != "" {
|
||||||
|
return transformToHTML(n.Inner.InnerXML)
|
||||||
|
}
|
||||||
|
return n.Value.Chardata
|
||||||
|
}
|
||||||
|
|
||||||
type Identifier struct {
|
type Identifier struct {
|
||||||
ID string `xml:"id,attr"`
|
ID string `xml:"id,attr"`
|
||||||
keys []string
|
keys []string
|
||||||
@@ -88,6 +131,14 @@ type Reference struct {
|
|||||||
Inner Inner
|
Inner Inner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HTML returns the HTML-transformed version of the reference
|
||||||
|
func (r Reference) HTML() string {
|
||||||
|
if r.Inner.InnerXML != "" {
|
||||||
|
return transformToHTML(r.Inner.InnerXML)
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func (r Reference) Readable(lib *Library) map[string]interface{} {
|
func (r Reference) Readable(lib *Library) map[string]interface{} {
|
||||||
data := make(map[string]interface{})
|
data := make(map[string]interface{})
|
||||||
if r.Category != "" {
|
if r.Category != "" {
|
||||||
@@ -98,6 +149,7 @@ func (r Reference) Readable(lib *Library) map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data["ReferenceComment"] = r.Inner.InnerXML
|
data["ReferenceComment"] = r.Inner.InnerXML
|
||||||
|
data["ReferenceCommentHTML"] = r.HTML()
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,3 +160,31 @@ type Value struct {
|
|||||||
type Inner struct {
|
type Inner struct {
|
||||||
InnerXML string `xml:",innerxml"`
|
InnerXML string `xml:",innerxml"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// transformToHTML converts XML content to HTML
|
||||||
|
func transformToHTML(xmlContent string) string {
|
||||||
|
if xmlContent == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simple string replacements for now
|
||||||
|
html := xmlContent
|
||||||
|
|
||||||
|
// Transform wwwlink tags to anchor tags
|
||||||
|
// This is a simple regex replacement - for production you might want more robust parsing
|
||||||
|
html = strings.ReplaceAll(html, `<wwwlink address="`, `<a href="`)
|
||||||
|
html = strings.ReplaceAll(html, `</wwwlink>`, `</a>`)
|
||||||
|
html = strings.ReplaceAll(html, `">`, `">`) // Keep the closing of the opening tag
|
||||||
|
|
||||||
|
// Transform title tags to em tags
|
||||||
|
html = strings.ReplaceAll(html, `<title>`, `<em>`)
|
||||||
|
html = strings.ReplaceAll(html, `</title>`, `</em>`)
|
||||||
|
|
||||||
|
// Remove year tags but keep content
|
||||||
|
html = strings.ReplaceAll(html, `<year>`, ``)
|
||||||
|
html = strings.ReplaceAll(html, `</year>`, ``)
|
||||||
|
|
||||||
|
return html
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,14 @@ type Citation struct {
|
|||||||
Inner
|
Inner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HTML returns the HTML-transformed version of the citation
|
||||||
|
func (c Citation) HTML() string {
|
||||||
|
if c.Inner.InnerXML != "" {
|
||||||
|
return transformToHTML(c.Inner.InnerXML)
|
||||||
|
}
|
||||||
|
return c.Value.Chardata
|
||||||
|
}
|
||||||
|
|
||||||
func (w Work) References() xmlprovider.ResolvingMap[Work] {
|
func (w Work) References() xmlprovider.ResolvingMap[Work] {
|
||||||
refs := make(xmlprovider.ResolvingMap[Work])
|
refs := make(xmlprovider.ResolvingMap[Work])
|
||||||
|
|
||||||
@@ -57,12 +65,18 @@ func (w Work) Readable(lib *Library) map[string]interface{} {
|
|||||||
"Title": w.Citation.Title,
|
"Title": w.Citation.Title,
|
||||||
"Year": w.Citation.Year,
|
"Year": w.Citation.Year,
|
||||||
"CitationTitle": w.Citation.Title,
|
"CitationTitle": w.Citation.Title,
|
||||||
|
"CitationHTML": w.Citation.HTML(),
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range w.AnnotationNote.Readable() {
|
for k, v := range w.AnnotationNote.Readable() {
|
||||||
ret[k] = v
|
ret[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add HTML versions
|
||||||
|
for k, v := range w.AnnotationNote.ReadableHTML() {
|
||||||
|
ret[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
agents := make([]map[string]interface{}, len(w.AgentRefs))
|
agents := make([]map[string]interface{}, len(w.AgentRefs))
|
||||||
for k, v := range w.AgentRefs {
|
for k, v := range w.AgentRefs {
|
||||||
agents[k] = v.Readable(lib)
|
agents[k] = v.Readable(lib)
|
||||||
|
|||||||
Reference in New Issue
Block a user