Skip to content

Commit

Permalink
Add markdown helper function.
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonkearns committed Jun 23, 2021
1 parent ba436fb commit 0e53560
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/docs/src/MarkdownCodec.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0e53560

Please sign in to comment.