Skip to content

Commit 06e30ff

Browse files
committed
chore: use default config from mkdocs.yml #27
1 parent a655f08 commit 06e30ff

File tree

6 files changed

+312
-364
lines changed

6 files changed

+312
-364
lines changed

Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,13 @@ test-report: ## Report testing
5353

5454
.PHONY: lint
5555
lint: ## Check code
56-
$(RUNNER) ruff $(CODE)
57-
$(RUNNER) black --check $(CODE)
56+
$(RUNNER) ruff check $(CODE)
5857
$(RUNNER) pytest --dead-fixtures --dup-fixtures
5958
$(RUNNER) mypy $(CODE)
6059

6160
.PHONY: format
6261
format: ## Formatting code
63-
$(RUNNER) ruff --fix-only $(CODE)
64-
$(RUNNER) black $(CODE)
62+
$(RUNNER) ruff format $(CODE)
6563

6664
.PHONY: docs
6765
docs: ## Build docs

docs/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ plugins:
1515
- "$"
1616
```
1717
18-
You can override configurations for each block. If you set a part of the settings, the other part will be set to the default value.
18+
You can override configurations for each block. If you set a part of the settings, the other part will be set to the default value from `mkdocs.yml`.
1919

2020
`<!-- termynal: {"prompt_literal_start": ["$", ">>>", "PS >"], title: powershell, buttons: windows} -->`
2121

pyproject.toml

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ mkdocs = ["mkdocs >= 1.4"]
2626

2727
[dependency-groups]
2828
dev = [
29-
"black >= 24.10",
3029
"mypy >= 1.13.0",
3130
"pytest >= 7.4",
3231
"pytest-cov >= 4.1",
3332
"pytest-deadfixtures >= 2.2",
3433
"pytest-mock >= 3.14",
3534
"pyyaml >= 6.0",
36-
"ruff >= 0.1",
35+
"ruff < 1",
3736
"types-markdown >= 3.7",
3837
"types-pyyaml >= 6.0",
3938
]
@@ -85,63 +84,10 @@ fail_under = 94
8584
addopts = "--strict-markers --showlocals --verbosity 2"
8685
log_level = "DEBUG"
8786

88-
[tool.ruff]
89-
select = [
90-
"F",
91-
"E",
92-
"W",
93-
"C90",
94-
"I",
95-
"N",
96-
"D",
97-
# "UP",
98-
"YTT",
99-
# "ANN",
100-
"S",
101-
"BLE",
102-
# "FBT",
103-
"B",
104-
"A",
105-
"COM",
106-
"C4",
107-
"DTZ",
108-
"T10",
109-
"EM",
110-
"EXE",
111-
"ISC",
112-
"ICN",
113-
"G",
114-
"INP",
115-
"PIE",
116-
"T20",
117-
"PT",
118-
"Q",
119-
"RET",
120-
"SIM",
121-
"TID",
122-
"TCH",
123-
"ARG",
124-
"PTH",
125-
"ERA",
126-
"PD",
127-
# "PGH",
128-
"PL",
129-
"TRY",
130-
"RSE",
131-
"RUF",
132-
]
133-
ignore = [
134-
"D100",
135-
"D101",
136-
"D102",
137-
"D103",
138-
"D104",
139-
"D105",
140-
"D106",
141-
"D107",
142-
"D203",
143-
"D213",
144-
"D401",
145-
"S101",
146-
]
87+
[tool.ruff.lint]
88+
select = []
89+
ignore = []
14790
exclude = []
91+
92+
[tool.ruff.lint.per-file-ignores]
93+
"tests/*" = ["S101"]

termynal/markdown.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22
import re
33
from enum import Enum
44
from textwrap import dedent
5-
from typing import TYPE_CHECKING, Any, Dict, Iterable, List, NamedTuple, Optional, Union
5+
from typing import (
6+
TYPE_CHECKING,
7+
Any,
8+
Dict,
9+
List,
10+
NamedTuple,
11+
Optional,
12+
Sequence,
13+
Union,
14+
)
615

716
import yaml
817
import yaml.parser
@@ -22,7 +31,7 @@ class Buttons(str, Enum):
2231

2332
class Config(NamedTuple):
2433
title: str
25-
prompt_literal_start: Iterable[str]
34+
prompt_literal_start: Sequence[str]
2635
buttons: Buttons
2736

2837

@@ -47,7 +56,7 @@ def __repr__(self) -> str: # pragma:no cover
4756
ParsedBlock = Union[Command, Comment, Output, Progress]
4857

4958

50-
def make_regex_prompts(prompt_literal_start: Iterable[str]) -> "re.Pattern[str]":
59+
def make_regex_prompts(prompt_literal_start: Sequence[str]) -> "re.Pattern[str]":
5160
prompt_literal_start = [re.escape(p).strip() for p in prompt_literal_start]
5261
prompt_to_replace = {
5362
">": "&gt;",
@@ -88,7 +97,7 @@ def add_spaces(code: str, spaces: str) -> str:
8897
return "\n".join(result)
8998

9099

91-
def parse_config(raw: str) -> Optional[Config]:
100+
def parse_config(raw: str, default: Optional[Config]) -> Optional[Config]:
92101
try:
93102
config = yaml.full_load(raw)
94103
except yaml.parser.ParserError: # pragma:no cover
@@ -97,14 +106,22 @@ def parse_config(raw: str) -> Optional[Config]:
97106
if not isinstance(config, dict):
98107
return None
99108

100-
return parse_config_from_dict(config)
109+
return parse_config_from_dict(config, default)
101110

102111

103-
def parse_config_from_dict(config: Dict[str, Any]) -> Config:
112+
def parse_config_from_dict(
113+
config: Dict[str, Any],
114+
default: Optional[Config] = None,
115+
) -> Config:
104116
return Config(
105-
title=str(config.get("title", "bash")),
106-
prompt_literal_start=list(config.get("prompt_literal_start", ("$",))),
107-
buttons=Buttons(config.get("buttons", "macos")),
117+
title=str(config.get("title", default.title if default else "bash")),
118+
prompt_literal_start=list(
119+
config.get(
120+
"prompt_literal_start",
121+
default.prompt_literal_start if default else ("$",),
122+
),
123+
),
124+
buttons=Buttons(config.get("buttons", default.buttons if default else "macos")),
108125
)
109126

110127

@@ -236,7 +253,7 @@ def run(self, lines: List[str]) -> List[str]:
236253
spaces = m.group("spaces") or ""
237254
config_raw = (m.group("config") or "").strip()
238255
if config_raw:
239-
config = parse_config(config_raw)
256+
config = parse_config(config_raw, self.config)
240257
if config:
241258
termynal = Termynal(config)
242259

tests/test_markdown_extension.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ def test_cases_yml(
3535
TermynalExtension(**config),
3636
],
3737
)
38-
assert (
39-
html == expected_html
40-
), "The expected html is different, see tests/test_cases.yml"
38+
assert html == expected_html, (
39+
"The expected html is different, see tests/test_cases.yml"
40+
)

0 commit comments

Comments
 (0)