-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #910 from Lorak-mmk/book-preprocessor
Docs: Add a book preprocessor
- Loading branch information
Showing
6 changed files
with
54 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ build: | |
|
||
.PHONY: docs | ||
docs: | ||
./docs/build_book.py | ||
mdbook build docs | ||
|
||
.PHONY: up | ||
up: | ||
|
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 was deleted.
Oops, something went wrong.
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,34 @@ | ||
import json | ||
import sys | ||
|
||
def remove_sphinx_markdown(md_file_text): | ||
text_split = md_file_text.split("```eval_rst") | ||
|
||
result = text_split[0] | ||
|
||
for i in range(1, len(text_split)): | ||
cur_chunk = text_split[i] | ||
result += cur_chunk[cur_chunk.find("```") + 3:] | ||
|
||
return result | ||
|
||
def process_section(section): | ||
if 'Chapter' in section: | ||
section['Chapter']['content'] = remove_sphinx_markdown(section['Chapter']['content']) | ||
for s in section['Chapter']['sub_items']: | ||
process_section(s) | ||
|
||
if __name__ == '__main__': | ||
if len(sys.argv) > 1: # we check if we received any argument | ||
if sys.argv[1] == "supports": | ||
# then we are good to return an exit status code of 0, since the other argument will just be the renderer's name | ||
sys.exit(0) | ||
|
||
# load both the context and the book representations from stdin | ||
context, book = json.load(sys.stdin) | ||
|
||
for section in book['sections']: | ||
process_section(section) | ||
|
||
# we are done with the book's modification, we can just print it to stdout | ||
print(json.dumps(book)) |