Skip to content

Commit 2ad1104

Browse files
committed
feat: options to remove header and toc for html/mdd
1 parent f938530 commit 2ad1104

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

cmd/root.go

+8
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ func init() {
8787
rootCmd.Flags().BoolVar(&config.OutputOptions.CSVOptions.SkipDownHosts, "csv-skip-down-hosts", true, "--csv-skip-down-hosts=false, would print all hosts that are offline in CSV output")
8888
rootCmd.Flags().BoolVar(&config.OutputOptions.ExcelOptions.SkipDownHosts, "excel-skip-down-hosts", true, "--excel-skip-down-hosts=false, would print all hosts that are offline in Excel file")
8989

90+
// Skip header information (overall meta information from the scan)
91+
rootCmd.Flags().BoolVar(&config.OutputOptions.HTMLOptions.SkipHeader, "html-skip-header", false, "--html-skip-header, skips header in HTML output")
92+
rootCmd.Flags().BoolVar(&config.OutputOptions.MarkdownOptions.SkipHeader, "md-skip-header", false, "--md-skip-header, skips header in Markdown output")
93+
94+
// Skip table of contents (TOC) information
95+
rootCmd.Flags().BoolVar(&config.OutputOptions.HTMLOptions.SkipTOC, "html-skip-toc", false, "--html-skip-toc, skips table of contents in HTML output")
96+
rootCmd.Flags().BoolVar(&config.OutputOptions.MarkdownOptions.SkipTOC, "md-skip-toc", false, "--md-skip-toc, skips table of contents in Markdown output")
97+
9098
// Skip summary (overall meta information from the scan)
9199
rootCmd.Flags().BoolVar(&config.OutputOptions.HTMLOptions.SkipSummary, "html-skip-summary", false, "--html-skip-summary=true, skips summary in HTML output")
92100
rootCmd.Flags().BoolVar(&config.OutputOptions.MarkdownOptions.SkipSummary, "md-skip-summary", false, "--md-skip-summary=true, skips summary in Markdown output")

formatter/output_options.go

+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ type OutputOptions struct {
1313

1414
// HTMLOutputOptions stores options related only to HTML conversion/formatting
1515
type HTMLOutputOptions struct {
16+
// SkipHeader skips the header of the HTML output
17+
SkipHeader bool
18+
// SkipTOC skips the table of contents in the HTML output
19+
SkipTOC bool
1620
// SkipDownHosts skips hosts that are down (including TOC)
1721
SkipDownHosts bool
1822
// SkipSummary skips general summary for HTML
@@ -31,6 +35,10 @@ type HTMLOutputOptions struct {
3135

3236
// MarkdownOutputOptions stores options related only to Markdown conversion/formatting
3337
type MarkdownOutputOptions struct {
38+
// SkipHeader skips the header
39+
SkipHeader bool
40+
// SkipTOC skips the table of contents
41+
SkipTOC bool
3442
// SkipDownHosts skips hosts that are down (including TOC)
3543
SkipDownHosts bool
3644
// SkipSummary skips general summary for Markdown

formatter/resources/templates/markdown.tmpl

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
{{- if not .OutputOptions.MarkdownOptions.SkipHeader -}}
12
NMAP Scan Result: {{ .NMAPRun.StartStr }}
23
==========================================
3-
{{ $skipDownHosts := .OutputOptions.MarkdownOptions.SkipDownHosts }}
4-
{{ $skipSummary := .OutputOptions.MarkdownOptions.SkipSummary }}
5-
{{ $skipPortScripts := .OutputOptions.MarkdownOptions.SkipPortScripts }}
6-
{{ $skipMetrics := .OutputOptions.MarkdownOptions.SkipMetrics }}
7-
{{ $skipTraceroute := .OutputOptions.MarkdownOptions.SkipTraceroute }}
8-
4+
{{ end }}
5+
{{- $skipTOC := .OutputOptions.MarkdownOptions.SkipTOC -}}
6+
{{- $skipDownHosts := .OutputOptions.MarkdownOptions.SkipDownHosts -}}
7+
{{- $skipSummary := .OutputOptions.MarkdownOptions.SkipSummary -}}
8+
{{- $skipPortScripts := .OutputOptions.MarkdownOptions.SkipPortScripts -}}
9+
{{- $skipMetrics := .OutputOptions.MarkdownOptions.SkipMetrics -}}
10+
{{- $skipTraceroute := .OutputOptions.MarkdownOptions.SkipTraceroute -}}
11+
{{ if not $skipTOC -}}
912
## TOC
1013

1114
{{ if not $skipSummary }}
@@ -16,6 +19,7 @@ NMAP Scan Result: {{ .NMAPRun.StartStr }}
1619
* [{{ md_title . }}](#{{ md_link . }})
1720
{{- end -}}{{/* .ShouldNotSkipHost $skipDownHosts */}}
1821
{{- end -}}{{/* range .Host */}}
22+
{{- end -}}{{/* if not $skipTOC */}}
1923

2024
{{- if not $skipSummary }}
2125
----

formatter/resources/templates/simple-html.gohtml

+6
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,18 @@
104104
</style>
105105
</head>
106106
<body>
107+
{{ $skipTOC := .OutputOptions.HTMLOptions.SkipTOC }}
108+
{{ $skipHeader := .OutputOptions.HTMLOptions.SkipHeader }}
107109
{{ $skipDownHosts := .OutputOptions.HTMLOptions.SkipDownHosts }}
108110
{{ $skipSummary := .OutputOptions.HTMLOptions.SkipSummary }}
109111
{{ $skipTraceroute := .OutputOptions.HTMLOptions.SkipTraceroute }}
110112
{{ $skipMetrics := .OutputOptions.HTMLOptions.SkipMetrics }}
111113
{{ $skipPortScripts := .OutputOptions.HTMLOptions.SkipPortScripts }}
114+
{{- if not $skipHeader }}
112115
<h1>NMAP Scan Result: {{ .NMAPRun.StartStr }}</h1>
113116
<hr>
117+
{{- end }}{{/* if not $skipHeader */}}
118+
{{ if not $skipTOC }}
114119
<div id="toc">
115120
<h2>Table of contents:</h2>
116121
<ul>
@@ -123,6 +128,7 @@
123128
</ul>
124129
<hr>
125130
</div>
131+
{{ end }}{{/* if not $skipTOC */}}
126132
{{ if not $skipSummary }}
127133
<a id="scan-summary"></a>
128134
<h2>Scan Summary:</h2>

0 commit comments

Comments
 (0)