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

Upgrade to laika 1.0.0 #140

Merged
merged 6 commits into from
Dec 2, 2023
Merged

Upgrade to laika 1.0.0 #140

merged 6 commits into from
Dec 2, 2023

Conversation

valencik
Copy link
Contributor

@valencik valencik commented Nov 5, 2023

This PR upgrades to laika 1.0.0

The two important pieces are:

  • Plaintext which implements RenderFormat[Formatter]
  • IndexFormat which implements the TwoPhaseRenderFormat[Formatter, BinaryPostProcessor.Builder]

Plaintext runs on every document.
IndexFormat renders a tree of documents that have been formatted with Plaintext

This follows the approach outlined in #102 (comment)

The DocsDirectory file is upgraded, but this really is not the intended way to use things going forward.

@valencik valencik self-assigned this Nov 5, 2023
@valencik valencik mentioned this pull request Nov 7, 2023

val formatterFactory: RenderContext[TextFormatter] => TextFormatter = PlaintextFormatter
val formatterFactory: Formatter.Context[Formatter] => Formatter =
Copy link
Contributor

Choose a reason for hiding this comment

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

Very minor thing: to reduce a bit if boilerplate you could also simply inline this like here:
https://github.com/typelevel/Laika/blob/main/core/shared/src/main/scala/laika/format/AST.scala#L41

@jenshalm
Copy link
Contributor

jenshalm commented Nov 8, 2023

Just quickly want to confirm that the post processor skeleton looks okay in my eyes.

@valencik
Copy link
Contributor Author

To test this I published the laikaIO project as a sbt plugin (adding sbtPlugin := true to it's settings and running laikaIOJVM/publishLocal on scala 2.12.18) and then created a custom task in the docs project like this:

Some preamble in the build.sbt:

import cats.effect.unsafe.implicits.global
import pink.cozydev.protosearch.analysis.DocsDirectory
import laika.io.model.FilePath

lazy val indexTask = taskKey[String]("Generates the index output")

And then the task:

    indexTask := {
      val userConfig = laikaConfig.value
      val targetDir = (laikaAST / target).value
      val parser = laika.sbt.Settings.parser.value
      val tree = parser.use(_.fromInput(laikaInputs.value.delegate).parse).unsafeRunSync()
      DocsDirectory.plaintextRenderer.use(
        _.from(tree)
         .toDirectory(FilePath.fromJavaFile(targetDir))(userConfig.encoding)
         .render
      ).unsafeRunSync()
      println(s"rendered to ${targetDir}")
      root.toString()
    }

This rendered the Plaintext formatted docs to /home/andrew/src/github.com/cozydev/protosearch/site/target/docs/ast and they looked as expected (which is actually a rather silly format currently, but improving that is not the goal here).

So I am happy to say that I think we are on a good path here.
Up next, in the immediate future, I'd like to turn this task into a quick sbt plugin. With the goal being that it will be much easier to use in another project. Specifically I'd like to be able to modify the http4s build with just a new plugin dependency and maybe one or two lines, and then have it generate plaintext files like above.

And then I can get back to actually making the plaintext formatting reasonable, and the IndexFormat actually building an index.

@valencik valencik marked this pull request as ready for review November 22, 2023 13:15
@valencik
Copy link
Contributor Author

Here's the commit of the hacked build testing this out:
c84d141

@valencik
Copy link
Contributor Author

It turns out I didn't need to publish laikaIO as a sbt plugin, we can use it as a regular dependency as in
https://github.com/cozydev-pink/protosearch/compare/laika-v1...laika-v1-snapshot?expand=1

Thank you @armanbilge suggesting this :)

Co-authored-by: Sam Pillsworth <sam@blerf.ca>
@valencik
Copy link
Contributor Author

valencik commented Dec 2, 2023

Merging this and continuing the work in #148

@valencik valencik merged commit e19f306 into main Dec 2, 2023
19 checks passed
@valencik valencik deleted the laika-v1 branch December 2, 2023 14:31
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.

3 participants