Skip to content

Commit

Permalink
Merge branch 'master' into triple-package
Browse files Browse the repository at this point in the history
  • Loading branch information
norbusan committed Dec 10, 2024
2 parents 26b9886 + e23bd02 commit ef1b2b6
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 5 deletions.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions tex2pdf-tools/tests/preflight_parser/fixture/html_1/paper.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd"><html lang='eng'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title>HTML Submission Test</title>
</head>

<body>
<center>
Hello World
</center>
</body>
</html>

16 changes: 16 additions & 0 deletions tex2pdf-tools/tests/preflight_parser/test_preflight.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,19 @@ def test_preflight_pdf_only_submission(self):
"""{"engine": "unknown", "lang": "pdf", "output": "unknown", "postp": "none"}""",
)
self.assertEqual(pf.detected_toplevel_files[0].process.compiler.compiler_string, "pdf_submission")

def test_preflight_html_only_submission(self):
"""Test HTML only submission."""
dir_path = os.path.join(self.fixture_dir, "html_1")
pf: PreflightResponse = generate_preflight_response(dir_path)
self.assertEqual(pf.status.key.value, "success")
self.assertEqual(len(pf.detected_toplevel_files), 1)
self.assertEqual(pf.detected_toplevel_files[0].filename, "paper.html")
self.assertEqual(
pf.detected_toplevel_files[0].process.compiler.json(exclude_none=True, exclude_defaults=True),
"""{"engine": "unknown", "lang": "html", "output": "unknown", "postp": "none"}""",
)
self.assertEqual(
pf.detected_toplevel_files[0].process.compiler.compiler_string,
"html_submission"
)
32 changes: 27 additions & 5 deletions tex2pdf-tools/tex2pdf_tools/preflight_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

MODULE_PATH = os.path.dirname(__file__)


T = TypeVar("T")

PDF_SUBMISSION_STRING = "pdf_submission"
HTML_SUBMISSION_STRING = "html_submission"

#
# CLASSES AND TYPES
#
Expand Down Expand Up @@ -66,13 +68,16 @@ class LanguageType(str, Enum):
TEX does not allow compiling as latex, e.g., because it contains \bye
LATEX does not allow compiling as plain tex, e.g., because it contains \documentclass
PDF is for PDF only submissions.
HTML is for HTML only submissions.
UNKNOWN allows compilation as either TEX or LATEX.
"""

unknown = "unknown"
tex = "tex"
latex = "latex"
pdf = "pdf"
html = "html"


class EngineType(str, Enum):
Expand Down Expand Up @@ -215,7 +220,9 @@ def compiler_string(self) -> str | None:
"""Convert Language/Output/Engine/PostProcess to compiler string."""
# first deal with PDF only submissions:
if self.lang.value == "pdf":
return "pdf_submission"
return PDF_SUBMISSION_STRING
if self.lang.value == "html":
return HTML_SUBMISSION_STRING
if self.lang in self._COMPILER_SELECTION:
if self.output in self._COMPILER_SELECTION[self.lang]:
if self.engine in self._COMPILER_SELECTION[self.lang][self.output]:
Expand All @@ -233,7 +240,9 @@ def tex_compiler(self) -> str | None:
"""Return the TeX compiler to be used."""
# first deal with PDF only submissions:
if self.lang.value == "pdf":
return "pdf_submission"
return PDF_SUBMISSION_STRING
if self.lang.value == "html":
return HTML_SUBMISSION_STRING
if self.lang in self._COMPILER_SELECTION:
if self.output in self._COMPILER_SELECTION[self.lang]:
if self.engine in self._COMPILER_SELECTION[self.lang][self.output]:
Expand All @@ -242,12 +251,18 @@ def tex_compiler(self) -> str | None:

def from_compiler_string(self, compiler: str) -> None:
"""Convert compiler string to Language/Output/Engine/PostProcess types."""
if compiler == "pdf_submission":
if compiler == PDF_SUBMISSION_STRING:
self.lang = LanguageType.pdf
self.engine = EngineType.unknown
self.output = OutputType.unknown
self.postp = PostProcessType.none
return
if compiler == HTML_SUBMISSION_STRING:
self.lang = LanguageType.html
self.engine = EngineType.unknown
self.output = OutputType.unknown
self.postp = PostProcessType.none
return
parts = compiler.split("+", 1)
comp: str = ""
if len(parts) == 2:
Expand Down Expand Up @@ -955,8 +970,15 @@ def parse_dir(rundir: str) -> dict[str, ParsedTeXFile] | ToplevelFile:
if len(files) == 1 and files[0].lower().endswith(".pdf"):
# PDF only submission, only one PDF file, nothing else
return ToplevelFile(
filename=files[0], process=MainProcessSpec(compiler=CompilerSpec(compiler="pdf_submission"))
filename=files[0], process=MainProcessSpec(compiler=CompilerSpec(compiler=PDF_SUBMISSION_STRING))
)
else:
# check for HTML submissions
for f in sorted(files):
if f.lower().endswith(".html"):
return ToplevelFile(
filename=f, process=MainProcessSpec(compiler=CompilerSpec(compiler=HTML_SUBMISSION_STRING))
)
nodes = {f: parse_file(rundir, f) for f in tex_files}
# print(nodes)
return nodes
Expand Down

0 comments on commit ef1b2b6

Please sign in to comment.