Skip to content
Draft
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
4 changes: 2 additions & 2 deletions guide/book.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[book]
title = "PyO3 user guide"
description = "PyO3 user guide"
author = "PyO3 Project and Contributors"
authors = ["PyO3 Project and Contributors"]

[preprocessor.pyo3_version]
command = "python3 guide/pyo3_version.py"
command = "python3 pyo3_version.py"

[preprocessor.tabs]

Expand Down
18 changes: 9 additions & 9 deletions guide/pyo3_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- {{#PYO3_CRATE_VERSION}} with a relevant toml snippet (e.g. 'version = "0.13.2"')


Tested against mdbook 0.4.10.
Tested against mdbook 0.5.0.
"""

import json
Expand All @@ -28,26 +28,26 @@
PYO3_CRATE_VERSION = f'version = "{version}"'


def replace_section_content(section):
if not isinstance(section, dict) or "Chapter" not in section:
def replace_item_content(item):
if not isinstance(item, dict) or "Chapter" not in item:
return

# Replace raw and url-encoded forms
section["Chapter"]["content"] = (
section["Chapter"]["content"]
item["Chapter"]["content"] = (
item["Chapter"]["content"]
.replace("{{#PYO3_VERSION_TAG}}", PYO3_VERSION_TAG)
.replace("{{#PYO3_DOCS_URL}}", PYO3_DOCS_URL)
.replace("{{#PYO3_DOCS_VERSION}}", PYO3_DOCS_VERSION)
.replace("{{#PYO3_CRATE_VERSION}}", PYO3_CRATE_VERSION)
)

for sub_item in section["Chapter"]["sub_items"]:
replace_section_content(sub_item)
for sub_item in item["Chapter"]["sub_items"]:
replace_item_content(sub_item)


for line in sys.stdin:
if line:
[context, book] = json.loads(line)
for section in book["sections"]:
replace_section_content(section)
for item in book["items"]:
replace_item_content(item)
json.dump(book, fp=sys.stdout)
Loading