Skip to content

Commit 01b1158

Browse files
authored
Enable multiple install instructions per page (#186)
1 parent 52c3496 commit 01b1158

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

docs/plugins/main.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,15 @@ def install_logfire(markdown: str, page: Page) -> str:
104104
return markdown
105105

106106
# Match instructions like "{{ install_logfire(extras=['fastapi']) }}". Get the extras, if any.
107-
match = re.search(r'{{ *install_logfire\((.*)\) *}}', markdown)
107+
matches = re.findall(r'{{ *install_logfire\((.*)\) *}}', markdown)
108108
extras = []
109-
if match:
110-
arguments = match.group(1).split('=')
109+
for match in matches:
110+
arguments = match.split('=')
111111
# Split them and strip quotes for each one separately.
112112
extras = [arg.strip('\'"') for arg in arguments[1].strip('[]').split(',')] if len(arguments) > 1 else []
113-
114-
package = 'logfire' if not extras else f"'logfire[{','.join(extras)}]'"
115-
extras_arg = ' '.join(f'-E {extra}' for extra in extras)
116-
instructions = f"""
113+
package = 'logfire' if not extras else f"'logfire[{','.join(extras)}]'"
114+
extras_arg = ' '.join(f'-E {extra}' for extra in extras)
115+
instructions = f"""
117116
=== "PIP"
118117
```bash
119118
pip install {package}
@@ -129,14 +128,15 @@ def install_logfire(markdown: str, page: Page) -> str:
129128
poetry add {package}
130129
```
131130
"""
132-
if not extras:
133-
instructions += """
131+
if not extras:
132+
instructions += """
134133
=== "Conda"
135134
```bash
136135
conda install -c conda-forge logfire
137136
```
138137
"""
139-
return re.sub(r'{{ *install_logfire\(.*\) *}}', instructions, markdown)
138+
markdown = re.sub(r'{{ *install_logfire\(.*\) *}}', instructions, markdown, count=1)
139+
return markdown
140140

141141

142142
def warning_on_third_party(markdown: str, page: Page) -> str:

0 commit comments

Comments
 (0)