Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ARXIVCE-2905] Support HTML submissions #78

Merged
merged 4 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions preflight_parser/preflight_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

MODULE_PATH = os.path.dirname(__file__)

PDF_SUBMISSION_STRING = "pdf_submission"
HTML_SUBMISSION_STRING = "html_submission"

#
# CLASSES AND TYPES
#
Expand Down Expand Up @@ -62,13 +65,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 @@ -211,7 +217,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 @@ -229,7 +237,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 @@ -238,12 +248,18 @@ def tex_compiler(self) -> str | None:

def from_compiler_string(self, compiler: str):
"""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 @@ -953,8 +969,15 @@ def parse_dir(rundir) -> 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
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 preflight_parser/tests/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 preflight_parser/tests/test_preflight.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,19 @@ def test_preflight_pdf_only_submission(self):
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"
)
Loading