From 18d443b354d7a933f449eaf94a2c7c7619a1a3fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Bal=C3=A1=C5=BE?= Date: Tue, 26 Dec 2023 14:56:48 +0000 Subject: [PATCH] Updates to convertor --- core/builder/convertor.py | 5 ++--- core/markdown-check.py | 21 ++++++++++++++++++--- core/mdcheck/exceptions.py | 7 +++++++ core/tests/test_convertor.py | 6 ++++-- core/tex/dgs.cls | 3 ++- modules/seminar/builder/validators.py | 2 +- 6 files changed, 34 insertions(+), 10 deletions(-) diff --git a/core/builder/convertor.py b/core/builder/convertor.py index 178944aa..1a78f235 100644 --- a/core/builder/convertor.py +++ b/core/builder/convertor.py @@ -128,9 +128,7 @@ def __init__(self, output_format: str, locale_code: str, infile, outfile, **opti ] self.pre_regexes['all'] += [ - RegexReplacement(r'^!include (?P[\w]+)', - fr'!include {Path(self.infile.name).parent}/\g', - purpose="Include code listing"), + # Currently nothing ] self.pre_checks = self._filter_regexes(self.pre_checks) @@ -229,6 +227,7 @@ def call_pandoc(self): #"-M", "cref=true", "--filter", "pandoc-eqnos", "--filter", "pandoc-include", + "-M", f"include-entry={Path(self.infile.name).parent}/", "--filter", "pandoc-minted", "--lua-filter", "./core/filters/quotes.lua", ] diff --git a/core/markdown-check.py b/core/markdown-check.py index 0e5b8141..d38b677d 100755 --- a/core/markdown-check.py +++ b/core/markdown-check.py @@ -1,6 +1,8 @@ #!/usr/bin/env python3 import argparse, os, sys, re, copy +import subprocess +import tempfile from pathlib import Path @@ -57,10 +59,10 @@ def __init__(self): def check(self): for filename in self.args.infiles: - if self.check_markdown_file(filename): - pass + self.check_markdown(filename) + self.check_lines(filename) - def check_markdown_file(self, file): + def check_lines(self, file): path = Path(file.name) problem_id = Path(file.name).parent.stem @@ -94,6 +96,19 @@ def check_markdown_file(self, file): if self.args.verbose and ok: print(f"File {c.path(file.name)} {c.ok('OK')}") + return ok + + def check_markdown(self, file): + path = Path(file.name) + output = tempfile.SpooledTemporaryFile() + out = subprocess.check_output(['pandoc', '--from', 'markdown+smart', '--to', 'native', path], encoding='utf-8').split("\n") + + for line in out: + try: + if matches := re.match(r'.*(Format "tex").*(?P\\\\(SI|num){.*}{.*})', line): + raise exceptions.MarkdownError(f"Raw siunitx token \"{matches.group('si')}\"") + except exceptions.MarkdownError as e: + print(e.message) def check_line(self, checker, file, number, line, *, cfunc=c.err): if self.commented.match(line): diff --git a/core/mdcheck/exceptions.py b/core/mdcheck/exceptions.py index 5739c644..180e07be 100644 --- a/core/mdcheck/exceptions.py +++ b/core/mdcheck/exceptions.py @@ -18,3 +18,10 @@ class EncodingError(Exception): def __init__(self, message): super().__init__(message) self.message = message + + +class MarkdownError(Exception): + def __init__(self, message): + super().__init__(message) + self.message = message + diff --git a/core/tests/test_convertor.py b/core/tests/test_convertor.py index a0d15890..98a19688 100644 --- a/core/tests/test_convertor.py +++ b/core/tests/test_convertor.py @@ -61,7 +61,8 @@ def test_english(self, convert): class TestImages: def test_image_latex(self, convert): output = convert('latex', 'sk', '![Masívna ryba](ryba.svg){#fig:ryba height=47mm}') - assert r'\insertPicture[width=\textwidth,height=47mm]{ryba.pdf}' in output + assert r'\insertPicture[width=\textwidth,height=47mm]' in output + assert 'ryba.pdf' in output def test_image_latex_multiline(self, convert): output = convert('latex', 'sk', """ @@ -69,7 +70,8 @@ def test_image_latex_multiline(self, convert): Veľmi masívne. Aj s newlinami.](subor.png){#fig:dlhy height=53mm} """) - assert re.search(r'\\insertPicture\[width=\\textwidth,height=53mm]{subor\.png}', output) is not None + assert r'\insertPicture[width=\textwidth,height=53mm]' in output + assert 'subor.png' in output def test_image_html(self, convert): output = convert('html', 'sk', '![Masívna ryba](ryba.svg){#fig:ryba height=47mm}') diff --git a/core/tex/dgs.cls b/core/tex/dgs.cls index 467b6a8f..32eacbdb 100644 --- a/core/tex/dgs.cls +++ b/core/tex/dgs.cls @@ -88,7 +88,8 @@ russian, polish, spanish, - english + english, + shorthands=off, ]{babel} % multi-language support \RequirePackage{xunicode} \RequirePackage{cleveref} diff --git a/modules/seminar/builder/validators.py b/modules/seminar/builder/validators.py index f482433a..70c9e34d 100644 --- a/modules/seminar/builder/validators.py +++ b/modules/seminar/builder/validators.py @@ -8,7 +8,7 @@ class SeminarRoundValidator(FileSystemValidator): Regex(r'0[1-8]'): { 'problem.md': File, 'solution.md': File, - Optional(Regex(r'[\w-]+\.(png|jpg|svg|gp|py|dat)')): File, + Optional(Regex(r'[\w-]+\.(png|jpg|svg|gp|py|cpp|dat)')): File, 'meta.yaml': File, }, 'meta.yaml': File,