Skip to content

Parse rustdocs out of markdown-formatted doc strings #1942

Closed
@brson

Description

@brson

This is an example of a current rustdoc from core:

#[doc(
    desc = "

Convert a string to a float

This function accepts strings such as

* '3.14'
* '+3.14', equivalent to '3.14'
* '-3.14'
* '2.5E10', or equivalently, '2.5e10'
* '2.5E-10'
* '', or, equivalently, '.' (understood as 0)
* '5.'
* '.5', or, equivalently,  '0.5'

Leading and trailing whitespace are ignored.

",
    args(
        num = "A string"
    ),
    return = "

none if the string did not represent a valid number.  Otherwise, some(n) where
n is the floating-point number represented by [num].

")]

All of the extra attribute stuff is noise. Without much difficulty we could parse markdown like:

#[doc = "

Convert a string to a float

This function accepts strings such as

* '3.14'
* '+3.14', equivalent to '3.14'
* '-3.14'
* '2.5E10', or equivalently, '2.5e10'
* '2.5E-10'
* '', or, equivalently, '.' (understood as 0)
* '5.'
* '.5', or, equivalently,  '0.5'

Leading and trailing whitespace are ignored.

Arguments:

* num - A string

Returns:

none if the string did not represent a valid number.  Otherwise, some(n) where
n is the floating-point number represented by [num].

"]

Metadata

Metadata

Assignees

Labels

C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions