-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
df1db22
commit 8d0de31
Showing
5 changed files
with
61 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
outs: | ||
- md5: 24468ff299e6b6f608ceb7e52618af0d.dir | ||
size: 3246802 | ||
- md5: 454f0f0ed0a390bc98cda08391d71afc.dir | ||
size: 3235049 | ||
nfiles: 11 | ||
hash: md5 | ||
path: docs |
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,53 @@ | ||
"""Filter tables from Pandoc input.""" | ||
|
||
from dataclasses import dataclass | ||
from typing import Any | ||
|
||
from pandocfilters import toJSONFilter | ||
|
||
REMOVE: list[Any] = [] | ||
"""Signals the removal of a block.""" | ||
|
||
memory: list[str] = [] | ||
"""Memory of block keys for multi-block matching.""" | ||
|
||
|
||
def main( | ||
key: str, _value: str, _format: str, _meta: dict[str, Any] | ||
) -> list[Any] | None: | ||
checks = [check_table(key)] | ||
if memory and not any(c.match for c in checks): | ||
memory.clear() | ||
if any(c.remove for c in checks): | ||
return REMOVE # Remove this block | ||
|
||
|
||
@dataclass | ||
class Check: | ||
"""Whether the current block is part of a match, and whether to remove it.""" | ||
|
||
match: bool = True | ||
"""Whether the current block is part of a match.""" | ||
|
||
remove: bool = True | ||
"""Whether to remove the current block.""" | ||
|
||
|
||
TABLE = ["RawBlock", "Plain", "Str"] | ||
"""Sequence of blocks representing a table.""" | ||
|
||
|
||
def check_table(key: str) -> Check: | ||
if key == TABLE[0]: | ||
memory.append(key) | ||
return Check() | ||
if memory and key == TABLE[1] and memory[-1] == TABLE[0]: | ||
memory.append(key) | ||
return Check() | ||
if memory and key == TABLE[2] and memory[-2:] == TABLE[:2]: | ||
return Check() | ||
return Check(match=False, remove=False) | ||
|
||
|
||
if __name__ == "__main__": | ||
toJSONFilter(main) |
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