Compare commits
	
		
			No commits in common. "48e6f53a4fa308503b59aa37c33ff34c01b25b68" and "410c2852b2590f5999f7c8d7acd5a27c21f43865" have entirely different histories.
		
	
	
		
			48e6f53a4f
			...
			410c2852b2
		
	
		
					 12 changed files with 35 additions and 56 deletions
				
			
		| 
						 | 
					@ -1,7 +0,0 @@
 | 
				
			||||||
root = true
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
[*]
 | 
					 | 
				
			||||||
end_of_line = lf
 | 
					 | 
				
			||||||
insert_final_newline = true
 | 
					 | 
				
			||||||
charset = utf-8
 | 
					 | 
				
			||||||
indent_style = tab
 | 
					 | 
				
			||||||
| 
						 | 
					@ -28,9 +28,8 @@ formatitko = "formatitko.formatitko:main"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[tool.setuptools_scm]
 | 
					[tool.setuptools_scm]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[tool.setuptools.packages.find]
 | 
					[tool.setuptools.packages.find]
 | 
				
			||||||
where = ["src"]
 | 
					where = ["src"]
 | 
				
			||||||
exclude = ["src/formatitko/katex-server/node_modules"]
 | 
					exclude = ["src/formatitko/katex-server/node_modules"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[tool.pyright]
 | 
					 | 
				
			||||||
strictParameterNoneValue = false
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,9 +1,10 @@
 | 
				
			||||||
from panflute import Div, Span, Para, Element
 | 
					from panflute import Div,Span,Para
 | 
				
			||||||
from typing import List
 | 
					from typing import List
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Import local files
 | 
					# Import local files
 | 
				
			||||||
from .util import nullify, import_md
 | 
					from .util import *
 | 
				
			||||||
from .context import Context
 | 
					from .context import Context
 | 
				
			||||||
 | 
					from .mj_show import show
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Command:
 | 
					class Command:
 | 
				
			||||||
	pass
 | 
						pass
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,6 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from panflute import Doc, Div
 | 
					from panflute import Doc, Div
 | 
				
			||||||
 | 
					from typing import Dict
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -70,15 +71,15 @@ class Context:
 | 
				
			||||||
		if key == "language":
 | 
							if key == "language":
 | 
				
			||||||
			print("WARN: Setting language this way doesn't propagate to TeX. Either use the Front Matter or specify it additionally using the \\languagexx macro.")
 | 
								print("WARN: Setting language this way doesn't propagate to TeX. Either use the Front Matter or specify it additionally using the \\languagexx macro.")
 | 
				
			||||||
		meta = self.doc.metadata
 | 
							meta = self.doc.metadata
 | 
				
			||||||
		keys = key.split(".")
 | 
							key = key.split(".")
 | 
				
			||||||
		for k in keys[:-1]:
 | 
							for k in key[:-1]:
 | 
				
			||||||
			meta = meta[k]
 | 
								meta = meta[k]
 | 
				
			||||||
		meta[keys[-1]] = value
 | 
							meta[key[-1]] = value
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	def unset_metadata(self, key: str):
 | 
						def unset_metadata(self, key: str):
 | 
				
			||||||
		meta = self.doc.metadata
 | 
							meta = self.doc.metadata
 | 
				
			||||||
		keys = key.split(".")
 | 
							key = key.split(".")
 | 
				
			||||||
		for k in keys[:-1]:
 | 
							for k in key[:-1]:
 | 
				
			||||||
			meta = meta[k]
 | 
								meta = meta[k]
 | 
				
			||||||
		del meta.content[key[-1]] # A hack because MetaMap doesn't have a __delitem__
 | 
							del meta.content[key[-1]] # A hack because MetaMap doesn't have a __delitem__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,10 +1,14 @@
 | 
				
			||||||
#!/usr/bin/env python3
 | 
					#!/usr/bin/env python3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import argparse
 | 
					import argparse
 | 
				
			||||||
 | 
					import re
 | 
				
			||||||
 | 
					import sys
 | 
				
			||||||
 | 
					from typing import List
 | 
				
			||||||
 | 
					import os
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Import local files
 | 
					# Import local files
 | 
				
			||||||
from .transform import transform
 | 
					from .transform import transform
 | 
				
			||||||
from .util import import_md
 | 
					from .util import *
 | 
				
			||||||
from .context import Context, Group
 | 
					from .context import Context, Group
 | 
				
			||||||
from .katex import KatexClient
 | 
					from .katex import KatexClient
 | 
				
			||||||
from .html import html
 | 
					from .html import html
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,6 @@ from pygments.lexers import get_lexer_by_name
 | 
				
			||||||
from pygments.formatters import HtmlFormatter
 | 
					from pygments.formatters import HtmlFormatter
 | 
				
			||||||
from pygments.util import ClassNotFound
 | 
					from pygments.util import ClassNotFound
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
from typing import Union
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
from .whitespace import NBSP
 | 
					from .whitespace import NBSP
 | 
				
			||||||
from .transform import FQuoted
 | 
					from .transform import FQuoted
 | 
				
			||||||
| 
						 | 
					@ -13,7 +12,7 @@ from .util import inlinify
 | 
				
			||||||
from .context import Group
 | 
					from .context import Group
 | 
				
			||||||
from .images import ImageProcessor
 | 
					from .images import ImageProcessor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def html(e: Union[Element, ListContainer], k: KatexClient, i: ImageProcessor, indent_level: int=0, indent_str: str="\t") -> str:
 | 
					def html(e: Element, k: KatexClient, i: ImageProcessor, indent_level: int=0, indent_str: str="\t") -> str:
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	# `only` attribute which makes transformed elements appear only in tex
 | 
						# `only` attribute which makes transformed elements appear only in tex
 | 
				
			||||||
	# output or html output
 | 
						# output or html output
 | 
				
			||||||
| 
						 | 
					@ -41,7 +40,7 @@ def html(e: Union[Element, ListContainer], k: KatexClient, i: ImageProcessor, in
 | 
				
			||||||
		Emph: "em",
 | 
							Emph: "em",
 | 
				
			||||||
		Caption: "figcaption",
 | 
							Caption: "figcaption",
 | 
				
			||||||
		Para: "p",
 | 
							Para: "p",
 | 
				
			||||||
		Header: "h"+str(e.level) if isinstance(e, Header) else "",
 | 
							Header: "h"+str(e.level) if hasattr(e, "level") else "",
 | 
				
			||||||
		LineBlock: "p",
 | 
							LineBlock: "p",
 | 
				
			||||||
		ListItem: "li",
 | 
							ListItem: "li",
 | 
				
			||||||
		SmallCaps: "span",
 | 
							SmallCaps: "span",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,4 @@
 | 
				
			||||||
from typing import List, Union
 | 
					from typing import List
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import shutil
 | 
					import shutil
 | 
				
			||||||
import subprocess
 | 
					import subprocess
 | 
				
			||||||
| 
						 | 
					@ -74,7 +74,7 @@ class ImageProcessor:
 | 
				
			||||||
		return Image.open(full_path).size
 | 
							return Image.open(full_path).size
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	def find_image(self, input_filename: str, additional_dirs: List[str]=[]) -> Union[str, None]:
 | 
						def find_image(self, input_filename: str, additional_dirs: List[str]=[]) -> str:
 | 
				
			||||||
		for dir in [*self.lookup_dirs, *additional_dirs]:
 | 
							for dir in [*self.lookup_dirs, *additional_dirs]:
 | 
				
			||||||
			if os.path.isfile(dir + "/" + input_filename):
 | 
								if os.path.isfile(dir + "/" + input_filename):
 | 
				
			||||||
				return dir + "/" + input_filename
 | 
									return dir + "/" + input_filename
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										30
									
								
								src/formatitko/katex-server/package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										30
									
								
								src/formatitko/katex-server/package-lock.json
									
									
									
										generated
									
									
									
								
							| 
						 | 
					@ -1,38 +1,20 @@
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  "name": "ksp-katex-server",
 | 
					  "name": "ksp-katex-server",
 | 
				
			||||||
  "version": "1.0.0",
 | 
					  "version": "1.0.0",
 | 
				
			||||||
  "lockfileVersion": 3,
 | 
					  "lockfileVersion": 1,
 | 
				
			||||||
  "requires": true,
 | 
					  "requires": true,
 | 
				
			||||||
  "packages": {
 | 
					  "dependencies": {
 | 
				
			||||||
    "": {
 | 
					    "commander": {
 | 
				
			||||||
      "name": "ksp-katex-server",
 | 
					 | 
				
			||||||
      "version": "1.0.0",
 | 
					 | 
				
			||||||
      "license": "ISC",
 | 
					 | 
				
			||||||
      "dependencies": {
 | 
					 | 
				
			||||||
        "katex": "^0.16.3"
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
    "node_modules/commander": {
 | 
					 | 
				
			||||||
      "version": "8.3.0",
 | 
					      "version": "8.3.0",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/commander/-/commander-8.3.0.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/commander/-/commander-8.3.0.tgz",
 | 
				
			||||||
      "integrity": "sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==",
 | 
					      "integrity": "sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww=="
 | 
				
			||||||
      "engines": {
 | 
					 | 
				
			||||||
        "node": ">= 12"
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "node_modules/katex": {
 | 
					    "katex": {
 | 
				
			||||||
      "version": "0.16.3",
 | 
					      "version": "0.16.3",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/katex/-/katex-0.16.3.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/katex/-/katex-0.16.3.tgz",
 | 
				
			||||||
      "integrity": "sha512-3EykQddareoRmbtNiNEDgl3IGjryyrp2eg/25fHDEnlHymIDi33bptkMv6K4EOC2LZCybLW/ZkEo6Le+EM9pmA==",
 | 
					      "integrity": "sha512-3EykQddareoRmbtNiNEDgl3IGjryyrp2eg/25fHDEnlHymIDi33bptkMv6K4EOC2LZCybLW/ZkEo6Le+EM9pmA==",
 | 
				
			||||||
      "funding": [
 | 
					      "requires": {
 | 
				
			||||||
        "https://opencollective.com/katex",
 | 
					 | 
				
			||||||
        "https://github.com/sponsors/katex"
 | 
					 | 
				
			||||||
      ],
 | 
					 | 
				
			||||||
      "dependencies": {
 | 
					 | 
				
			||||||
        "commander": "^8.0.0"
 | 
					        "commander": "^8.0.0"
 | 
				
			||||||
      },
 | 
					 | 
				
			||||||
      "bin": {
 | 
					 | 
				
			||||||
        "katex": "cli.js"
 | 
					 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,7 @@ import tempfile
 | 
				
			||||||
import json
 | 
					import json
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
from typing import Dict
 | 
					from typing import Dict
 | 
				
			||||||
 | 
					import time
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class KatexError(Exception):
 | 
					class KatexError(Exception):
 | 
				
			||||||
| 
						 | 
					@ -65,5 +66,5 @@ class KatexClient:
 | 
				
			||||||
	def __enter__(self):
 | 
						def __enter__(self):
 | 
				
			||||||
		return self
 | 
							return self
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	def __exit__(self):
 | 
						def __exit__(self, type, value, tb):
 | 
				
			||||||
		self._server_process.terminate()
 | 
							self._server_process.terminate()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,7 +3,7 @@
 | 
				
			||||||
###
 | 
					###
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import sys, re
 | 
					import sys, re
 | 
				
			||||||
from panflute import Str, Element, ListContainer, DictContainer
 | 
					from panflute import *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
avoid_keys = {
 | 
					avoid_keys = {
 | 
				
			||||||
	'dict',
 | 
						'dict',
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,5 @@
 | 
				
			||||||
from panflute import *
 | 
					from panflute import *
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
from typing import Union
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
from .whitespace import NBSP
 | 
					from .whitespace import NBSP
 | 
				
			||||||
from .transform import FQuoted
 | 
					from .transform import FQuoted
 | 
				
			||||||
| 
						 | 
					@ -9,7 +8,7 @@ from .context import Group
 | 
				
			||||||
from .images import ImageProcessor
 | 
					from .images import ImageProcessor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Heavily inspired by: git://git.ucw.cz/labsconf2022.git
 | 
					# Heavily inspired by: git://git.ucw.cz/labsconf2022.git
 | 
				
			||||||
def tex(e: Union[Element, ListContainer], i: ImageProcessor, indent_level: int=0, indent_str: str="\t") -> str:
 | 
					def tex(e: Element, i: ImageProcessor, indent_level: int=0, indent_str: str="\t") -> str:
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	# `only` attribute which makes transformed elements appear only in tex
 | 
						# `only` attribute which makes transformed elements appear only in tex
 | 
				
			||||||
	# output or html output
 | 
						# output or html output
 | 
				
			||||||
| 
						 | 
					@ -31,7 +30,7 @@ def tex(e: Union[Element, ListContainer], i: ImageProcessor, indent_level: int=0
 | 
				
			||||||
	tag = e.tag.lower()
 | 
						tag = e.tag.lower()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tags = {
 | 
						tags = {
 | 
				
			||||||
		Header: "h"+chr(64 + e.level) if isinstance(e, Header) else "",
 | 
							Header: "h"+chr(64 + e.level) if hasattr(e, "level") else "",
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if type(e) in tags:
 | 
						if type(e) in tags:
 | 
				
			||||||
		tag = tags[type(e)]
 | 
							tag = tags[type(e)]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,11 +1,11 @@
 | 
				
			||||||
from panflute import Element, Div, Span, Quoted, Image, CodeBlock, Str, MetaInlines, MetaStr, MetaBool
 | 
					from panflute import *
 | 
				
			||||||
import re
 | 
					import re
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Import local files
 | 
					# Import local files
 | 
				
			||||||
from .whitespace import Whitespace, NBSP, bavlna
 | 
					from .whitespace import *
 | 
				
			||||||
from .command import Command, BlockCommand, InlineCommand, handle_command_define, executeCommand
 | 
					from .command import *
 | 
				
			||||||
from .util import nullify, import_md
 | 
					from .util import *
 | 
				
			||||||
from .context import Context, Group
 | 
					from .context import *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# This is a small extension to the Quoted panflute elements which allows to
 | 
					# This is a small extension to the Quoted panflute elements which allows to
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue