Skip to content

Commit

Permalink
Don't truncate in array item restrictions tables (#216)
Browse files Browse the repository at this point in the history
Co-authored-by: Denis Blanchette <[email protected]>
  • Loading branch information
alexjurkiewicz and dblanchette authored Sep 28, 2023
1 parent c2b2758 commit 178c7b1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
6 changes: 3 additions & 3 deletions json_schema_for_humans/jinja_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ def deprecated(config, schema: SchemaNode) -> bool:
return is_deprecated_look_in_description(schema) if config.deprecated_from_description else is_deprecated(schema)


def first_line(example_text: str, max_length: int = 0) -> str:
def first_line(example_text: str) -> str:
"""Filter. Retrieve first line of string + add ... at the end if text has multiple lines cut line at max_length"""
lines = example_text.splitlines()
result = lines[0]
etc = (max_length and len(result) > max_length) or len(lines) > 1
return f"{result[:max_length]}{' ...' if etc else ''}"
etc = len(lines) > 1
return f"{result}{' ...' if etc else ''}"


def get_local_time() -> str:
Expand Down
9 changes: 4 additions & 5 deletions json_schema_for_humans/md_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ def array_items(schema: SchemaNode, title: str) -> List[List[str]]:
return items


def first_line_fixed(example_text: str, max_length: int = 0) -> str:
"""first_line truncated but replace ` with ' to avoid to have only one ` to avoid issues with jekyll"""
return jinja_filters.first_line(example_text, max_length).translate(str.maketrans({"`": "'"}))
def first_line_fixed(example_text: str) -> str:
"""first_line but replace ` with ' to avoid unbalanced `s in markdown"""
return jinja_filters.first_line(example_text).translate(str.maketrans({"`": "'"}))


def array_items_restrictions(schema: SchemaNode) -> List[List[str]]:
Expand All @@ -174,7 +174,7 @@ def array_items_restrictions(schema: SchemaNode) -> List[List[str]]:
items_restrictions.append(
[
f"[{item_label}](#{item_html_id})",
escape_for_table(first_line_fixed(item.description or "-", const.LINE_WIDTH)),
escape_for_table(first_line_fixed(item.description or "-")),
]
)

Expand All @@ -200,7 +200,6 @@ def register_jinja(self, env: jinja2.Environment):
env.filters["md_array_items"] = array_items
env.filters["md_restrictions_table"] = restrictions_table
env.filters["md_generate_table"] = generate_table
env.filters["md_first_line"] = first_line_fixed

env.globals["md_badge"] = self.badge
env.globals["md_get_toc"] = self.get_toc
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "json-schema-for-humans"
version = "0.45.0"
version = "0.46.0"
description = "Generate static HTML documentation from JSON schemas"
authors = ["Denis Blanchette <[email protected]>", "AbdulRahman Al Hamali <[email protected]>"]
license = "Apache-2.0"
Expand Down

0 comments on commit 178c7b1

Please sign in to comment.