Commit 5b50a6f7 authored by ankraft's avatar ankraft
Browse files

Added stdin/stdout filter to convert grid tables to html

parent ea4853f4
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
#
#	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()