Skip to content
Closed
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
12 changes: 10 additions & 2 deletions md2misc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
from .core import convert, convert_schelp, default_template
from .errors_warnings import DocumentError, Md2miscError, Md2miscWarning, ParsingException, UnsupportedConstruct

__all__ = ["convert", "convert_schelp", "default_template",
"Md2miscError", "Md2miscWarning", "DocumentError", "ParsingException", "UnsupportedConstruct"]
__all__ = [
"convert",
"convert_schelp",
"default_template",
"Md2miscError",
"Md2miscWarning",
"DocumentError",
"ParsingException",
"UnsupportedConstruct",
]
5 changes: 2 additions & 3 deletions md2misc/backends/minted.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# --------------------------------------------------------------------------
# list of languages supported by pygments/minted (01.11.2024)
# source: https://pygments.org/languages/
Expand Down Expand Up @@ -909,5 +908,5 @@
"bro",
"zephir",
"zig",
"zone"
]
"zone",
]
212 changes: 147 additions & 65 deletions md2misc/backends/schelp.py

Large diffs are not rendered by default.

22 changes: 16 additions & 6 deletions md2misc/backends/tex.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ class TeXBackend(Backend):
"article": ["section", "subsection", "subsubsection"],
"book": ["chapter", "section", "subsection", "subsubsection"],
}
def __init__(self, unnumbered: bool = False, document_class: str = "article",
minted_language: str = "text", override_language: bool = False):

def __init__(
self,
unnumbered: bool = False,
document_class: str = "article",
minted_language: str = "text",
override_language: bool = False,
):
self.unnumbered = unnumbered
self.document_class = document_class
self.minted_language = minted_language
Expand All @@ -47,7 +53,7 @@ def escape(self, string: str) -> str:
string = string.replace("$", r"\$")
string = string.replace("%", r"\%")
string = string.replace(r"$", r"\&")
#string = string.replace(r"~", r"\~") # leads to an error if ~ is used in an inline quote
# string = string.replace(r"~", r"\~") # leads to an error if ~ is used in an inline quote
string = string.replace("_", r"\_")
string = string.replace("&", r"\&")
string = re.sub(r"\^", r"\\^", string, flags=re.M)
Expand Down Expand Up @@ -199,7 +205,7 @@ def code_block(self, code: str, language: str = None, title: str = None, highlig

# titles are converted to captions
if title:
env = env.replace("@@CAPTIONTOKEN@@", r'\caption{' + title + r'}')
env = env.replace("@@CAPTIONTOKEN@@", r"\caption{" + title + r"}")
else: # remove captiontoken line
env = env.replace("@@CAPTIONTOKEN@@\n", "")

Expand Down Expand Up @@ -246,6 +252,10 @@ def clean(self, string: str) -> str:
# string = re.sub(r"{\s+", r"{", string, flags=re.M) # remove whitespace after opening curly brace
# string = re.sub(r"\s+}", r"}", string, flags=re.M) # remove whitespace before closing curly brace
string = re.sub(r"\n{2,}", r"\n\n", string, flags=re.M) # reduce 2+ consecutive newlines to 2
string = re.sub(r"(\\begin\{.*?)\n{2,}", r"\1\n", string, flags=re.M) # replace multiple consecutive newlines after \begin with just one
string = re.sub(r"\n{2,}( *\\end\{)", r"\n\1", string, flags=re.M) # replace multiple consecutive newlines before \end with just one
string = re.sub(
r"(\\begin\{.*?)\n{2,}", r"\1\n", string, flags=re.M
) # replace multiple consecutive newlines after \begin with just one
string = re.sub(
r"\n{2,}( *\\end\{)", r"\n\1", string, flags=re.M
) # replace multiple consecutive newlines before \end with just one
return string
12 changes: 8 additions & 4 deletions md2misc/citations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
the output of Pandoc is its JSON form (the document tree), so that the text of a citation does not need to be
read as Markdown again.
"""

import json
import os
import shutil
Expand All @@ -25,8 +26,10 @@ def find_pandoc() -> str:
"""
path = os.environ.get("PANDOC") or shutil.which("pandoc")
if not path:
raise DocumentError("citations need the program `pandoc`: put it on the PATH, or set the environment "
"variable PANDOC to its path")
raise DocumentError(
"citations need the program `pandoc`: put it on the PATH, or set the environment "
"variable PANDOC to its path"
)
return path


Expand All @@ -45,8 +48,9 @@ def process(citations: list, bibliography) -> tuple:
source = "".join(citation + "\n\n" for citation in citations) + "::: {#refs}\n:::\n"
pandoc = find_pandoc()
try:
done = subprocess.run([pandoc, *PANDOC_ARGUMENTS, "--bibliography", str(path)],
input=source, capture_output=True, text=True)
done = subprocess.run(
[pandoc, *PANDOC_ARGUMENTS, "--bibliography", str(path)], input=source, capture_output=True, text=True
)
except OSError as error:
raise DocumentError(f"md2misc could not run pandoc (`{pandoc}`): {error}") from error
if done.returncode != 0:
Expand Down
Loading
Loading