Skip to content

Commit 8a32df0

Browse files
authored
fix: handle line continuations gracefully (#68)
* handle line continuations gracefully * Update headings.md * Update headings.md
1 parent 8518db4 commit 8a32df0

File tree

10 files changed

+119
-90
lines changed

10 files changed

+119
-90
lines changed

docs/debug.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import os
12
from contextlib import contextmanager
2-
from mkdocs.commands import serve
33
from pathlib import Path
44

5-
import os
5+
from mkdocs.commands import serve
66

77

88
@contextmanager

docs/usage/configuration/headings.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,13 @@ plugins:
521521
Show the symbol type in headings.
522522

523523
This option will prefix headings with
524-
<code class="doc-symbol doc-symbol-attribute"></code>,
524+
<code class="doc-symbol doc-symbol-property"></code>,
525525
<code class="doc-symbol doc-symbol-function"></code>,
526526
<code class="doc-symbol doc-symbol-method"></code>,
527-
<code class="doc-symbol doc-symbol-class"></code> or
528-
<code class="doc-symbol doc-symbol-module"></code> types.
527+
<code class="doc-symbol doc-symbol-class"></code>,
528+
<code class="doc-symbol doc-symbol-script"></code>,
529+
<code class="doc-symbol doc-symbol-namespace"></code> or.
530+
<code class="doc-symbol doc-symbol-folder"></code> types.
529531
See also [`show_symbol_type_toc`][show_symbol_type_toc].
530532

531533
```yaml title="in mkdocs.yml (global configuration)"

scripts/copy_and_update_python_templates.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""A script to copy the modules and attributes templates from
22
the python handler to the matlab handler and update the names"""
33

4-
from mkdocstrings_handlers.python.handler import PythonHandler
5-
from pathlib import Path
64
import re
5+
from pathlib import Path
6+
7+
from mkdocstrings_handlers.python.handler import PythonHandler
78

89
# Get the templates directory of the python handler
910
pythonHandler = PythonHandler("python", "material")

src/mkdocstrings_handlers/matlab/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""MATLAB handler for mkdocstrings."""
22

3-
from mkdocstrings_handlers.matlab.handler import get_handler
4-
from mkdocstrings_handlers.matlab import collect, handler, models, treesitter
3+
from _griffe.docstrings import google, numpy
54
from _griffe.enumerations import DocstringSectionKind
6-
from _griffe.docstrings import numpy, google
5+
6+
from mkdocstrings_handlers.matlab import collect, handler, models, treesitter
7+
from mkdocstrings_handlers.matlab.handler import get_handler
78

89
__all__ = ["get_handler", "collect", "handler", "models", "treesitter"]
910

src/mkdocstrings_handlers/matlab/collect.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,35 @@
33
from collections import defaultdict, deque
44
from copy import copy, deepcopy
55
from pathlib import Path
6-
from typing import Any, Mapping, Sequence, Callable, TypeVar
6+
from typing import Any, Callable, Mapping, Sequence, TypeVar
77

8-
from _griffe.collections import LinesCollection as GLC, ModulesCollection
8+
from _griffe.collections import LinesCollection as GLC
9+
from _griffe.collections import ModulesCollection
910
from _griffe.docstrings.models import (
11+
DocstringParameter,
12+
DocstringReturn,
1013
DocstringSectionOtherParameters,
1114
DocstringSectionParameters,
1215
DocstringSectionReturns,
13-
DocstringParameter,
14-
DocstringReturn,
1516
)
1617
from _griffe.enumerations import DocstringSectionKind
1718
from _griffe.expressions import Expr
1819

1920
from mkdocstrings_handlers.matlab.enums import ParameterKind
2021
from mkdocstrings_handlers.matlab.models import (
21-
_ParentGrabber,
2222
Class,
2323
Classfolder,
2424
Docstring,
2525
DocstringSectionText,
26-
Function,
2726
Folder,
27+
Function,
2828
MatlabMixin,
2929
Namespace,
3030
PathMixin,
31+
_ParentGrabber,
3132
)
3233
from mkdocstrings_handlers.matlab.treesitter import FileParser
3334

34-
3535
PathType = TypeVar("PathType", bound=PathMixin)
3636

3737
__all__ = ["LinesCollection", "PathCollection"]
@@ -198,7 +198,6 @@ def resolve(
198198
elif self._config_path is not None and "/" in identifier:
199199
absolute_path = (self._config_path / Path(identifier)).resolve()
200200
if absolute_path.exists():
201-
202201
if absolute_path.suffix:
203202
path, member = absolute_path.parent, absolute_path.stem
204203
else:
@@ -549,9 +548,7 @@ def addpath(self, path: str | Path, to_end: bool = False, recursive: bool = Fals
549548
]:
550549
if member.parent.is_relative_to(self._config_path):
551550
if member.parent not in self._folders:
552-
self._folders[member.parent] = LazyModel(
553-
member.parent, self
554-
)
551+
self._folders[member.parent] = LazyModel(member.parent, self)
555552
else:
556553
pass # TODO: Issue warning?
557554

src/mkdocstrings_handlers/matlab/enums.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from enum import Enum
2-
from _griffe.enumerations import Kind as GriffeKind
32

43

54
class Kind(str, Enum):
65
"""
76
An enumeration representing different kinds of MATLAB code elements.
87
This enumeration is a subclass of the Griffe `Kind` enumeration, and extends it with additional values.
98
"""
9+
1010
MODULE = "module"
1111
"""Modules."""
1212
CLASS = "class"

src/mkdocstrings_handlers/matlab/handler.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
"""The mkdocstrings handler for processing MATLAB code documentation."""
22

3-
from pathlib import Path
3+
import re
44
from collections import ChainMap
5+
from pathlib import Path
6+
from pprint import pprint
7+
from typing import Any, ClassVar, Mapping
8+
59
from jinja2.loaders import FileSystemLoader
610
from markdown import Markdown
711
from mkdocs.exceptions import PluginError
8-
from mkdocstrings.handlers.base import BaseHandler, CollectorItem, CollectionError
9-
from mkdocstrings_handlers.python import rendering
10-
from typing import Any, ClassVar, Mapping
11-
from pprint import pprint
12-
13-
import re
12+
from mkdocstrings.handlers.base import BaseHandler, CollectionError, CollectorItem
1413

1514
from mkdocstrings_handlers.matlab.collect import LinesCollection, PathCollection
15+
from mkdocstrings_handlers.python import rendering
1616

1717

1818
class MatlabHandler(BaseHandler):
@@ -363,7 +363,7 @@ def collect(self, identifier: str, config: Mapping[str, Any]) -> CollectorItem:
363363
except SyntaxError as ex:
364364
msg = str(ex)
365365
if ex.text:
366-
msg += ':\n' + ex.text
366+
msg += ":\n" + ex.text
367367
raise CollectionError(msg) from ex
368368
except Exception as ex:
369369
raise CollectionError(str(ex)) from ex

src/mkdocstrings_handlers/matlab/models.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,16 @@ def namespaces(self) -> dict[str, "Namespace"]:
153153

154154
@property
155155
def scripts(self) -> dict[str, "Script"]:
156-
return {name: member for name, member in self.all_members.items() if member.kind is Kind.SCRIPT} # type: ignore[misc]
156+
return {
157+
name: member
158+
for name, member in self.all_members.items()
159+
if member.kind is Kind.SCRIPT
160+
} # type: ignore[misc]
157161

158162
@property
159163
def is_script(self) -> bool:
160164
return False
161-
165+
162166
@property
163167
def is_namespace(self) -> bool:
164168
return False
@@ -288,7 +292,8 @@ class Script(MatlabMixin, PathMixin, MatlabObject):
288292
This class inherits from `PathMixin` and `MatlabObject` to provide
289293
functionality specific to MATLAB scripts.
290294
"""
291-
kind = Kind.SCRIPT # type: ignore
295+
296+
kind = Kind.SCRIPT # type: ignore
292297

293298
def __init__(self, *args: Any, **kwargs: Any) -> None:
294299
super().__init__(*args, **kwargs)
@@ -298,6 +303,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
298303
def is_script(self) -> bool:
299304
return True
300305

306+
301307
class Class(MatlabMixin, PathMixin, GriffeClass, MatlabObject):
302308
"""
303309
Represents a MATLAB class with additional properties and methods for handling
@@ -458,7 +464,7 @@ def Private(self) -> bool:
458464
private = self.Access != AccessEnum.public
459465
get_private = self.GetAccess != AccessEnum.public
460466
return private or get_private
461-
467+
462468
@property
463469
def is_private(self) -> bool:
464470
return self.Private or self.Hidden

0 commit comments

Comments
 (0)