Repository navigation
libdoc: support for markdown file writing - #5764
Conversation
1a47661 to
6f51294
Compare
pekkaklarck
left a comment
There was a problem hiding this comment.
Looks very good, but I believe the formatting logic should be restructured and few other smaller things fixed/enhanced.
| @@ -65,19 +61,6 @@ def version(self): | |||
| def _console(self, msg, end="\n"): | |||
| print(console_encode(msg), end=end) | |||
There was a problem hiding this comment.
There might be room for cleanup here now that formatting has been moved elsewhere.
| return "" | ||
| md = "#### Arguments\n\n" | ||
| for arg in args: | ||
| if arg.kind in (ArgInfo.POSITIONAL_ONLY_MARKER, ArgInfo.NAMED_ONLY_MARKER): |
There was a problem hiding this comment.
Can actually use arg.is_marker here. I had forgotten about it myself.
Possibly could also change to if not arg.is_marker to avoid continue.
| return "" | ||
| md = "#### Documentation\n\n" | ||
| return md + doc + "\n\n" | ||
| # return f"{doc}\n\n" if doc else "" |
|
|
||
| Reuses the same rendering `ConsoleViewer` uses for `libdoc ... show`: doc | ||
| strings are inserted as-is, converted to Markdown only when the source is | ||
| already documented in the Markdown doc format. |
There was a problem hiding this comment.
The end here is pretty confusing, because nothing is ever converted to Markdown. Perhaps the paragraph could we written like this:
Formatting is the same that is used when viewing documentation on console. Actual documentation is got directly from the library/resource, so the result is proper Markdown only if the library uses Markdown as its documentation format.
|
|
||
| def format(self) -> str: | ||
| md = f"### {self.keyword.name}\n\n" if not self.init else "" | ||
| md += self._format_args(self.keyword.args) |
There was a problem hiding this comment.
Looking at this code now, I believe this would be a slightly better style:
def __init__(self, init: bool = False):
self.init = init
def format(self, keyword: "KeywordDoc") -> str:
md = f"### {keyword.name}\n\n" if not self.init else ""
md += self._format_args(keyword.args)The idea is that you could then use this like
init_formatter = KeywordFormatter(init=True)
init_formatter.format(init)
kw_formatter = KeywordFormatter()
for kw in keywords:
kw.formatter.format(kw)It may be that the code is never used like that, but I still believe this would be better OO design.
There was a problem hiding this comment.
I agree. Made the change.
| spec files and HTML with JSON specs and when using | ||
| the special LIBSPEC format. | ||
| the special LIBSPEC format. Not applicable with HTML | ||
| or MD outputs. |
There was a problem hiding this comment.
or MD outputs -> or Markdown outputs
| `lang` must be one of the built-in language codes: | ||
| {format_languages()} | ||
| New in RF 7.2. | ||
| New in RF 7.2. Not applicable with MD outputs. |
There was a problem hiding this comment.
This isn't really applicable with specs either. I believe the added note can be removed. Changing it to something like Only applicable with HTML outputs. would be fine as well, but I'm 98% sure we'd forget to update it if we actually enable translations with Markdown. 😄
|
|
||
| When creating documentation in HTML, XML or JSON format, the output file must | ||
| be specified as the second argument after the library or resource name or path. | ||
| When creating documentation in HTML, XML, JSON or MD format, the output file |
| It is written as-is, with no keyword name filtering. Documentation is only | ||
| converted to Markdown when the library itself uses the Markdown documentation | ||
| format (see `--docformat`); otherwise the original documentation is included | ||
| unconverted. MD output is new in RF 7.5. |
There was a problem hiding this comment.
This paragraph is confusing similarly as the earlier API doc. There's no conversion to Markdown at all. This could be enhanced, but I'm not sure is this relevant information in --help text in general. If this is preserved, use Markdown instead of MD and Robot Framework 7.5 instead of RF 7.5..
Notice that RF 7.5 is fine when documenting options, because there's not much room for docs. Here we don't have such a problem so better use proper names instead of abbreviations. MD isn't a generally used abbreviation so I'd avoid it altogether (except in *.md).
There was a problem hiding this comment.
Related to the above, this feature needs to be documented in the User Guide.
| # TODO: Markdown output doesn't support --language yet. Remove this guard, | ||
| # and thread `lang` through to `LibdocMarkdownWriter`, once it does. | ||
| if format == "MD" and lang: | ||
| raise DataError("The --language option is not applicable with MD outputs.") |
There was a problem hiding this comment.
Do we need to add this at all?
There was a problem hiding this comment.
Well, there are similar type of errors raised example in here: https://github.com/robotframework/robotframework/blob/master/src/robot/libdoc.py#L266 and few other places. We can also silently ignore the invalid command line switch too. or do you mean the comment?
d1fb60f to
6029994
Compare
pekkaklarck
left a comment
There was a problem hiding this comment.
Looks very good but some fine tuning could still be done!
5f3bbdd to
6b6a02b
Compare
6b6a02b to
f24c344
Compare
Fixes #5749