From 5b50a6f75de1436d2e8637e2f720b2d0fc39628d Mon Sep 17 00:00:00 2001
From: ankraft <an.kraft@gmail.com>
Date: Mon, 24 Feb 2025 20:17:23 +0100
Subject: [PATCH] Added stdin/stdout filter to convert grid tables to html

---
 toMkdocs/gridTableFilter.py | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 toMkdocs/gridTableFilter.py

diff --git a/toMkdocs/gridTableFilter.py b/toMkdocs/gridTableFilter.py
new file mode 100644
index 0000000..c630ae1
--- /dev/null
+++ b/toMkdocs/gridTableFilter.py
@@ -0,0 +1,36 @@
+#
+#	gridTableFilter.py
+#
+#	(c) 2025 by Andreas Kraft & Miguel Angel Reina Ortega
+#	License: BSD 3-Clause License. See the LICENSE file for further details.
+#
+""" This script replaces the grid tables in the markdown files with the equivalent
+	html tables. Other markdown elements are not affected and are passed through.
+
+	The script expects the markdown file to be converted from stdin and writes the
+	result to stdout.
+"""
+
+import argparse, sys
+from rich import print
+from markdownTools import analyseMarkdown, setLoggers
+
+def main() -> None:
+
+	# Parse the command line arguments
+	parser = argparse.ArgumentParser(description='Convert grid tables to html tables. This script reads the markdown file from stdin and writes the result to stdout.')
+	parser.add_argument('-v', '--verbose', action='store_true', help='Print debug information to stderr.')
+	args = parser.parse_args()
+
+	# Set the loggers
+	setLoggers(info=lambda m: print(f'[green]{m}', file=sys.stderr) if args.verbose else None, 
+			   debug=lambda m: print(f'[dim]{m}', file=sys.stderr) if args.verbose else None,
+			   error=lambda m: print(f'[red]{m}', file=sys.stderr) if args.verbose else None)  
+
+	# Read the input from stdin and write the result to stdout
+	print(analyseMarkdown(inLines=sys.stdin.readlines()), file=sys.stdout)
+
+
+if __name__ == '__main__':
+	main()
+
-- 
GitLab