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

damldocs: Backend for rendering docs to multiple pages. #2259

Merged
6 commits merged into from
Jul 23, 2019

Conversation

ghost
Copy link

@ghost ghost commented Jul 23, 2019

This PR provides the backend necessary to render docs to a folder, one page per module. It replaces the existing "one page per module" solution that already existed for rendering to HTML, which could not handle anchors across pages.

This PR also includes a couple of fixes for HTML output: anchor tags were not being rendered because of the CMark default options (which would strip out any raw HTML), so I changed that, and the default HTML template resulted in misinterpreted unicode since it didn't have a <meta charset="utf-8"> tag.

I also added a Bazel target for generating standard library html docs in a tarball.

Future work / not done in this PR:

  • Hooking up the RendererOptions to the command line options for damldocs. Right now you can only render HTML across multiple files and everything else renders to a single file, which is the same as before.

  • Golden tests for multi-file rendering.

@ghost ghost requested review from cocreature, hurryabit and jberthold-da July 23, 2019 09:27
@ghost ghost force-pushed the damldocs-linked-project branch from b37eb60 to cb39474 Compare July 23, 2019 09:52
Copy link
Contributor

@cocreature cocreature left a comment

Choose a reason for hiding this comment

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

Nice, thank you!

Hoogle -> const (renderLine "") -- not implemented (yet?)
Rst -> renderSimpleRst
Markdown -> renderSimpleMD
Html -> renderSimpleMD
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth adding a comment that the conversion to Html is done in postProcessing. I first thought this was a typo 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this can be made clearer in code by something like

let (renderModule, postProcessing) = case ro_format of
      Markdown -> (renderSimpleMD, id)
      Html -> (renderSimpleMD, GFM.commonmarkToHtml [GFM.optUnsafe] [GFM.extTable])
      ...

Copy link
Author

Choose a reason for hiding this comment

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

Oh, that is more intuitive :-)

-> T.Text -- ^ page body
-> T.Text
renderTemplate template pageTitle pageBody
= T.replace "__BODY__" pageBody
Copy link
Contributor

Choose a reason for hiding this comment

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

If this starts becoming more complex we might want to switch to some standard templating library, e.g., mustache. For now this is totally fine.

Copy link
Author

Choose a reason for hiding this comment

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

Agreed :-)

case lookupAnchor env anchor of
Nothing -> escapeMd $ unTypename n
Just anchorLoc -> T.concat
[ "["
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add braces and parens helpers?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or a link helper.

@@ -23,38 +47,71 @@ newtype RenderEnv = RenderEnv (Set.Set Anchor)
-- Another possibly reason is that the anchor refers to a definition in another
-- package (and at the moment it's not possible to link accross packages).
renderAnchorAvailable :: RenderEnv -> Anchor -> Bool
renderAnchorAvailable (RenderEnv anchors) anchor = Set.member anchor anchors
renderAnchorAvailable RenderEnv{..} anchor = isJust (lookupAnchor anchor)
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like we aren’t using this anymore?

Copy link
Author

Choose a reason for hiding this comment

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

Right! Thanks!

Copy link
Contributor

@hurryabit hurryabit left a comment

Choose a reason for hiding this comment

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

Nice. Thanks you very much.

ro_format = Html
ro_title = Nothing
ro_template = Nothing
renderDocs RenderOptions{..} docData
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not the biggest fan of using record wild cards to construct value when the proper record syntax would be good enough. I prefer something more explicit like

let opts = RenderOptions
      { ro_mode = RenderToFolder output
      ; ...
      }

Copy link
Author

Choose a reason for hiding this comment

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

👍 that looks good!

Hoogle -> const (renderLine "") -- not implemented (yet?)
Rst -> renderSimpleRst
Markdown -> renderSimpleMD
Html -> renderSimpleMD
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this can be made clearer in code by something like

let (renderModule, postProcessing) = case ro_format of
      Markdown -> (renderSimpleMD, id)
      Html -> (renderSimpleMD, GFM.commonmarkToHtml [GFM.optUnsafe] [GFM.extTable])
      ...

case lookupAnchor env anchor of
Nothing -> escapeMd $ unTypename n
Just anchorLoc -> T.concat
[ "["
Copy link
Contributor

Choose a reason for hiding this comment

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

Or a link helper.

-- rendered differently from an anchor that is external. Thus we can
-- handle every case correctly.
data AnchorLocation
= SamePage -- ^ anchor is in same file
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
= SamePage -- ^ anchor is in same file
= SameFile -- ^ anchor is in same file

@ghost ghost merged commit d0dd201 into master Jul 23, 2019
@ghost ghost deleted the damldocs-linked-project branch July 24, 2019 10:23
This pull request was closed.
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.

2 participants