Commit a276e44f authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

Adding output option to the processMDSpec.py

parent a37f391b
Loading
Loading
Loading
Loading
Loading
+12 −2
Changes for markdownTools/processMDSpec.py: 12 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -288,6 +288,7 @@ def main(args=None):
	parser.add_argument('--frontmatter-only', '-fmo', dest='onlyFrontMatter', action='store_true',  help='output only front matter')
	parser.add_argument('--frontmatter-out-file', '-fmf', dest='frontMatterOutFile', type=str, help='output front matter to a file')
	parser.add_argument('--frontmatter-out-format', '-fmt', dest='frontMatterOutFormat', type=str, choices=['yaml', 'json'], default='yaml', help='front matter output format (default: yaml)')
	parser.add_argument('--output', '-o', dest='outputFile', type=str, help='write processed markdown to a file (recommended when running under docker)')
	parser.add_argument('--verbose', '-v', action='store_true', help='print debug information to stderr.')
	parser.add_argument('document', type=str, help='a markdown specification document to process')
	args = parser.parse_args()
@@ -345,8 +346,17 @@ def main(args=None):
			# Render the markdown content
			print(markdown.Markdown(lines))
		else:
			# Print the raw markdown content
			_print(lines)
			# Prefer writing to a file when running under docker: host-side redirects of
			# `docker run ... > file` can truncate large stdout streams.
			output = lines if lines.endswith('\n') else lines + '\n'
			if args.outputFile:
				if args.verbose:
					print(f'[green]Writing processed markdown to {args.outputFile}', file=sys.stderr)
				with open(args.outputFile, 'w', encoding='utf-8', newline='\n') as f:
					f.write(output)
			else:
				sys.stdout.write(output)
				sys.stdout.flush()

if __name__ == '__main__':
	sys.exit(main())