Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[scaladoc] fix: Only trim one newline when preprocessing the content of a markdown code snippet #21519

Merged
merged 1 commit into from
Sep 19, 2024

Conversation

KacperFKorban
Copy link
Member

fixes #21429

Comment on lines +33 to +98
val rootDocsPage: Option[Page] = staticSite match {
case None => None
case Some(siteContext) =>
val rootTemplate = siteContext.staticSiteRoot.rootTemplate

// Below code is for walking in order the tree and modifing its nodes basing on its neighbours

// We add dummy guards
val notHidden: Seq[Option[LoadedTemplate]] = None +: siteContext.allTemplates.filterNot(_.hidden).map(Some(_)) :+ None

// Let's gather the list of maps for each template with its in-order neighbours
val newSettings: List[Map[String, Object]] = notHidden.sliding(size = 3, step = 1).map {
case None :: None :: Nil =>
Map.empty
case prev :: mid :: next :: Nil =>
def link(sibling: Option[LoadedTemplate]): Option[String] =
def realPath(path: Path) = if Files.isDirectory(path) then Paths.get(path.toString, "index.html") else path
sibling.map { n =>
val realMidPath = realPath(mid.get.file.toPath)
val realSiblingPath = realPath(n.file.toPath)
realMidPath.relativize(realSiblingPath).toString.stripPrefix("../")
}
List(
for {
link <- link(prev)
p <- prev
} yield (
"previous" -> Map(
"title" -> p.templateFile.title.name,
"url" -> link
)
),
for {
link <- link(next)
n <- next
} yield (
"next" -> Map(
"title" -> n.templateFile.title.name,
"url" -> link
)
),
).flatten.toMap
}.toList

def updateSettings(templates: Seq[LoadedTemplate], additionalSettings: ListBuffer[Map[String, Object]]): List[LoadedTemplate] =
val updatedTemplates = List.newBuilder[LoadedTemplate]
for template <- templates do
val head: Map[String, Object] =
if template.hidden then Map.empty
else additionalSettings.remove(0)
val current: Map[String, Object] = template.templateFile.settings.getOrElse("page", Map.empty).asInstanceOf[Map[String, Object]]
val updatedTemplateFile = template.templateFile.copy(settings = template.templateFile.settings.updated("page", head ++ current))
updatedTemplates += template.copy(
templateFile = updatedTemplateFile,
children = updateSettings(template.children, additionalSettings)
)
updatedTemplates.result()

val newTemplates = updateSettings(Seq(rootTemplate), newSettings.to(ListBuffer))
val templatePages = newTemplates.map(templateToPage(_, siteContext))

val newRoot = newTemplates.head

Some(newRoot).filter(r => r.children.nonEmpty || r.templateFile.rawCode.nonEmpty)
.map(templateToPage(_, siteContext))
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only changed a wrong indentation and added braces here.

@KacperFKorban KacperFKorban marked this pull request as ready for review September 2, 2024 21:42
@hamzaremmal hamzaremmal merged commit a9fd5b8 into scala:main Sep 19, 2024
28 checks passed
@hamzaremmal hamzaremmal deleted the scaladoc/fix-i21429 branch September 19, 2024 12:54
@WojciechMazur WojciechMazur added this to the 3.6.0 milestone Oct 8, 2024
WojciechMazur added a commit that referenced this pull request Dec 4, 2024
…e content of a markdown code snippet" to LTS (#22134)

Backports #21519 to the 3.3.5.

PR submitted by the release tooling.
[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scaladoc removes indentation of first line, making code incorrect
4 participants