@@ -24,6 +24,7 @@ import Text.Blaze (ToMarkup (preEscapedToMarkup))
24
24
import Text.Blaze.Html.Renderer.Utf8 (renderHtml )
25
25
import Text.Cassius
26
26
import Text.Hamlet (Html , shamlet )
27
+ import Text.InterpolatedString.Perl6 (q )
27
28
28
29
import Nirum.Constructs (Construct (toCode ))
29
30
import Nirum.Constructs.Declaration (Documented (docsBlock ))
@@ -114,6 +115,7 @@ $doctype 5
114
115
<meta property="#{ogTag}" content="#{ogContent}">
115
116
<link rel="stylesheet" href="#{root}style.css">
116
117
<link rel="stylesheet" href="#{hljsCss}">
118
+ <script src="#{root}nirum.js"></script>
117
119
<script src="#{hljsJs}"></script>
118
120
<script>hljs.initHighlightingOnLoad();</script>
119
121
<body>
@@ -261,7 +263,7 @@ blockToHtml =
261
263
typeDecl :: BoundModule Docs -> Identifier -> TD. TypeDeclaration -> Html
262
264
typeDecl mod' ident
263
265
tc@ TD. TypeDeclaration { TD. type' = TD. Alias cname } = [shamlet |
264
- <h2>
266
+ <h2 id="#{toNormalizedText ident}" >
265
267
type <dfn><code>#{toNormalizedText ident}</code></dfn> = #
266
268
<code.type>#{typeExpression mod' cname}</code>
267
269
$maybe d <- docsBlock tc
@@ -270,7 +272,7 @@ typeDecl mod' ident
270
272
typeDecl mod' ident
271
273
tc@ TD. TypeDeclaration { TD. type' = TD. UnboxedType innerType } =
272
274
[shamlet |
273
- <h2>
275
+ <h2 id="#{toNormalizedText ident}" >
274
276
unboxed
275
277
<dfn><code>#{toNormalizedText ident}</code>
276
278
(<code>#{typeExpression mod' innerType}</code>)
@@ -279,7 +281,8 @@ typeDecl mod' ident
279
281
|]
280
282
typeDecl _ ident
281
283
tc@ TD. TypeDeclaration { TD. type' = TD. EnumType members } = [shamlet |
282
- <h2>enum <dfn><code>#{toNormalizedText ident}</code></dfn>
284
+ <h2 id="#{toNormalizedText ident}">
285
+ enum <dfn><code>#{toNormalizedText ident}</code></dfn>
283
286
$maybe d <- docsBlock tc
284
287
#{blockToHtml d}
285
288
<dl class="members">
@@ -292,7 +295,8 @@ typeDecl _ ident
292
295
|]
293
296
typeDecl mod' ident
294
297
tc@ TD. TypeDeclaration { TD. type' = TD. RecordType fields } = [shamlet |
295
- <h2>record <dfn><code>#{toNormalizedText ident}</code></dfn>
298
+ <h2 id="#{toNormalizedText ident}">
299
+ record <dfn><code>#{toNormalizedText ident}</code></dfn>
296
300
$maybe d <- docsBlock tc
297
301
#{blockToHtml d}
298
302
<dl.fields>
@@ -311,7 +315,8 @@ typeDecl mod' ident
311
315
}
312
316
} =
313
317
[shamlet |
314
- <h2>union <dfn><code>#{toNormalizedText ident}</code></dfn>
318
+ <h2 id="#{toNormalizedText ident}">
319
+ union <dfn><code>#{toNormalizedText ident}</code></dfn>
315
320
$maybe d <- docsBlock tc
316
321
#{blockToHtml d}
317
322
$forall (default_, tagDecl@(TD.Tag _ fields _)) <- tagList
@@ -340,12 +345,14 @@ typeDecl mod' ident
340
345
]
341
346
typeDecl _ ident
342
347
TD. TypeDeclaration { TD. type' = TD. PrimitiveType {} } = [shamlet |
343
- <h2>primitive <code>#{toNormalizedText ident}</code>
348
+ <h2 id="#{toNormalizedText ident}">
349
+ primitive <code>#{toNormalizedText ident}</code>
344
350
|]
345
351
typeDecl mod' ident
346
352
tc@ TD. ServiceDeclaration { TD. service = S. Service methods } =
347
353
[shamlet |
348
- <h2>service <dfn><code>#{toNormalizedText ident}</code></dfn>
354
+ <h2 id="#{toNormalizedText ident}">
355
+ service <dfn><code>#{toNormalizedText ident}</code></dfn>
349
356
$maybe d <- docsBlock tc
350
357
#{blockToHtml d}
351
358
$forall md@(S.Method _ ps ret err _) <- DES.toList methods
@@ -520,6 +527,11 @@ h1, h2, h3, h4, h5, h6, dt
520
527
font-weight: bold
521
528
code
522
529
font-weight: 400
530
+ h2 a.pilcrow
531
+ visibility: hidden
532
+ margin-left: 10px
533
+ h2:hover a.pilcrow
534
+ visibility: visible
523
535
a
524
536
text-decoration: none
525
537
a:link
@@ -610,10 +622,24 @@ footer
610
622
navWidth :: PixelSize
611
623
navWidth = PixelSize 300
612
624
625
+ javascript :: T. Text
626
+ javascript = [q |
627
+ window.addEventListener('load', function () {
628
+ document.querySelectorAll('h2[id]').forEach(function(node) {
629
+ var anchor = document.createElement("a");
630
+ anchor.className = "pilcrow";
631
+ anchor.text = "\xb6";
632
+ anchor.href = "#" + node.id;
633
+ node.appendChild(anchor);
634
+ });
635
+ });
636
+ |]
637
+
613
638
compilePackage' :: Package Docs -> Map FilePath (Either Error BS. ByteString )
614
639
compilePackage' pkg = unions
615
640
[ fromList
616
641
[ (" style.css" , Right $ encodeUtf8 css)
642
+ , (" nirum.js" , Right $ encodeUtf8 javascript)
617
643
, ( " index.html"
618
644
, Right $ toStrict $ renderHtml $ case readme of
619
645
Nothing -> contents pkg
0 commit comments