-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use katex_js_path when pre-rendering (#128)
* Use katex_js_path when pre-rendering * Try to point to non-existing file * Try to fix command line * Try to be more verbose * DEBUG * Add KATEX_PATH as class method * Try to point to actual katex.min.js * DEBUG * DEBUG * Fix error * DEBUG * Use relative path to katex.min.js * DEBUG * Check if ./../ works * Cleanup debug and comments * Build documentation without verbose output * Fix typo * Update sphinxcontrib/katex-server.js Co-authored-by: kalvdans <[email protected]> * Use lower-case class variables * Improve comment * Add test and debug * Improve code and more tests * Use uppercase for constants * Fix linter * Add missing docstring to test --------- Co-authored-by: kalvdans <[email protected]>
- Loading branch information
Showing
5 changed files
with
117 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pytest | ||
toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from sphinxcontrib.katex import KaTeXServer | ||
|
||
|
||
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"katex_js_path, expected_require_path", | ||
[ | ||
( | ||
"katex.min.js", | ||
"./katex.min", | ||
), | ||
( | ||
"./katex.min.js", | ||
"./katex.min", | ||
), | ||
( | ||
os.path.join(".", "katex.min.js"), | ||
"./katex.min", | ||
), | ||
( | ||
os.path.join(CURRENT_DIR, "..", "sphinxcontrib", "katex.min.js"), | ||
"./katex.min", | ||
), | ||
], | ||
) | ||
def test_katex_server_js_path(katex_js_path, expected_require_path): | ||
"""Test configured KaTeX Javascript library path. | ||
When using the pre-rendering capabilities | ||
of the ``sphinxcontrib.katex`` sphinx extension, | ||
it requires a KaTeX Javascript library | ||
provided by the file | ||
specified in the config value ``katex_js_path``. | ||
Args: | ||
katex_js_path: path specified for the ``katex_js_path`` | ||
config path variable | ||
expected_require_path: expected path | ||
to the KaTeX Javascript library as provided | ||
to the Javascript ``require()`` function. | ||
The path needs to be relative | ||
to the path of ``katex-server.js`` | ||
always starts with ``./``, | ||
and exclude the file extension | ||
""" | ||
KaTeXServer.katex_path = katex_js_path | ||
cmd = KaTeXServer.build_command() | ||
assert cmd[-1] == expected_require_path | ||
|
||
|
||
def test_katex_server_js_path_error(): | ||
"""Test errors for configured KaTeX Javascript library path.""" | ||
katex_js_path = "non-existing.js" | ||
error_msg = ( | ||
"KaTeX Javascript library could not be found at " | ||
f"{os.path.join('.', katex_js_path)}." | ||
) | ||
with pytest.raises(ValueError, match=error_msg): | ||
KaTeXServer.katex_path = katex_js_path | ||
KaTeXServer.build_command() |