Unifikace stylu názvů proměnných, viz můj komentář v #14.
This commit is contained in:
		
							parent
							
								
									cfbe3e128d
								
							
						
					
					
						commit
						1ed1265b19
					
				
					 3 changed files with 23 additions and 23 deletions
				
			
		|  | @ -11,8 +11,8 @@ from .katex import KatexClient | ||||||
| from .html import html | from .html import html | ||||||
| from .tex import tex | from .tex import tex | ||||||
| from .images import ImageProcessor | from .images import ImageProcessor | ||||||
| from .output_generator import Output_generator | from .output_generator import OutputGenerator | ||||||
| from .html_generator import HTML_generator | from .html_generator import HTMLGenerator | ||||||
| 
 | 
 | ||||||
| from .mj_show import show | from .mj_show import show | ||||||
| 
 | 
 | ||||||
|  | @ -56,7 +56,7 @@ def main(): | ||||||
| 		# Generate HTML and TeX out of the transformed document | 		# Generate HTML and TeX out of the transformed document | ||||||
| 		#open(args.output_html, "w").write(html(doc, katexClient, imageProcessor)) | 		#open(args.output_html, "w").write(html(doc, katexClient, imageProcessor)) | ||||||
| 		#open(args.output_tex, "w").write(tex(doc, imageProcessor)) | 		#open(args.output_tex, "w").write(tex(doc, imageProcessor)) | ||||||
| 		Output_generator(sys.stdout).generate(doc) | 		OutputGenerator(sys.stdout).generate(doc) | ||||||
| 
 | 
 | ||||||
| 	if args.debug: | 	if args.debug: | ||||||
| 		print(show(doc)) | 		print(show(doc)) | ||||||
|  |  | ||||||
|  | @ -15,15 +15,15 @@ from pygments.util import ClassNotFound | ||||||
| 
 | 
 | ||||||
| from .whitespace import NBSP | from .whitespace import NBSP | ||||||
| from .context import Group | from .context import Group | ||||||
| from .output_generator import Output_generator | from .output_generator import OutputGenerator | ||||||
| from .katex import KatexClient | from .katex import KatexClient | ||||||
| from .images import ImageProcessor | from .images import ImageProcessor | ||||||
| from .util import inlinify | from .util import inlinify | ||||||
| 
 | 
 | ||||||
| class HTML_generator(Output_generator): | class HTMLGenerator(OutputGenerator): | ||||||
| 	def __init__(self, output_file, katex_client: KatexClient, image_processor:ImageProcessor, *args, **kwargs): | 	def __init__(self, output_file, katexClient: KatexClient, imageProcessor: ImageProcessor, *args, **kwargs): | ||||||
| 		self.katex_client = katex_client | 		self.katexClient = katexClient | ||||||
| 		self.image_processor = image_processor | 		self.imageProcessor = imageProcessor | ||||||
| 		super().__init__(output_file, *args, **kwargs) | 		super().__init__(output_file, *args, **kwargs) | ||||||
| 
 | 
 | ||||||
| 	def generate(self, e: Union[Element, ListContainer]): | 	def generate(self, e: Union[Element, ListContainer]): | ||||||
|  | @ -149,15 +149,15 @@ class HTML_generator(Output_generator): | ||||||
| 			# Even supported elements have to be 'converted' because the | 			# Even supported elements have to be 'converted' because the | ||||||
| 			# processing contains finding and moving them to the output | 			# processing contains finding and moving them to the output | ||||||
| 			# directory. | 			# directory. | ||||||
| 			url = self.image_processor.process_image(url, ext, source_dir, **additional_args) | 			url = self.imageProcessor.process_image(url, ext, source_dir, **additional_args) | ||||||
| 		elif ext in ["pdf", "epdf"]: | 		elif ext in ["pdf", "epdf"]: | ||||||
| 			if not "dpi" in additional_args: | 			if not "dpi" in additional_args: | ||||||
| 				additional_args["dpi"] = 300 | 				additional_args["dpi"] = 300 | ||||||
| 			url = self.image_processor.process_image(url, "png", source_dir, **additional_args) | 			url = self.imageProcessor.process_image(url, "png", source_dir, **additional_args) | ||||||
| 		elif ext in ["jpg"]: | 		elif ext in ["jpg"]: | ||||||
| 			url = self.image_processor.process_image(url, "jpeg", source_dir, **additional_args) | 			url = self.imageProcessor.process_image(url, "jpeg", source_dir, **additional_args) | ||||||
| 		else: | 		else: | ||||||
| 			url = self.image_processor.process_image(url, "png", source_dir, **additional_args) | 			url = self.imageProcessor.process_image(url, "png", source_dir, **additional_args) | ||||||
| 		 | 		 | ||||||
| 		# Srcset generation - multiple alternative sizes of images browsers can | 		# Srcset generation - multiple alternative sizes of images browsers can | ||||||
| 		# choose from. | 		# choose from. | ||||||
|  | @ -168,16 +168,16 @@ class HTML_generator(Output_generator): | ||||||
| 			# This is inspired by @vojta001's blogPhoto shortcode he made for | 			# This is inspired by @vojta001's blogPhoto shortcode he made for | ||||||
| 			# patek.cz: | 			# patek.cz: | ||||||
| 			# https://gitlab.com/patek-devs/patek.cz/-/blob/master/themes/patek/layouts/shortcodes/blogPhoto.html | 			# https://gitlab.com/patek-devs/patek.cz/-/blob/master/themes/patek/layouts/shortcodes/blogPhoto.html | ||||||
| 			width, height = self.image_processor.get_image_size(url, [self.image_processor.public_dir]) | 			width, height = self.imageProcessor.get_image_size(url, [self.imageProcessor.public_dir]) | ||||||
| 			sizes = [(640, 360, 85), (1280, 720, 85), (1920, 1080, 90)] # (widht, height, quality) | 			sizes = [(640, 360, 85), (1280, 720, 85), (1920, 1080, 90)] # (widht, height, quality) | ||||||
| 			for size in sizes: | 			for size in sizes: | ||||||
| 				if width <= size[0] and height <= size[1]: | 				if width <= size[0] and height <= size[1]: | ||||||
| 					srcset.append((f'{self.image_processor.web_path}/{url}', f'{width}w')) | 					srcset.append((f'{self.imageProcessor.web_path}/{url}', f'{width}w')) | ||||||
| 					break | 					break | ||||||
| 				quality = size[2] if ext == "jpeg" else None | 				quality = size[2] if ext == "jpeg" else None | ||||||
| 				srcset.append((f'{self.image_processor.web_path}/{self.image_processor.process_image(url, ext, self.image_processor.public_dir, width=size[0], height=size[1], quality=quality)}', f'{size[0]}w')) | 				srcset.append((f'{self.imageProcessor.web_path}/{self.imageProcessor.process_image(url, ext, self.imageProcessor.public_dir, width=size[0], height=size[1], quality=quality)}', f'{size[0]}w')) | ||||||
| 
 | 
 | ||||||
| 		url = self.image_processor.web_path + "/" + url | 		url = self.imageProcessor.web_path + "/" + url | ||||||
| 		 | 		 | ||||||
| 		attributes = self.common_attributes(e) | 		attributes = self.common_attributes(e) | ||||||
| 		if "width" in e.attributes: | 		if "width" in e.attributes: | ||||||
|  | @ -187,7 +187,7 @@ class HTML_generator(Output_generator): | ||||||
| 			attributes["alt"] = e.title | 			attributes["alt"] = e.title | ||||||
| 		else: | 		else: | ||||||
| 			fake_out = io.StringIO() | 			fake_out = io.StringIO() | ||||||
| 			HTML_generator(fake_out, self.katex_client, self.image_processor).generate(e.content) | 			HTMLGenerator(fake_out, self.katexClient, self.imageProcessor).generate(e.content) | ||||||
| 			attributes["alt"] = fake_out.getvalue() | 			attributes["alt"] = fake_out.getvalue() | ||||||
| 		 | 		 | ||||||
| 		if len(srcset) != 0: | 		if len(srcset) != 0: | ||||||
|  | @ -202,9 +202,9 @@ class HTML_generator(Output_generator): | ||||||
| 		self.generate(link) | 		self.generate(link) | ||||||
| 
 | 
 | ||||||
| 	def generate_Group(self, e: Group): | 	def generate_Group(self, e: Group): | ||||||
| 		self.katex_client.begingroup() | 		self.katexClient.begingroup() | ||||||
| 		self.generate(e.content) | 		self.generate(e.content) | ||||||
| 		self.katex_client.endgroup() | 		self.katexClient.endgroup() | ||||||
| 
 | 
 | ||||||
| 	def generate_Plain(self, e: Plain): | 	def generate_Plain(self, e: Plain): | ||||||
| 		self.generate(e.content) | 		self.generate(e.content) | ||||||
|  | @ -234,7 +234,7 @@ class HTML_generator(Output_generator): | ||||||
| 			"DisplayMath": True, | 			"DisplayMath": True, | ||||||
| 			"InlineMath": False | 			"InlineMath": False | ||||||
| 		} | 		} | ||||||
| 		self.writeln(self.katex_client.render(e.text, {"displayMode": formats[e.format]})) | 		self.writeln(self.katexClient.render(e.text, {"displayMode": formats[e.format]})) | ||||||
| 
 | 
 | ||||||
| 	def generate_RawInline(self, e: RawInline): | 	def generate_RawInline(self, e: RawInline): | ||||||
| 		if e.format == "html": | 		if e.format == "html": | ||||||
|  |  | ||||||
|  | @ -8,11 +8,11 @@ from .whitespace import NBSP | ||||||
| from .transform import FQuoted | from .transform import FQuoted | ||||||
| from .context import Group | from .context import Group | ||||||
| 
 | 
 | ||||||
| class UnknownElementException(Exception): | class UnknownElementError(Exception): | ||||||
| 	"An unknown Element has been passed to the Output_generator, probably because panflute introduced a new one." | 	"An unknown Element has been passed to the Output_generator, probably because panflute introduced a new one." | ||||||
| 	pass | 	pass | ||||||
| 
 | 
 | ||||||
| class Output_generator: | class OutputGenerator: | ||||||
| 	def __init__(self, output_file, indent_str: str="\t", initial_indent_level: int=0): | 	def __init__(self, output_file, indent_str: str="\t", initial_indent_level: int=0): | ||||||
| 		self.output_file = output_file | 		self.output_file = output_file | ||||||
| 		self.indent_str = indent_str | 		self.indent_str = indent_str | ||||||
|  | @ -85,7 +85,7 @@ class Output_generator: | ||||||
| 					ListItem: self.generate_ListItem | 					ListItem: self.generate_ListItem | ||||||
| 				}[type(e)](e) | 				}[type(e)](e) | ||||||
| 			except KeyError: | 			except KeyError: | ||||||
| 				raise UnknownElementException(type(e)) | 				raise UnknownElementError(type(e)) | ||||||
| 
 | 
 | ||||||
| 	def generate_ListContainer(self, e: ListContainer): | 	def generate_ListContainer(self, e: ListContainer): | ||||||
| 		for child in e: | 		for child in e: | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue