From 68ac117821e757dc26a92fbaa4057870eb38667c Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 6 Dec 2025 23:41:47 +0200 Subject: Fix draft HTML generation for files with unsupported source-highlight languages - Add .tmp to exclusion pattern in cleanup to prevent race condition - Gracefully fallback to plain
 when source-highlight fails (e.g., yaml)
---
 AGENTS.md              | 23 +++++++++++++++++++++++
 lib/generate.source.sh |  2 +-
 lib/html.source.sh     | 12 ++++++------
 3 files changed, 30 insertions(+), 7 deletions(-)
 create mode 100644 AGENTS.md

diff --git a/AGENTS.md b/AGENTS.md
new file mode 100644
index 0000000..70c98f0
--- /dev/null
+++ b/AGENTS.md
@@ -0,0 +1,23 @@
+# AGENTS.md
+
+## Build, Lint, and Test
+
+- **Build/generate:** `./gemtexter --generate`
+- **Publish:** `./gemtexter --publish`
+- **Run all tests:** `./gemtexter --test`
+- **Lint (ShellCheck):** `shellcheck --external-sources --check-sourced lib/*.sh ./gemtexter`
+- **Run a single test:** Edit `lib/assert.source.sh` or relevant test function, then run `./gemtexter --test`
+
+## Code Style Guidelines
+
+- **Shell:** Bash 5.x+ only. Use `#!/usr/bin/env bash` shebang.
+- **Formatting:** 2 spaces, no tabs. Max line length: 80 chars.
+- **Imports:** Source libraries with `.sh` extension, not executable.
+- **Naming:** Functions/variables: `lower_case`, constants: `ALL_CAPS`.
+- **Functions:** Use `package::function()` for libraries. Add header comments for non-trivial functions.
+- **Quoting:** Always quote variables, command substitutions, and paths.
+- **Error handling:** Use `set -euf -o pipefail`. Check all command return values.
+- **Testing:** Use `assert::` functions for unit tests.
+- **Linting:** Fix all ShellCheck warnings except those excluded in `assert::shellcheck`.
+- **Consistency:** Follow [Google Shell Style Guide](https://google.github.io/styleguide/shellguide.html) and [ShellCheck Wiki](https://github.com/koalaman/shellcheck/wiki).
+
diff --git a/lib/generate.source.sh b/lib/generate.source.sh
index db9dc95..313531d 100644
--- a/lib/generate.source.sh
+++ b/lib/generate.source.sh
@@ -185,7 +185,7 @@ generate::fromgmi () {
     # Anoter note: The CNAME file is required by GitHub pages as well for custom domains.
     for format in "$@"; do
         find "$CONTENT_BASE_DIR/$format" -type f |
-        $GREP -E -v '(\.git.*|_config.yml|CNAME|.domains|robots.txt|static)$'|
+        $GREP -E -v '(\.git.*|_config.yml|CNAME|.domains|robots.txt|static|\.tmp)$'|
         while read -r src; do
             generate::fromgmi_cleanup_docs "$src" "$format" 
         done &
diff --git a/lib/html.source.sh b/lib/html.source.sh
index 1d5b34c..f772e22 100644
--- a/lib/html.source.sh
+++ b/lib/html.source.sh
@@ -138,11 +138,6 @@ html::source_highlight () {
         html::encode "$bare_text"
         echo '
' else - local style_css='' - if [ -n "$SOURCE_HIGHLIGHT_CSS" ]; then - style_css="--style-css-file=$SOURCE_HIGHLIGHT_CSS" - fi - if [[ "$lang_trimmed" == "AUTO" ]]; then log WARN "GNU Source Highlight auto detection not yet supported!" echo '
'
@@ -154,7 +149,12 @@ html::source_highlight () {
             if [ -n "$SOURCE_HIGHLIGHT_CSS" ]; then
                 cmd+=("--style-css-file=$SOURCE_HIGHLIGHT_CSS")
             fi
-            "${cmd[@]}" <<< "$bare_text" | $SED 's|||; s|||;'
+            if ! "${cmd[@]}" <<< "$bare_text" 2>/dev/null | $SED 's|||; s|||;'; then
+                # Fallback if source-highlight doesn't support the language
+                echo '
'
+                html::encode "$bare_text"
+                echo '
' + fi fi fi } -- cgit v1.2.3