From a32c66a3bf59c5583d77379180c9bc863460ebdd Mon Sep 17 00:00:00 2001 From: Matthew John Date: Sat, 15 Jun 2024 05:57:39 +0100 Subject: [PATCH 1/2] feat: Support syntax highlighting in code blocks in README and other markdown The fenced_code extension of markdown already adds the language-X classes to code blocks. This was being stripped off by bleach, which has now been updated to allow classes in code blocks. Issue #529 --- terrareg/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/terrareg/utils.py b/terrareg/utils.py index 8d558854..7f4ce5f5 100644 --- a/terrareg/utils.py +++ b/terrareg/utils.py @@ -118,8 +118,10 @@ def sanitise_html_content(text, allow_markdown_html=False): # Custom allowed attributes 'h1': ['id'], 'h2': ['id'], 'h3': ['id'], 'h4': ['id'], 'h5': ['id'], 'h6': ['id'], - 'img': ['src'] + 'img': ['src'], + 'code': ['class'] } + return ( bleach.clean( text, **kwargs From 66e21fdbc351280a05753ede3da5be173a16413e Mon Sep 17 00:00:00 2001 From: Matthew John Date: Mon, 17 Jun 2024 07:25:01 +0100 Subject: [PATCH 2/2] docs: Add documentation explaining markdown syntax highlighting Issue #529 --- docs/modules/best_practices.md | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/docs/modules/best_practices.md b/docs/modules/best_practices.md index 8d06c586..cba2b6f6 100644 --- a/docs/modules/best_practices.md +++ b/docs/modules/best_practices.md @@ -6,6 +6,42 @@ Terrareg has been extensively tested with Terraform modules of all shapes and si However, to get the _most_ out of Terrareg, there are some practices/guides that will help. +## Markdown + +Markdown files can be indexed and shown as tabs. + +The README.md in a root module, sub-modules and examples are indexed by default. + +Additional markdown files can be indexed and shown as tabs using [ADDITIONAL_MODULE_TABS](../CONFIG.md#additional_module_tabs) + +Code blocks are shown with syntax highlighting, with the following supported languages: + + * `hcl` + * `css` + * `bash` + * `batch` + * `docker` + * `hcl` + * `plsql` + * `powershell` + * `python` + * `sql` + +Auto-detection of languages is used, but it's safest to write with language-helper markup, e.g.: +```` +```hcl +terraform { + required_version = "0.1.2 +} +``` + +```bash +#!/bin/bash + +echo Some bash script +``` +```` + ## Terrareg metadata file A metadata file can be provided each an uploaded module's archive to provide additional metadata to terrareg.