Skip to content

Commit 4d655fe

Browse files
committed
#81: Option to enable floating table of contents
1 parent 990b5c3 commit 4d655fe

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ func init() {
101101

102102
rootCmd.Flags().BoolVar(&config.OutputOptions.HTMLOptions.DarkMode, "html-dark-mode", true, "--html-dark-mode=false, sets HTML output in dark colours")
103103

104+
rootCmd.Flags().BoolVar(&config.OutputOptions.HTMLOptions.FloatingContentsTable, "html-toc-float", false, "--html-toc-float=true, Table of contents floats along with the scroll")
105+
104106
// Pretty-print json
105107
rootCmd.Flags().BoolVar(&config.OutputOptions.JSONOptions.PrettyPrint, "json-pretty", true, "--json-pretty=false (pretty prints JSON output)")
106108

formatter/output_options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ type HTMLOutputOptions struct {
2121
SkipPortScripts bool
2222
// DarkMode sets a style to be mostly in dark colours, if false, light colours would be used
2323
DarkMode bool
24+
// FloatingContentsTable is an option to make contents table float on the side of the page
25+
FloatingContentsTable bool
2426
}
2527

2628
type MarkdownOutputOptions struct {

formatter/resources/templates/simple-html.gohtml

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4+
{{ $ftColor := "#121212" }}
5+
{{ $bgColor := "#eee" }}
6+
{{ if .OutputOptions.HTMLOptions.DarkMode }}
7+
{{ $ftColor = "#eee" }}
8+
{{ $bgColor = "#121212" }}
9+
{{ end }}
410
<title>NMAP Scan result: {{ .NMAPRun.StartStr }}</title>
511
<meta charset="utf-8" />
612
<style>
713
body {
8-
{{ if .OutputOptions.HTMLOptions.DarkMode }}
9-
color: #eee;
10-
background-color: #121212;
11-
{{ else }}
12-
color: #121212;
13-
background-color: #eee;
14-
{{ end }}
14+
color: {{ $ftColor }};
15+
background-color: {{ $bgColor }};
1516
font-family: -apple-system,Helvetica,"Segoe UI Symbol";
1617
}
18+
{{ if .OutputOptions.HTMLOptions.FloatingContentsTable }}
19+
#toc {
20+
position: fixed;
21+
top: 20px;
22+
right: 0;
23+
margin-right: 5px;
24+
z-index: 1000;
25+
max-height: 780px;
26+
max-width: 250px;
27+
overflow: auto;
28+
background-color: {{ $bgColor }};
29+
}
30+
{{ end }}
1731
#summary-table {
1832
table-layout: fixed;
1933
width: 640px;
@@ -36,6 +50,9 @@
3650
.data-table > tbody > tr > td {
3751
border-bottom: 1px solid #404040;
3852
}
53+
.data-table > tbody > tr > td > pre {
54+
white-space: pre-wrap;
55+
}
3956
.data-table > tbody > tr > td > ul {
4057
padding-left: 0;
4158
}
@@ -89,16 +106,18 @@
89106
{{ $skipPortScripts := .OutputOptions.HTMLOptions.SkipPortScripts }}
90107
<h1>NMAP Scan Result: {{ .NMAPRun.StartStr }}</h1>
91108
<hr />
92-
<h2>TOC:</h2>
93-
<ul>
94-
{{ if not $skipSummary }}<li><a href="#scan-summary">Scan Summary</a></li>{{ end }}
95-
{{ range .NMAPRun.Host }}
96-
{{ if or ($displayDownHosts) (eq .Status.State "up") }}
97-
<li><a href="#{{ .HostAddress.Address }}">{{ .HostAddress.Address }}{{ range .HostNames.HostName }} / {{ .Name }}{{ end }}</a> ({{ .Status.State }})</li>
98-
{{ end }}{{/* if or ($displayDownHosts) (eq .Status.State "up") */}}
99-
{{ end }}{{/* range .Host */}}
100-
</ul>
101-
<hr />
109+
<div id="toc">
110+
<h2>Table of contents:</h2>
111+
<ul>
112+
{{ if not $skipSummary }}<li><a href="#scan-summary">Scan Summary</a></li>{{ end }}
113+
{{ range .NMAPRun.Host }}
114+
{{ if or ($displayDownHosts) (eq .Status.State "up") }}
115+
<li><a href="#{{ .HostAddress.Address }}">{{ .HostAddress.Address }}{{ range .HostNames.HostName }} / {{ .Name }}{{ end }}</a> ({{ .Status.State }})</li>
116+
{{ end }}{{/* if or ($displayDownHosts) (eq .Status.State "up") */}}
117+
{{ end }}{{/* range .Host */}}
118+
</ul>
119+
<hr />
120+
</div>
102121
{{ if not $skipSummary }}
103122
<a name="scan-summary"></a>
104123
<h2>Scan Summary:</h2>

0 commit comments

Comments
 (0)