From 0e5356058a4a9ea91a939e59ce928f462bddf7c5 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Tue, 22 Jun 2021 22:14:48 -0700 Subject: [PATCH] Add markdown helper function. --- examples/docs/src/MarkdownCodec.elm | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/examples/docs/src/MarkdownCodec.elm b/examples/docs/src/MarkdownCodec.elm index 97ef1fa4..6bc7db6b 100644 --- a/examples/docs/src/MarkdownCodec.elm +++ b/examples/docs/src/MarkdownCodec.elm @@ -42,6 +42,39 @@ withFrontmatter constructor frontmatterDecoder renderer filePath = ) +withoutFrontmatter : + (frontmatter -> List view -> value) + -> Decoder frontmatter + -> Markdown.Renderer.Renderer view + -> String + -> DataSource.DataSource value +withoutFrontmatter constructor frontmatterDecoder renderer filePath = + DataSource.map2 constructor + (StaticFile.onlyFrontmatter + frontmatterDecoder + filePath + ) + ((StaticFile.bodyWithoutFrontmatter + filePath + |> DataSource.andThen + (\rawBody -> + rawBody + |> Markdown.Parser.parse + |> Result.mapError (\_ -> "Couldn't parse markdown.") + |> DataSource.fromResult + ) + ) + |> DataSource.distillSerializeCodec ("markdown-blocks-" ++ filePath) + (S.list codec) + |> DataSource.andThen + (\blocks -> + blocks + |> Markdown.Renderer.render renderer + |> DataSource.fromResult + ) + ) + + codec : S.Codec Never Block codec = S.customType