Skip to content

Commit

Permalink
Updates to convertor
Browse files Browse the repository at this point in the history
  • Loading branch information
sesquideus committed Dec 26, 2023
1 parent ede2ef7 commit 18d443b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
5 changes: 2 additions & 3 deletions core/builder/convertor.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ def __init__(self, output_format: str, locale_code: str, infile, outfile, **opti
]

self.pre_regexes['all'] += [
RegexReplacement(r'^!include (?P<path>[\w]+)',
fr'!include {Path(self.infile.name).parent}/\g<path>',
purpose="Include code listing"),
# Currently nothing
]

self.pre_checks = self._filter_regexes(self.pre_checks)
Expand Down Expand Up @@ -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",
]
Expand Down
21 changes: 18 additions & 3 deletions core/markdown-check.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python3

import argparse, os, sys, re, copy
import subprocess
import tempfile

from pathlib import Path

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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>\\\\(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):
Expand Down
7 changes: 7 additions & 0 deletions core/mdcheck/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

6 changes: 4 additions & 2 deletions core/tests/test_convertor.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,17 @@ 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', """
![Veľmi dlhý text. Akože masívne.
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}')
Expand Down
3 changes: 2 additions & 1 deletion core/tex/dgs.cls
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@
russian,
polish,
spanish,
english
english,
shorthands=off,
]{babel} % multi-language support
\RequirePackage{xunicode}
\RequirePackage{cleveref}
Expand Down
2 changes: 1 addition & 1 deletion modules/seminar/builder/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 18d443b

Please sign in to comment.