Skip to content
Merged
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
20 changes: 15 additions & 5 deletions src/markdown_include_variants/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,18 @@ def run(self, lines: list[str]) -> list[str]:
configs_str = line_match.group(2).strip()
include_lines: list[tuple[int, int]] = []
highlight_lines: list[tuple[int, int]] = []
title: Union[str, None] = None
for config_match in re.finditer(re_config, configs_str):
if config_match:
name = config_match.group(1)
ranges_str = config_match.group(2)
ranges = parse_lines_index(ranges_str)
value_str = config_match.group(2)
if name == "ln":
include_lines.extend(ranges)
include_lines.extend(parse_lines_index(value_str))
elif name == "hl":
highlight_lines.extend(ranges)
highlight_lines.extend(parse_lines_index(value_str))
elif name == "title":
assert value_str.startswith('"') and value_str.endswith('"')
title = value_str[1:-1]
use_hl_lines: list[tuple[int, int]] = []
if highlight_lines:
if include_lines:
Expand Down Expand Up @@ -356,6 +359,8 @@ def run(self, lines: list[str]) -> list[str]:
first_line = "```python"
if use_hl_lines:
first_line += f' hl_lines="{use_hl_lines_str}"'
if title:
first_line += f' title="{title}"'

block_lines.extend(
[
Expand All @@ -373,6 +378,8 @@ def run(self, lines: list[str]) -> list[str]:
if highlight_lines:
hl_lines_full_str = generate_hl_string(highlight_lines)
first_line_full += f' hl_lines="{hl_lines_full_str}"'
if title:
first_line_full += f' title="{title}"'
block_lines.extend(
[
"///// details | 👀 Full file preview",
Expand All @@ -390,6 +397,9 @@ def run(self, lines: list[str]) -> list[str]:
]
)
if len(sorted_variants):
first_line_variant = "```python"
if title:
first_line_variant += f' title="{title}"'
block_lines.extend(
[
"///// details | 🤓 Other versions and variants",
Expand All @@ -413,7 +423,7 @@ def run(self, lines: list[str]) -> list[str]:

block_lines.extend(
[
"```python",
first_line_variant,
f"{{!{variant.path}!}}",
"```",
"////",
Expand Down
Loading