-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX Fix line breaks in markdown tables #156
Changes from 2 commits
7b5adf0
d1112d4
dc78f1e
8f6726d
1d5fb40
4ba9f5a
f79c636
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,19 @@ def wrap_as_details(text: str, folded: bool) -> str: | |
return f"<details>\n<summary> Click to expand </summary>\n\n{text}\n\n</details>" | ||
|
||
|
||
def _clean_table(table: str) -> str: | ||
# replace line breaks "\n" with html tag <br />, however, leave end-of-line | ||
# line breaks (eol_lb) intact | ||
eol_lb = "|\n" | ||
placeholder = "$%!?" # arbitrary sting that never appears naturally | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as a friend once said, equivalent to banging my head against the keyboard lol There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's stupid :D If you have a better idea, please let me know About the PR number: I fixed that. How do you add the correct number before you even created the PR? Do you just check the highest number so far and hope that until you actually open the PR, there hasn't been another PR in-between? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't, I just add that as a commit after I create the PR :D |
||
table = ( | ||
table.replace(eol_lb, placeholder) | ||
.replace("\n", "<br />") | ||
.replace(placeholder, eol_lb) | ||
) | ||
return table | ||
|
||
|
||
@dataclass | ||
class PlotSection: | ||
"""Adds a link to a figure to the model card""" | ||
|
@@ -48,7 +61,7 @@ def __repr__(self) -> str: | |
class TableSection: | ||
"""Adds a table to the model card""" | ||
|
||
table: dict["str", list[Any]] | ||
table: dict[str, list[Any]] | ||
folded: bool = False | ||
|
||
def __post_init__(self) -> None: | ||
|
@@ -78,8 +91,8 @@ def format(self) -> str: | |
else: | ||
headers = self.table.keys() | ||
|
||
table = tabulate( | ||
self.table, tablefmt="github", headers=headers, showindex=False | ||
table = _clean_table( | ||
tabulate(self.table, tablefmt="github", headers=headers, showindex=False) | ||
) | ||
return wrap_as_details(table, folded=self.folded) | ||
|
||
|
@@ -467,10 +480,12 @@ def _extract_estimator_config(self) -> str: | |
Markdown table of hyperparameters. | ||
""" | ||
hyperparameter_dict = self.model.get_params(deep=True) | ||
return tabulate( | ||
list(hyperparameter_dict.items()), | ||
headers=["Hyperparameter", "Value"], | ||
tablefmt="github", | ||
return _clean_table( | ||
tabulate( | ||
list(hyperparameter_dict.items()), | ||
headers=["Hyperparameter", "Value"], | ||
tablefmt="github", | ||
) | ||
) | ||
|
||
@staticmethod | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR number missing here.