Skip to content

Commit

Permalink
Linkify function args (new feature in Crystal JSON)
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin committed Jan 2, 2021
1 parent bea6bfd commit fe0d634
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions mkdocstrings/handlers/crystal/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from cached_property import cached_property
from mkdocstrings.handlers.base import CollectionError

from . import crystal_html


class DocItem(metaclass=abc.ABCMeta):
"""A representation of a documentable item from Crystal language.
Expand Down Expand Up @@ -309,9 +311,14 @@ def is_abstract(self):
def args(self) -> Mapping[str, Any]:
return self.data["args"]

@property
def args_string(self) -> str:
return re.sub(r"<[\w/].*?>", "", self.data["args_string"])
@cached_property
def args_html(self) -> crystal_html.TextWithLinks:
# https://github.com/crystal-lang/crystal/pull/10109
try:
html = self.data["args_html"]
except KeyError:
html = self.data["args_string"]
return crystal_html.parse_crystal_html(html)

@cached_property
def location(self) -> Optional[DocLocation]:
Expand Down
2 changes: 1 addition & 1 deletion mkdocstrings/templates/crystal/material/method.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

{% if obj.is_abstract %}<small style="font-weight: normal">abstract</small> {% endif %}
<code>
{{ obj.short_name }}<span style="font-weight: normal">{{ obj.args_string |highlight(language="crystal", inline=True) }}</span>
{{ obj.short_name }}<span style="font-weight: normal">{{ obj.args_html |code_highlight(language="crystal", inline=True) }}</span>
</code>
</h{{ heading_level }}>

Expand Down

0 comments on commit fe0d634

Please sign in to comment.