Compare commits
	
		
			No commits in common. "e939322f92f858cea3f89fa4c4fee20e6b9d8c9b" and "0dcad55bb874acda1723b5ad4fe0808149230f91" have entirely different histories.
		
	
	
		
			e939322f92
			...
			0dcad55bb8
		
	
		
					 2 changed files with 34 additions and 24 deletions
				
			
		| 
						 | 
					@ -14,9 +14,8 @@ from .images import ImageProcessor
 | 
				
			||||||
from .output_generator import OutputGenerator
 | 
					from .output_generator import OutputGenerator
 | 
				
			||||||
from .html_generator import HTMLGenerator
 | 
					from .html_generator import HTMLGenerator
 | 
				
			||||||
from .transform_processor import TransformProcessor
 | 
					from .transform_processor import TransformProcessor
 | 
				
			||||||
from .pandoc_processor import PandocProcessor
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
from panflute import convert_text
 | 
					from .mj_show import show
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def main():
 | 
					def main():
 | 
				
			||||||
	# Initialize command line arguments
 | 
						# Initialize command line arguments
 | 
				
			||||||
| 
						 | 
					@ -25,10 +24,8 @@ def main():
 | 
				
			||||||
	parser.add_argument("-p", "--img-public-dir", help="Directory to put processed images into. The program will overwrite images, whose dependencies are newer.", default="public")
 | 
						parser.add_argument("-p", "--img-public-dir", help="Directory to put processed images into. The program will overwrite images, whose dependencies are newer.", default="public")
 | 
				
			||||||
	parser.add_argument("-c", "--img-cache-dir", help="Directory to cache processed images and intermediate products. The program will overwrite files, whose dependencies are newer.", default="cache")
 | 
						parser.add_argument("-c", "--img-cache-dir", help="Directory to cache processed images and intermediate products. The program will overwrite files, whose dependencies are newer.", default="cache")
 | 
				
			||||||
	parser.add_argument("-i", "--img-web-path", help="Path where the processed images are available on the website.", default="/")
 | 
						parser.add_argument("-i", "--img-web-path", help="Path where the processed images are available on the website.", default="/")
 | 
				
			||||||
	parser.add_argument("-w", "--output-html", help="The HTML file (for Web) to write into.")
 | 
						parser.add_argument("-w", "--output-html", help="The HTML file (for Web) to write into.", default="output.html")
 | 
				
			||||||
	parser.add_argument("-t", "--output-tex", help="The TEX file to write into.")
 | 
						parser.add_argument("-t", "--output-tex", help="The TEX file to write into.", default="output.tex")
 | 
				
			||||||
	parser.add_argument("-m", "--output-md", help="The Markdown file to write into. (Uses pandoc to generate markdown)")
 | 
					 | 
				
			||||||
	parser.add_argument("-j", "--output-json", help="The JSON file to dump the pandoc-compatible AST into.")
 | 
					 | 
				
			||||||
	parser.add_argument("input_filename", help="The markdown file to process.")
 | 
						parser.add_argument("input_filename", help="The markdown file to process.")
 | 
				
			||||||
	parser.add_argument("--debug", action='store_true')
 | 
						parser.add_argument("--debug", action='store_true')
 | 
				
			||||||
	args = parser.parse_args()
 | 
						args = parser.parse_args()
 | 
				
			||||||
| 
						 | 
					@ -36,30 +33,44 @@ def main():
 | 
				
			||||||
	# just connect to an existing one. For formátíking many files in a row.
 | 
						# just connect to an existing one. For formátíking many files in a row.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	# Use panflute to parse the input MD file
 | 
						# Use panflute to parse the input MD file
 | 
				
			||||||
	doc = import_md(open(args.input_filename, "r").read())
 | 
						#doc1 = import_md(open(args.input_filename, "r").read())
 | 
				
			||||||
 | 
						doc2 = import_md(open(args.input_filename, "r").read())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if args.debug:
 | 
						if args.debug:
 | 
				
			||||||
		OutputGenerator(sys.stdout).generate(doc)
 | 
							print(show(doc1))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	doc = TransformProcessor(args.input_filename).transform(doc)
 | 
						# The language metadatum is important, so it's read before transformation and
 | 
				
			||||||
 | 
						# then attached to a group inside the Doc
 | 
				
			||||||
 | 
						#language = doc1.get_metadata("lang", None, True)
 | 
				
			||||||
 | 
						#context = Context(doc1, args.input_filename)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						# Transform the document. This includes all the fancy formatting this software does.
 | 
				
			||||||
 | 
						#doc1 = doc1.walk(transform, context)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						# Now wrap the document contents in a group, which is able to pop its language
 | 
				
			||||||
 | 
						# setting out to TeX
 | 
				
			||||||
 | 
						#doc1.content = [BlockGroup(*doc1.content, context=context, metadata={"lang":language})]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						doc2 = TransformProcessor(args.input_filename).transform(doc2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	# Initialize the image processor (this just keeps some basic state)
 | 
						# Initialize the image processor (this just keeps some basic state)
 | 
				
			||||||
	imageProcessor = ImageProcessor(args.img_public_dir, args.img_web_path, args.img_cache_dir, *args.img_lookup_dirs)
 | 
						imageProcessor = ImageProcessor(args.img_public_dir, args.img_web_path, args.img_cache_dir, *args.img_lookup_dirs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if args.output_html is not None:
 | 
					 | 
				
			||||||
	# Initialize KaTeX client (this runs the node app and connects to a unix socket)
 | 
						# Initialize KaTeX client (this runs the node app and connects to a unix socket)
 | 
				
			||||||
	with KatexClient() as katexClient:
 | 
						with KatexClient() as katexClient:
 | 
				
			||||||
			HTMLGenerator(open(args.output_html, "w"), katexClient, imageProcessor).generate(doc)
 | 
							# Generate HTML and TeX out of the transformed document
 | 
				
			||||||
 | 
							#open(args.output_html, "w").write(html(doc, katexClient, imageProcessor))
 | 
				
			||||||
 | 
							#open(args.output_tex, "w").write(tex(doc, imageProcessor))
 | 
				
			||||||
 | 
							HTMLGenerator(sys.stdout, katexClient, imageProcessor).generate(doc2)
 | 
				
			||||||
 | 
							#OutputGenerator(open("/tmp/doc1", "w")).generate(doc1)
 | 
				
			||||||
 | 
							#OutputGenerator(open("/tmp/doc2", "w")).generate(doc2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if args.output_md is not None:
 | 
						from panflute import convert_text
 | 
				
			||||||
		open(args.output_md, "w").write(convert_text(PandocProcessor().transform(doc), input_format="panflute", output_format="markdown"))
 | 
						from .pandoc_processor import PandocProcessor
 | 
				
			||||||
 | 
						open("/tmp/bruhecek.md", "w").write(convert_text(PandocProcessor().transform(doc2), input_format="panflute", output_format="markdown"))
 | 
				
			||||||
	if args.output_json is not None:
 | 
					 | 
				
			||||||
		open(args.output_json, "w").write(convert_text(PandocProcessor().transform(doc), input_format="panflute", output_format="json"))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if args.debug:
 | 
						if args.debug:
 | 
				
			||||||
		print("-----------------------------------")
 | 
							print(show(doc))
 | 
				
			||||||
		OutputGenerator(sys.stdout).generate(doc)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == "__main__":
 | 
					if __name__ == "__main__":
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,12 +2,14 @@ from .nop_processor import NOPProcessor
 | 
				
			||||||
from panflute import Div, Span, Null, Str, Plain, Quoted
 | 
					from panflute import Div, Span, Null, Str, Plain, Quoted
 | 
				
			||||||
from .context import Group, InlineGroup, BlockGroup
 | 
					from .context import Group, InlineGroup, BlockGroup
 | 
				
			||||||
from .elements import FQuoted
 | 
					from .elements import FQuoted
 | 
				
			||||||
from .whitespace import NBSP
 | 
					 | 
				
			||||||
from .nop_processor import ELCl
 | 
					from .nop_processor import ELCl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from typing import Callable
 | 
					from typing import Callable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
 | 
					def eprint(*args, **kwargs):
 | 
				
			||||||
 | 
						print(*args, **kwargs, file=sys.stderr)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PandocProcessor(NOPProcessor):
 | 
					class PandocProcessor(NOPProcessor):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	def get_posttransformers(self) -> list[Callable[[ELCl],ELCl]]:
 | 
						def get_posttransformers(self) -> list[Callable[[ELCl],ELCl]]:
 | 
				
			||||||
| 
						 | 
					@ -36,6 +38,3 @@ class PandocProcessor(NOPProcessor):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	def transform_FQuoted(self, e: FQuoted) -> Quoted:
 | 
						def transform_FQuoted(self, e: FQuoted) -> Quoted:
 | 
				
			||||||
		return Quoted(*e.content)
 | 
							return Quoted(*e.content)
 | 
				
			||||||
 | 
					 | 
				
			||||||
	def transform_NBSP(self, e: NBSP) -> Str:
 | 
					 | 
				
			||||||
		return Str(" ") # Unicode nbsp
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue