Skip to content

libdoc: support for markdown file writing - #5764

Merged
pekkaklarck merged 1 commit into
robotframework:masterfrom
aaltat:libdoc_markdown_output
Aug 28, 2026
Merged

pekkaklarck merged 1 commit into
robotframework:masterfrom
aaltat:libdoc_markdown_output

Conversation

@aaltat

@aaltat aaltat commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #5749

@aaltat
aaltat force-pushed the libdoc_markdown_output branch from 1a47661 to 6f51294 Compare August 25, 2026 11:58

@pekkaklarck pekkaklarck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return ""
md = "#### Documentation\n\n"
return md + doc + "\n\n"
# return f"{doc}\n\n" if doc else ""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, done


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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Made the change.

Comment thread src/robot/libdoc.py Outdated
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or MD outputs -> or Markdown outputs

Comment thread src/robot/libdoc.py Outdated
`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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. 😄

Comment thread src/robot/libdoc.py Outdated

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MD -> Markdown

Comment thread src/robot/libdoc.py Outdated
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to the above, this feature needs to be documented in the User Guide.

Comment thread src/robot/libdoc.py Outdated
# 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.")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add this at all?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@aaltat
aaltat force-pushed the libdoc_markdown_output branch 4 times, most recently from d1fb60f to 6029994 Compare August 28, 2026 12:45

@pekkaklarck pekkaklarck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good but some fine tuning could still be done!

@aaltat
aaltat force-pushed the libdoc_markdown_output branch 2 times, most recently from 5f3bbdd to 6b6a02b Compare August 28, 2026 13:37
@aaltat
aaltat force-pushed the libdoc_markdown_output branch from 6b6a02b to f24c344 Compare August 28, 2026 13:38
@pekkaklarck
pekkaklarck merged commit 0bfe709 into robotframework:master Aug 28, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Libdoc: Support Markdown as output format

2 participants