I’m generating cybersecurity reports using Pandoc and Markdown. Each report contains multiple vulnerabilities, each with a recommendation section. I need to extract all recommendations from the document and insert them into a separate section called Consolidated Recommendations at the end of the document (or in a specific location). The report follows the same template --- title: "Cybersecurity report" author: "security team" --- # Introduction Introduction here # Vulnerabilities ## CVE-2024-12345 **Description:** Description here **Impact:** Impact here **Recommendation:** Recommendation here ## CVE-2024-67890 **Description:** Description here **Impact:** Impact here **Recommendation:** Recommendation here # Summary Summary here I need to extract specific sections from a Markdown document and insert them into new sections or structured tables in the final output. For example, I want to collect all recommendations scattered throughout the document and place them in a separate Recommendations section. I've used JavaScript to parse HTML, but it wouldn’t be applicable to LaTeX or DOCX, so I need a unified approach. I've tried a python script that parses Markdown, extracts sections, stores them in JSON, and generates separate documents to be merged into the final output. Questions Best workflow? – Is my current approach (extracting to JSON, then generating separate documents) the best and most efficient way to handle this? I'm aware of gpp and lua filters, but given that this preprocessing is complex, I would prefer using python. Are there better alternatives? Merging extracted content with the main document – If I generate a new HTML file from the extracted JSON sections, what’s the best way to combine it with the main HTML template? The same question applies to LaTeX and DOCX. Continue reading...