mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-06 15:03:15 +02:00
feat: document_class function
This commit is contained in:
parent
78829e7391
commit
39466ca0aa
0
program/code/error_messages/__init__.py
Normal file
0
program/code/error_messages/__init__.py
Normal file
12
program/code/error_messages/error_arrays.py
Normal file
12
program/code/error_messages/error_arrays.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
error_arrays = [
|
||||||
|
"Error! No input given to document_class function",
|
||||||
|
"Error! documentclass curly bracket not closed!",
|
||||||
|
"Error! documentclass has optional parameters!",
|
||||||
|
"Error! documentclass curly bracket not opened!",
|
||||||
|
"Error! documentclass command misspeled!",
|
||||||
|
"Error! class is not known!",
|
||||||
|
"Error! documentclass has no slash at begining"
|
||||||
|
]
|
||||||
|
|
||||||
|
def return_error_arrays():
|
||||||
|
return error_arrays
|
||||||
@ -1,446 +1,9 @@
|
|||||||
"""
|
"""
|
||||||
Holds an array of all classes from https://ctan.org/topic/class
|
Holds an array of all classes from https://ctan.org/topic/class
|
||||||
"""
|
"""
|
||||||
classes = [
|
classes = ['article', 'report', 'book', 'beamer', 'letter', 'memoir', 'slides', 'IEEEtran', 'exam', 'amsart', 'amsbook', 'tufte-book', 'scrartcl', 'scrreprt', 'moderncv', 'cv', 'res', 'elsarticle', 'acm_proc_article-sp', 'scrbook']
|
||||||
"abntex2",
|
|
||||||
"acmart",
|
|
||||||
"acmconf",
|
|
||||||
"acmsiggraph",
|
|
||||||
"actapress",
|
|
||||||
"adelaide-thesis",
|
|
||||||
"afthesis",
|
|
||||||
"aguplus",
|
|
||||||
"amsart",
|
|
||||||
"amsbook",
|
|
||||||
"amsproc",
|
|
||||||
"amsrefs",
|
|
||||||
"apa6",
|
|
||||||
"apa7",
|
|
||||||
"apa",
|
|
||||||
"arabbook",
|
|
||||||
"articleingud",
|
|
||||||
"asaetr",
|
|
||||||
"ascelike",
|
|
||||||
"assignment",
|
|
||||||
"beamer",
|
|
||||||
"bgteubner",
|
|
||||||
"bookman",
|
|
||||||
"booktabs",
|
|
||||||
"cascadilla",
|
|
||||||
"cascdoc",
|
|
||||||
"casconky",
|
|
||||||
"cd",
|
|
||||||
"charter",
|
|
||||||
"chem-journal",
|
|
||||||
"chicago",
|
|
||||||
"cje",
|
|
||||||
"cls-bst-ex",
|
|
||||||
"cmactex",
|
|
||||||
"cmbright",
|
|
||||||
"cmpj",
|
|
||||||
"coclass",
|
|
||||||
"codeanatomy",
|
|
||||||
"concepts",
|
|
||||||
"conference-omega",
|
|
||||||
"constitution",
|
|
||||||
"context",
|
|
||||||
"cooking-units",
|
|
||||||
"coseoul",
|
|
||||||
"crimson",
|
|
||||||
"cslatex",
|
|
||||||
"csthesis",
|
|
||||||
"dcu",
|
|
||||||
"dinbrief",
|
|
||||||
"docbook",
|
|
||||||
"dtk",
|
|
||||||
"dtucolor",
|
|
||||||
"dvgloss",
|
|
||||||
"easychair",
|
|
||||||
"ebsthesis",
|
|
||||||
"ecothesis",
|
|
||||||
"edge",
|
|
||||||
"egs",
|
|
||||||
"eiadoc",
|
|
||||||
"elsarticle",
|
|
||||||
"els-cas-templates",
|
|
||||||
"els-cas-templates-3.0",
|
|
||||||
"elsdoc",
|
|
||||||
"emisa",
|
|
||||||
"engtlc",
|
|
||||||
"erdc",
|
|
||||||
"eskd",
|
|
||||||
"eth-biblatex",
|
|
||||||
"ethz-thesis",
|
|
||||||
"europasscv",
|
|
||||||
"exercise",
|
|
||||||
"expdlist",
|
|
||||||
"fancyslides",
|
|
||||||
"fei",
|
|
||||||
"feiinput",
|
|
||||||
"fhnw",
|
|
||||||
"fithesis",
|
|
||||||
"fkssd",
|
|
||||||
"flashcards",
|
|
||||||
"flippdf",
|
|
||||||
"fontinst",
|
|
||||||
"fonts-tlwg",
|
|
||||||
"frankenstein",
|
|
||||||
"frege",
|
|
||||||
"gaceta",
|
|
||||||
"galois",
|
|
||||||
"gatech-thesis",
|
|
||||||
"gzt",
|
|
||||||
"hacm",
|
|
||||||
"hagenberg-thesis",
|
|
||||||
"har2nat",
|
|
||||||
"harvard",
|
|
||||||
"hecthese",
|
|
||||||
"hep",
|
|
||||||
"hepthesis",
|
|
||||||
"herm-pic",
|
|
||||||
"hithesis",
|
|
||||||
"holtpolt",
|
|
||||||
"html-book",
|
|
||||||
"hustthesis",
|
|
||||||
"hwk-mactex",
|
|
||||||
"ieeetran",
|
|
||||||
"ifacconf",
|
|
||||||
"ifmbe",
|
|
||||||
"igm",
|
|
||||||
"ijsra",
|
|
||||||
"illcdiss",
|
|
||||||
"imsproc",
|
|
||||||
"imsproc-accepted",
|
|
||||||
"imsproc-nrc",
|
|
||||||
"informs3",
|
|
||||||
"informs4",
|
|
||||||
"isomath",
|
|
||||||
"issuulinks",
|
|
||||||
"iwhdp",
|
|
||||||
"jacow",
|
|
||||||
"jmlr",
|
|
||||||
"jnlpba",
|
|
||||||
"jpsj",
|
|
||||||
"kluwer",
|
|
||||||
"koma-moderncvclassic",
|
|
||||||
"ksp-thesis",
|
|
||||||
"kurier",
|
|
||||||
"l2picfaq",
|
|
||||||
"laa",
|
|
||||||
"laboratorybook",
|
|
||||||
"latex2e-help-texinfo",
|
|
||||||
"latex2man",
|
|
||||||
"latex2rtf",
|
|
||||||
"latex4wp",
|
|
||||||
"latexbug",
|
|
||||||
"latexdiff",
|
|
||||||
"latexfileversion",
|
|
||||||
"latexindent",
|
|
||||||
"latexmp",
|
|
||||||
"latex-notes-zh-cn",
|
|
||||||
"latex-refsheet",
|
|
||||||
"latex-subfiles",
|
|
||||||
"latex-tabellen",
|
|
||||||
"latex-tools",
|
|
||||||
"latex-uni8",
|
|
||||||
"layout",
|
|
||||||
"lcyw",
|
|
||||||
"letter1",
|
|
||||||
"letter2",
|
|
||||||
"lettergen",
|
|
||||||
"lettre",
|
|
||||||
"lexikon",
|
|
||||||
"linenofix",
|
|
||||||
"lingmacros",
|
|
||||||
"linguex",
|
|
||||||
"listings-ext",
|
|
||||||
"logsys",
|
|
||||||
"longnamefilelist",
|
|
||||||
"lplfitch",
|
|
||||||
"lps",
|
|
||||||
"lt3graph",
|
|
||||||
"ltx2any",
|
|
||||||
"ltxdockit",
|
|
||||||
"luatexja",
|
|
||||||
"lxfonts",
|
|
||||||
"makecell",
|
|
||||||
"makecirc",
|
|
||||||
"makeplot",
|
|
||||||
"mandi",
|
|
||||||
"manfnt",
|
|
||||||
"manuscript",
|
|
||||||
"mathalfa",
|
|
||||||
"mathastext",
|
|
||||||
"mathdesign",
|
|
||||||
"mathdots",
|
|
||||||
"mathpartir",
|
|
||||||
"mathspec",
|
|
||||||
"mathspic",
|
|
||||||
"maths-symbols",
|
|
||||||
"maths-symbols-a4",
|
|
||||||
"matlab-prettifier",
|
|
||||||
"mdframed",
|
|
||||||
"memoir",
|
|
||||||
"mentis",
|
|
||||||
"mfnfss",
|
|
||||||
"mh",
|
|
||||||
"microtype",
|
|
||||||
"minifp",
|
|
||||||
"mla-paper",
|
|
||||||
"mlacls",
|
|
||||||
"mlbib",
|
|
||||||
"moderncv",
|
|
||||||
"moderntimeline",
|
|
||||||
"modular",
|
|
||||||
"mparhack",
|
|
||||||
"msc",
|
|
||||||
"mugsthesis",
|
|
||||||
"musixguit",
|
|
||||||
"nag",
|
|
||||||
"natbib",
|
|
||||||
"newlfm",
|
|
||||||
"newpx",
|
|
||||||
"newspaper",
|
|
||||||
"newtx",
|
|
||||||
"nicefilelist",
|
|
||||||
"nidanfloat",
|
|
||||||
"nih",
|
|
||||||
"ntgclass",
|
|
||||||
"nwafu",
|
|
||||||
"ocg-p",
|
|
||||||
"ociamthesis",
|
|
||||||
"ocr-b-outline",
|
|
||||||
"ocropus",
|
|
||||||
"octavo",
|
|
||||||
"odsfile",
|
|
||||||
"ojps",
|
|
||||||
"opteng",
|
|
||||||
"osa",
|
|
||||||
"overlays",
|
|
||||||
"oztex",
|
|
||||||
"pacioli",
|
|
||||||
"paper",
|
|
||||||
"parallel",
|
|
||||||
"phd",
|
|
||||||
"phfnote",
|
|
||||||
"philosophy-doc-ru",
|
|
||||||
"phonenumbers",
|
|
||||||
"physconst",
|
|
||||||
"physor2016",
|
|
||||||
"piff",
|
|
||||||
"pitex",
|
|
||||||
"pkuthss",
|
|
||||||
"placeins",
|
|
||||||
"plaintex",
|
|
||||||
"play",
|
|
||||||
"plipsum",
|
|
||||||
"poemscol",
|
|
||||||
"polynom",
|
|
||||||
"powerdot",
|
|
||||||
"pracjourn",
|
|
||||||
"proceedings",
|
|
||||||
"progress",
|
|
||||||
"prosper",
|
|
||||||
"pst-exa",
|
|
||||||
"pst-plot",
|
|
||||||
"publist",
|
|
||||||
"pxfonts",
|
|
||||||
"qcm",
|
|
||||||
"qobitree",
|
|
||||||
"quran",
|
|
||||||
"raman-thesis",
|
|
||||||
"rcs-multi",
|
|
||||||
"rechnung",
|
|
||||||
"refcheck",
|
|
||||||
"refman",
|
|
||||||
"resphilosophica",
|
|
||||||
"revquantum",
|
|
||||||
"rfc",
|
|
||||||
"rochester-thesis",
|
|
||||||
"romanbar",
|
|
||||||
"rotating",
|
|
||||||
"rsfso",
|
|
||||||
"rspublications",
|
|
||||||
"rticle",
|
|
||||||
"sageep",
|
|
||||||
"samplepdf",
|
|
||||||
"samplics",
|
|
||||||
"sansmath",
|
|
||||||
"sasnrdisplay",
|
|
||||||
"sasnrtext",
|
|
||||||
"schule",
|
|
||||||
"sciposter",
|
|
||||||
"scratch",
|
|
||||||
"sduthesis",
|
|
||||||
"seminar",
|
|
||||||
"seuthesis",
|
|
||||||
"sf298",
|
|
||||||
"sffms",
|
|
||||||
"sgame",
|
|
||||||
"shdoc",
|
|
||||||
"sig-alternate",
|
|
||||||
"sigcas",
|
|
||||||
"sigchi",
|
|
||||||
"siggraph",
|
|
||||||
"siggraph2015",
|
|
||||||
"siggraph-2016-schedule",
|
|
||||||
"siggraph-2017-schedule",
|
|
||||||
"siggraph-2018-schedule",
|
|
||||||
"siggraph-2019-schedule",
|
|
||||||
"siggraph-2020-schedule",
|
|
||||||
"siggraph-2021-schedule",
|
|
||||||
"siggraph-2022-schedule",
|
|
||||||
"siggraph-asia",
|
|
||||||
"siggraph-extended-abstracts",
|
|
||||||
"siggraph-talks",
|
|
||||||
"siggraph-videos",
|
|
||||||
"siggraph-virtual-reality-contest",
|
|
||||||
"sigirconf",
|
|
||||||
"simplecv",
|
|
||||||
"sistthesis",
|
|
||||||
"skaknew",
|
|
||||||
"slides",
|
|
||||||
"smalltalk",
|
|
||||||
"smfbook",
|
|
||||||
"spie",
|
|
||||||
"spin",
|
|
||||||
"splncs",
|
|
||||||
"statrep",
|
|
||||||
"stdclsdv",
|
|
||||||
"stdpage",
|
|
||||||
"stex",
|
|
||||||
"studenthandouts",
|
|
||||||
"subcaption",
|
|
||||||
"subeqn",
|
|
||||||
"subfiles",
|
|
||||||
"subfigure",
|
|
||||||
"subfigmat",
|
|
||||||
"suftesi",
|
|
||||||
"svclasses",
|
|
||||||
"svg-inkscape",
|
|
||||||
"swimgraf",
|
|
||||||
"swimte",
|
|
||||||
"sympytex",
|
|
||||||
"syntaxdi",
|
|
||||||
"tablists",
|
|
||||||
"tablor",
|
|
||||||
"tabriz-thesis",
|
|
||||||
"tabstackengine",
|
|
||||||
"tango",
|
|
||||||
"tcolorbox",
|
|
||||||
"tetex",
|
|
||||||
"tex",
|
|
||||||
"tex2tok",
|
|
||||||
"tex4ht",
|
|
||||||
"texapi",
|
|
||||||
"texdoc",
|
|
||||||
"texdraw",
|
|
||||||
"texfot",
|
|
||||||
"texi2dvi",
|
|
||||||
"texi2html",
|
|
||||||
"texi2roff",
|
|
||||||
"texinfo",
|
|
||||||
"texlive",
|
|
||||||
"texmacs",
|
|
||||||
"texmate",
|
|
||||||
"tex-overview",
|
|
||||||
"tex-ps",
|
|
||||||
"texsis",
|
|
||||||
"texsort",
|
|
||||||
"textcase",
|
|
||||||
"textfit",
|
|
||||||
"textglos",
|
|
||||||
"textmerg",
|
|
||||||
"textools",
|
|
||||||
"textpath",
|
|
||||||
"textpos",
|
|
||||||
"thucoursework",
|
|
||||||
"thucslide",
|
|
||||||
"thuthesis",
|
|
||||||
"tioga",
|
|
||||||
"tkz",
|
|
||||||
"toascii",
|
|
||||||
"tocloft",
|
|
||||||
"todonotes",
|
|
||||||
"tools",
|
|
||||||
"tpic2pdftex",
|
|
||||||
"tpx",
|
|
||||||
"trajan",
|
|
||||||
"tree-dvips",
|
|
||||||
"tufte-latex",
|
|
||||||
"turabian",
|
|
||||||
"turnstile",
|
|
||||||
"twoinone",
|
|
||||||
"uafthesis",
|
|
||||||
"ucthesis",
|
|
||||||
"ucsmonograph",
|
|
||||||
"ucthesis",
|
|
||||||
"udesoftec",
|
|
||||||
"uiucthesis",
|
|
||||||
"ukthesis",
|
|
||||||
"unamthesis",
|
|
||||||
"unamth-template",
|
|
||||||
"undthesis",
|
|
||||||
"unswcover",
|
|
||||||
"uothesis",
|
|
||||||
"upmethodology",
|
|
||||||
"uptex",
|
|
||||||
"uspatent",
|
|
||||||
"uowthesis",
|
|
||||||
"uowthesistitlepage",
|
|
||||||
"urlbst",
|
|
||||||
"utf8mex",
|
|
||||||
"uwthesis",
|
|
||||||
"uythesis",
|
|
||||||
"uzbek",
|
|
||||||
"vaucanson-g",
|
|
||||||
"vancouver",
|
|
||||||
"vandocument",
|
|
||||||
"varsfromjobname",
|
|
||||||
"vassiliev",
|
|
||||||
"verbasef",
|
|
||||||
"verse",
|
|
||||||
"vhistory",
|
|
||||||
"vita",
|
|
||||||
"vmargin",
|
|
||||||
"voss-mathmode",
|
|
||||||
"vpe",
|
|
||||||
"vrbexin",
|
|
||||||
"web-o-mints",
|
|
||||||
"widetable",
|
|
||||||
"williams",
|
|
||||||
"wordlike",
|
|
||||||
"wrapfig",
|
|
||||||
"wsemclassic",
|
|
||||||
"wsuipa",
|
|
||||||
"wtref",
|
|
||||||
"xassoccnt",
|
|
||||||
"xcite",
|
|
||||||
"xcomment",
|
|
||||||
"xdot",
|
|
||||||
"xepersian",
|
|
||||||
"xetex",
|
|
||||||
"xetexfontinfo",
|
|
||||||
"xfor",
|
|
||||||
"xgreek",
|
|
||||||
"xhfill",
|
|
||||||
"xifthen",
|
|
||||||
"xint",
|
|
||||||
"xkeyval",
|
|
||||||
"xmltex",
|
|
||||||
"xyling",
|
|
||||||
"xymtex",
|
|
||||||
"yathesis",
|
|
||||||
"yfonts",
|
|
||||||
"yhmath",
|
|
||||||
"youngtab",
|
|
||||||
"yplan",
|
|
||||||
"ytableau",
|
|
||||||
"ytext",
|
|
||||||
"ziffer",
|
|
||||||
"zhlipsum",
|
|
||||||
]
|
|
||||||
|
|
||||||
def latex_classes():
|
|
||||||
|
def return_latex_classes():
|
||||||
""" Returns latex classes array"""
|
""" Returns latex classes array"""
|
||||||
return classes
|
return classes
|
||||||
|
|||||||
@ -2,11 +2,33 @@
|
|||||||
Program for converting Latex files into html files
|
Program for converting Latex files into html files
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from latex_classes.latex_classes import latex_classes
|
from code.latex_classes.latex_classes import return_latex_classes
|
||||||
|
from code.error_messages.error_arrays import return_error_arrays
|
||||||
|
|
||||||
|
|
||||||
def document_class(latex_string):
|
def document_class(latex_string):
|
||||||
"""
|
r"""
|
||||||
Converts LaTeX documentclass method to html
|
Converts LaTeX documentclass method to html
|
||||||
|
\documentclass{article}
|
||||||
"""
|
"""
|
||||||
print(latex_classes)
|
error_arrays = return_error_arrays()
|
||||||
return latex_string
|
latex_classes = return_latex_classes()
|
||||||
|
if latex_string == "":
|
||||||
|
print(error_arrays[0])
|
||||||
|
return "Error!"
|
||||||
|
if "}" not in latex_string:
|
||||||
|
print(error_arrays[1])
|
||||||
|
return "Error!"
|
||||||
|
if latex_string[len("\\documentclass{") - 1] != "{":
|
||||||
|
print(error_arrays[3])
|
||||||
|
return "Error!"
|
||||||
|
if latex_string[0] != "\\":
|
||||||
|
print(error_arrays[6])
|
||||||
|
return "Error!"
|
||||||
|
document_type = latex_string[len("\\documentclass{"):(len(latex_string) - 1)]
|
||||||
|
if document_type not in latex_classes:
|
||||||
|
return f"Error! class {document_type} is not known!"
|
||||||
|
return "<!DOCTYPE html><html>"
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
document_class("")
|
||||||
|
|||||||
@ -2,19 +2,93 @@
|
|||||||
Tests document class function
|
Tests document class function
|
||||||
"""
|
"""
|
||||||
from code.main import document_class
|
from code.main import document_class
|
||||||
|
from code.error_messages.error_arrays import return_error_arrays
|
||||||
|
|
||||||
|
error_arrays = return_error_arrays()
|
||||||
|
|
||||||
|
|
||||||
# Write python tests for a function translating LaTeX documentclass to html
|
# Write python tests for a function translating LaTeX documentclass to html
|
||||||
def test_document_class():
|
def given_empty_then_error():
|
||||||
"""
|
"""
|
||||||
Given
|
Given: ""
|
||||||
When
|
When: N/A
|
||||||
Then
|
Then: Error message
|
||||||
|
"""
|
||||||
|
assert document_class("") == "Error!"
|
||||||
|
|
||||||
|
|
||||||
|
def given_not_closed_then_error():
|
||||||
|
"""
|
||||||
|
Given: "\\documentclass{article"
|
||||||
|
When: N/A
|
||||||
|
Then: Error message
|
||||||
|
"""
|
||||||
|
assert document_class("\\documentclass{article") == "Error!"
|
||||||
|
|
||||||
|
|
||||||
|
def given_parameters_then_error():
|
||||||
|
"""
|
||||||
|
Given: class parameters
|
||||||
|
When: N/A
|
||||||
|
Then: Error message
|
||||||
|
"""
|
||||||
|
assert document_class("\\documentclass[12pt]{article}") == "Error!"
|
||||||
|
|
||||||
|
|
||||||
|
def given_no_opening_then_error():
|
||||||
|
"""
|
||||||
|
Given: No opening curly bracket
|
||||||
|
When: N/A
|
||||||
|
Then: Error message
|
||||||
|
"""
|
||||||
|
assert document_class("\\documentclassarticle}") == "Error!"
|
||||||
|
|
||||||
|
|
||||||
|
def given_misspeled_then_error():
|
||||||
|
"""
|
||||||
|
Given: misspelled document class
|
||||||
|
When: N/A
|
||||||
|
Then: Error message
|
||||||
|
"""
|
||||||
|
assert document_class("\\documentclas{article}") == "Error!"
|
||||||
|
|
||||||
|
|
||||||
|
def given_class_not_recognized_then_error():
|
||||||
|
"""
|
||||||
|
Given: class not recognized
|
||||||
|
When: N/A
|
||||||
|
Then: Error message
|
||||||
|
"""
|
||||||
|
assert (
|
||||||
|
document_class("\\documentclass{idonotexist}")
|
||||||
|
== "Error! class idonotexist is not known!"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def given_no_slash_then_error():
|
||||||
|
"""
|
||||||
|
Given: no backslash at start
|
||||||
|
When: N/A
|
||||||
|
Then: Error message
|
||||||
|
"""
|
||||||
|
assert document_class("documentclass{article}") == "Error!"
|
||||||
|
|
||||||
|
|
||||||
|
def given_correct_then_html():
|
||||||
|
"""
|
||||||
|
Given: \\documentclass{article}
|
||||||
|
When: N/A
|
||||||
|
Then: <!DOCTYPE html><html>
|
||||||
"""
|
"""
|
||||||
assert document_class("") == "Error! No input given to document_class function"
|
|
||||||
assert document_class("\\documentclass{article}") == "<!DOCTYPE html><html>"
|
assert document_class("\\documentclass{article}") == "<!DOCTYPE html><html>"
|
||||||
assert document_class("\\documentclass{article") == "Error! documentclass curly bracket not closed!"
|
|
||||||
assert document_class("\\documentclass[12pt]{article}") == "Error! documentclass has optional parameters!"
|
|
||||||
assert document_class("\\documentclassarticle}") == "Error! documentclass curly bracket not opened!"
|
def test_document_class():
|
||||||
assert document_class("\\documentclas{article}") == "Error! documentclass command misspeled!"
|
given_correct_then_html()
|
||||||
assert document_class("\\documentclass{idonotexist}") == "Error! class idonotexist is not known!"
|
given_class_not_recognized_then_error()
|
||||||
|
given_empty_then_error()
|
||||||
|
given_misspeled_then_error()
|
||||||
|
given_no_opening_then_error()
|
||||||
|
given_not_closed_then_error()
|
||||||
|
given_no_slash_then_error()
|
||||||
|
given_parameters_then_error()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user