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

Do not add -src suffix to links in HTML when running juvix html #1429

Merged
merged 1 commit into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Juvix/Documentation/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ goTopModule m = do
srcHtml :: forall s. Members '[Reader HtmlOptions, Embed IO] s => Sem s Html
srcHtml = do
utc <- Prelude.embed getCurrentTime
return (genModuleHtml defaultOptions True utc Ayu m)
return (genModuleHtml defaultOptions HtmlSrc True utc Ayu m)

docHtml :: forall s. Members '[Reader HtmlOptions, Reader EntryPoint] s => Sem s Html
docHtml = do
Expand Down
17 changes: 10 additions & 7 deletions src/Juvix/Syntax/Concrete/Scoped/Pretty/Html.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ data Theme
data HtmlKind
= HtmlDoc
| HtmlSrc
| HtmlOnly

newtype HtmlOptions = HtmlOptions
{ _htmlOptionsKind :: HtmlKind
Expand All @@ -40,6 +41,7 @@ kindSuffix :: HtmlKind -> String
kindSuffix = \case
HtmlDoc -> ""
HtmlSrc -> "-src"
HtmlOnly -> ""

genHtml :: Options -> Bool -> Theme -> FilePath -> Bool -> Module 'Scoped 'ModuleTop -> IO ()
genHtml opts recursive theme outputDir printMetadata entry = do
Expand Down Expand Up @@ -70,12 +72,12 @@ genHtml opts recursive theme outputDir printMetadata entry = do
createDirectoryIfMissing True (takeDirectory htmlFile)
putStrLn $ "Writing " <> pack htmlFile
utc <- getCurrentTime
Text.writeFile htmlFile (genModule opts printMetadata utc theme m)
Text.writeFile htmlFile (genModule opts HtmlOnly printMetadata utc theme m)
where
htmlFile = topModulePathToDottedPath (m ^. modulePath . S.nameConcrete) <.> ".html"

genModuleHtml :: Options -> Bool -> UTCTime -> Theme -> Module 'Scoped 'ModuleTop -> Html
genModuleHtml opts printMetadata utc theme m =
genModuleHtml :: Options -> HtmlKind -> Bool -> UTCTime -> Theme -> Module 'Scoped 'ModuleTop -> Html
genModuleHtml opts htmlKind printMetadata utc theme m =
docTypeHtml ! Attr.xmlns "http://www.w3.org/1999/xhtml" $
mhead
<> mbody
Expand All @@ -89,7 +91,7 @@ genModuleHtml opts printMetadata utc theme m =
htmlOpts :: HtmlOptions
htmlOpts =
HtmlOptions
{ _htmlOptionsKind = HtmlSrc
{ _htmlOptionsKind = htmlKind
}

pp :: PrettyCode a => a -> Html
Expand Down Expand Up @@ -130,11 +132,11 @@ genModuleHtml opts printMetadata utc theme m =

formattedTime = formatTime defaultTimeLocale "%Y-%m-%d %-H:%M %Z" utc

genModule :: Options -> Bool -> UTCTime -> Theme -> Module 'Scoped 'ModuleTop -> Text
genModule opts printMetadata utc theme =
genModule :: Options -> HtmlKind -> Bool -> UTCTime -> Theme -> Module 'Scoped 'ModuleTop -> Text
genModule opts htmlKind printMetadata utc theme =
toStrict
. Html.renderHtml
. genModuleHtml opts printMetadata utc theme
. genModuleHtml opts htmlKind printMetadata utc theme

docStream' :: PrettyCode a => Options -> a -> SimpleDocStream Ann
docStream' opts m = layoutPretty defaultLayoutOptions (runPrettyCode opts m)
Expand Down Expand Up @@ -179,6 +181,7 @@ putTag ann x = case ann of
asks (^. htmlOptionsKind) <&> \case
HtmlDoc -> Html.span ! Attr.class_ "ju-define"
HtmlSrc -> id
HtmlOnly -> id

tagDef :: TopModulePath -> S.NameId -> Sem r Html
tagDef tmp nid = do
Expand Down