Skip to content

Commit 90ac628

Browse files
committed
add a separate gallery caption for dcr txt cleaning
The GalleryCaptionCleaner used by twirl template is adding a class that is not needed for dcr, therefore, a separate cleaner is added to handle the dcr case.
1 parent 4f80533 commit 90ac628

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

common/app/model/dotcomrendering/pageElements/TextCleaner.scala

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import conf.Configuration.{affiliateLinks => affiliateLinksConfig}
55
import model.{Tag, Tags}
66
import org.jsoup.Jsoup
77
import org.jsoup.nodes.Document
8-
import views.support.{AffiliateLinksCleaner, GalleryCaptionCleaner, HtmlCleaner}
8+
import views.support.{AffiliateLinksCleaner, HtmlCleaner}
99

1010
import scala.jdk.CollectionConverters._
1111
import scala.util.matching.Regex
@@ -131,6 +131,27 @@ object TagLinker {
131131
}
132132
}
133133

134+
object GalleryCaptionCleaner extends HtmlCleaner {
135+
override def clean(galleryCaption: Document): Document = {
136+
// There is an inconsistent number of <br> tags in gallery captions.
137+
// To create some consistency, re will remove them all.
138+
galleryCaption.getElementsByTag("br").remove()
139+
140+
val firstStrong = Option(galleryCaption.getElementsByTag("strong").first())
141+
val captionTitle = galleryCaption.createElement("h2")
142+
val captionTitleText = firstStrong.map(_.html()).getOrElse("")
143+
144+
// <strong> is removed in place of having a <h2> element
145+
firstStrong.foreach(_.remove())
146+
147+
captionTitle.html(captionTitleText)
148+
149+
galleryCaption.body.prependChild(captionTitle)
150+
151+
galleryCaption
152+
}
153+
}
154+
134155
case class GalleryAffiliateLinksCleaner(
135156
pageUrl: String,
136157
shouldAddAffiliateLinks: Boolean,

0 commit comments

Comments
 (0)