Skip to content

Commit d6f78eb

Browse files
committed
feat: add table of contents to generated changelog
1 parent dfd7d8d commit d6f78eb

4 files changed

Lines changed: 93 additions & 77 deletions

File tree

mitreattack/diffStix/changelog_helper.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,11 @@ def get_markdown_string(self) -> str:
12361236
logger.info("Generating markdown output")
12371237
content = ""
12381238

1239+
# Add contributors if requested by argument
1240+
if self.include_contributors:
1241+
content += self.get_contributor_section()
1242+
content += "\n"
1243+
12391244
# Add statistics section for the new version
12401245
logger.info("Generating statistics section")
12411246
stats_section = self.get_statistics_section(datastore_version="new")
@@ -1245,6 +1250,9 @@ def get_markdown_string(self) -> str:
12451250
key_content = self.get_md_key()
12461251
content += f"{key_content}\n"
12471252

1253+
content += "## Table of Contents\n\n"
1254+
content += "[TOC]\n\n"
1255+
12481256
for object_type in self.types:
12491257
domains = ""
12501258

@@ -1279,10 +1287,6 @@ def get_markdown_string(self) -> str:
12791287
if domains != "":
12801288
content += f"## {self.attack_type_to_title[object_type]}\n\n{domains}"
12811289

1282-
# Add contributors if requested by argument
1283-
if self.include_contributors:
1284-
content += self.get_contributor_section()
1285-
12861290
return content
12871291

12881292
def get_layers_dict(self):
@@ -1782,7 +1786,7 @@ def markdown_to_html(outfile: str, content: str, diffStix: DiffStix):
17821786
html_string = """<div style='max-width: 55em;margin: auto;margin-top:20px;font-family: "Roboto", sans-serif;'>"""
17831787
html_string += "<meta charset='utf-8'>"
17841788
html_string += header
1785-
html_string += markdown.markdown(content)
1789+
html_string += markdown.markdown(content, extensions=['toc'])
17861790
html_string += "</div>"
17871791

17881792
with open(outfile, "w", encoding="utf-8") as outputfile:

tests/changelog/core/test_missing_functions.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ def test_markdown_to_html_real_conversion(self, lightweight_diffstix, tmp_path):
107107

108108
# Verify markdown was converted to HTML
109109
if "# " in markdown_content:
110-
assert "<h1>" in html_content or "<h2>" in html_content # Headers should be converted
110+
# when the python markdown Table of Contents plugin is enabled, it changes the <h1> and <h2> tags
111+
# to include id attributes and maybe a style attribute (at least to <h1>) so this assert statement
112+
# looks a little funny, but is good enough
113+
# https://python-markdown.github.io/extensions/toc/
114+
assert "<h1" in html_content or "<h2" in html_content # Headers should be converted
111115

112116
def test_layers_dict_to_files_real_file_writing(self, mock_layers_dict, tmp_path):
113117
"""Test real layer files generation."""

tests/changelog/formatting/test_html_output.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ def test_markdown_to_html_basic(self, tmp_path, lightweight_diffstix):
2323
assert outfile.exists()
2424
html_content = outfile.read_text(encoding="utf-8")
2525
assert f"ATT&CK Changes Between v{old_version} and v{new_version}" in html_content
26-
assert "<h1>Test Header</h1>" in html_content
2726
assert "<strong>bold</strong>" in html_content
2827
assert "charset='utf-8'" in html_content
28+
# it might be nice to add this back in, but when using the python markdown TOC extension,
29+
# it modifies the <h1> and <h2> tags, giving them additional attributes, like id (and maybe style?)
30+
# https://python-markdown.github.io/extensions/toc/
31+
# assert "<h1>Test Header</h1>" in html_content
2932

3033
def test_write_detailed_html_basic(
3134
self, tmp_path, lightweight_diffstix, sample_deepdiff_data, minimal_stix_bundles

tests/resources/changelog-v16.1_to_v17.0/changelog.md

Lines changed: 75 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,74 @@
1+
## Contributors to this release
2+
3+
* Aaron Sullivan aka ZerkerEOD
4+
* Adam Lichters
5+
* Alden Schmidt
6+
* Ale Houspanossian
7+
* Alexey Kleymenov
8+
* Alon Klayman, Hunters Security
9+
* Amnon Kushnir, Sygnia
10+
* Ben Smith, @cyberg3cko
11+
* Caio Silva
12+
* Cian Heasley
13+
* Cristian Souza - Kaspersky GERT
14+
* Cristóbal Martínez Martín
15+
* David Hughes, BT Security
16+
* Dhiraj Mishra (@RandomDhiraj)
17+
* Dmitry Bestuzhev
18+
* Dvir Sasson, Reco
19+
* Eliraz Levi, Hunters Security
20+
* Fabian Kammel
21+
* Fernando Bacchin
22+
* Flavio Costa, Cisco
23+
* Frank Angiolelli
24+
* Gabriel Currie
25+
* Gerardo Santos
26+
* Harikrishnan Muthu, Cyble
27+
* Hiroki Nagahama, NEC Corporation
28+
* Inna Danilevich, U.S. Bank
29+
* Jaesang Oh, KC7 Foundation
30+
* Janantha Marasinghe
31+
* Jennifer Kim Roman
32+
* Jiraput Thamsongkrah
33+
* Joas Antonio dos Santos, @C0d3Cr4zy
34+
* Joe Gumke, U.S. Bank
35+
* Jun Hirata, NEC Corporation
36+
* Kaung Zaw Hein
37+
* Kevin Ward
38+
* Kori Yoshihiro, NEC Corporation
39+
* Kyaw Pyiyt Htet, @KyawPyiytHtet
40+
* Liran Ravich, CardinalOps
41+
* Lê Phương Nam, Group-IB
42+
* Manikantan Srinivasan, NEC Corporation India
43+
* Matt Anderson, @‌nosecurething, Huntress
44+
* Matt Brenton, Zurich Global Information Security
45+
* Matt Brenton, Zurich Insurance Group
46+
* Menachem Goldstein
47+
* Michael Davis @ ServiceNow Threat Intelligence
48+
* MyungUk Han, ASEC
49+
* Natthawut Saexu
50+
* Nikita Rostovcev, Group-IB
51+
* Oren Biderman, Sygnia
52+
* Peter Oakes
53+
* Pooja Natarajan, NEC Corporation India
54+
* Raghvendra Mishra
55+
* ReliaQuest
56+
* RoseSecurity
57+
* Rouven Bissinger (SySS GmbH)
58+
* Ruben Groenewoud (@RFGroenewoud)
59+
* Ryan Perez
60+
* Sareena Karapoola, NEC Corporation India
61+
* seungyoul.yoo@ahnlab.com
62+
* Sharmine Low, Group-IB
63+
* Shun Miyazaki, NEC Corporation
64+
* Shwetank Murarka
65+
* Sittikorn Sangrattanapitak
66+
* Suraj Khetani (@r00treaver)
67+
* Vicky Ray, RayvenX
68+
* Vijay Lalwani
69+
* Wietze Beukema @Wietze
70+
* Yoshihiro Kori, NEC Corporation
71+
172
## Statistics
273

374
This version of ATT&CK contains 877 Software, 170 Groups, and 50 Campaigns.
@@ -19,6 +90,10 @@ Broken out by domain:
1990
* Object deprecations: ATT&CK objects which are deprecated and no longer in use, and not replaced.
2091
* Object deletions: ATT&CK objects which are no longer found in the STIX data.
2192

93+
## Table of Contents
94+
95+
[TOC]
96+
2297
## Techniques
2398

2499
### Enterprise
@@ -2226,73 +2301,3 @@ Broken out by domain:
22262301
* [Service Metadata](/datasources/DS0019/#Service%20Metadata) <small style="color:#929393">(v1.0)</small>
22272302
* [Software](/datasources/DS0039/#Software) <small style="color:#929393">(v1.0)</small>
22282303

2229-
## Contributors to this release
2230-
2231-
* Aaron Sullivan aka ZerkerEOD
2232-
* Adam Lichters
2233-
* Alden Schmidt
2234-
* Ale Houspanossian
2235-
* Alexey Kleymenov
2236-
* Alon Klayman, Hunters Security
2237-
* Amnon Kushnir, Sygnia
2238-
* Ben Smith, @cyberg3cko
2239-
* Caio Silva
2240-
* Cian Heasley
2241-
* Cristian Souza - Kaspersky GERT
2242-
* Cristóbal Martínez Martín
2243-
* David Hughes, BT Security
2244-
* Dhiraj Mishra (@RandomDhiraj)
2245-
* Dmitry Bestuzhev
2246-
* Dvir Sasson, Reco
2247-
* Eliraz Levi, Hunters Security
2248-
* Fabian Kammel
2249-
* Fernando Bacchin
2250-
* Flavio Costa, Cisco
2251-
* Frank Angiolelli
2252-
* Gabriel Currie
2253-
* Gerardo Santos
2254-
* Harikrishnan Muthu, Cyble
2255-
* Hiroki Nagahama, NEC Corporation
2256-
* Inna Danilevich, U.S. Bank
2257-
* Jaesang Oh, KC7 Foundation
2258-
* Janantha Marasinghe
2259-
* Jennifer Kim Roman
2260-
* Jiraput Thamsongkrah
2261-
* Joas Antonio dos Santos, @C0d3Cr4zy
2262-
* Joe Gumke, U.S. Bank
2263-
* Jun Hirata, NEC Corporation
2264-
* Kaung Zaw Hein
2265-
* Kevin Ward
2266-
* Kori Yoshihiro, NEC Corporation
2267-
* Kyaw Pyiyt Htet, @KyawPyiytHtet
2268-
* Liran Ravich, CardinalOps
2269-
* Lê Phương Nam, Group-IB
2270-
* Manikantan Srinivasan, NEC Corporation India
2271-
* Matt Anderson, @‌nosecurething, Huntress
2272-
* Matt Brenton, Zurich Global Information Security
2273-
* Matt Brenton, Zurich Insurance Group
2274-
* Menachem Goldstein
2275-
* Michael Davis @ ServiceNow Threat Intelligence
2276-
* MyungUk Han, ASEC
2277-
* Natthawut Saexu
2278-
* Nikita Rostovcev, Group-IB
2279-
* Oren Biderman, Sygnia
2280-
* Peter Oakes
2281-
* Pooja Natarajan, NEC Corporation India
2282-
* Raghvendra Mishra
2283-
* ReliaQuest
2284-
* RoseSecurity
2285-
* Rouven Bissinger (SySS GmbH)
2286-
* Ruben Groenewoud (@RFGroenewoud)
2287-
* Ryan Perez
2288-
* Sareena Karapoola, NEC Corporation India
2289-
* seungyoul.yoo@ahnlab.com
2290-
* Sharmine Low, Group-IB
2291-
* Shun Miyazaki, NEC Corporation
2292-
* Shwetank Murarka
2293-
* Sittikorn Sangrattanapitak
2294-
* Suraj Khetani (@r00treaver)
2295-
* Vicky Ray, RayvenX
2296-
* Vijay Lalwani
2297-
* Wietze Beukema @Wietze
2298-
* Yoshihiro Kori, NEC Corporation

0 commit comments

Comments
 (0)