forked from uabrc/uabrc.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
98 additions
and
89 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import logging | ||
from pathlib import Path, PurePath | ||
from typing import Literal | ||
|
||
import mkdocs_gen_files | ||
import pypandoc | ||
|
||
log = logging.getLogger(f"mkdocs.plugins.{__name__}") | ||
|
||
|
||
class Doc: | ||
def __init__(self, _path: PurePath) -> None: | ||
self._input_path: PurePath = _path | ||
self._output_path: PurePath = _path | ||
|
||
def set_output_path(self, _path: PurePath) -> None: | ||
self._output_path: PurePath = _path | ||
|
||
def to_docx(self) -> None: | ||
self._convert("docx") | ||
|
||
def to_plaintext(self) -> None: | ||
self._convert("plain") | ||
|
||
_FORMAT_SUFFIX_MAP = { | ||
"docx": ".docx", | ||
"plain": ".txt", | ||
} | ||
|
||
def _convert(self, _format: Literal["docx", "plain"]) -> None: | ||
suffix = self._FORMAT_SUFFIX_MAP[_format] | ||
|
||
# touch the file so mkdocs_gen_files is aware of what we intend | ||
# must do this because pypandoc can only write docx directly to disk | ||
mkdocs_url_output_path = self._output_path.with_suffix(suffix) | ||
with mkdocs_gen_files.open(mkdocs_url_output_path, "w") as f: | ||
f.write("") | ||
|
||
# clobber with the actual content | ||
pandoc_disk_output_path = ( | ||
PurePath(mkdocs_gen_files.directory) / mkdocs_url_output_path | ||
) | ||
pypandoc.convert_file( | ||
str(PurePath("docs") / self._input_path), | ||
to=_format, | ||
extra_args=["--wrap=preserve"], | ||
outputfile=str(pandoc_disk_output_path), | ||
) | ||
|
||
|
||
def generate() -> None: | ||
doc = Doc(PurePath("grants") / "res" / "uab-rc-facilities.md") | ||
doc.to_plaintext() | ||
doc.to_docx() | ||
|
||
|
||
generate() |
This file was deleted.
Oops, something went wrong.