spectree icon indicating copy to clipboard operation
spectree copied to clipboard

[QUESTION] Why are description strings joined with double newlines?

Open dfkki123508 opened this issue 2 years ago • 3 comments

For me it causes problems when trying to render markdown, e.g.

@validate()
def fun():
    """summary

    | One | Two | Three |
    |-----|-----|-------|
    | a   | b   | c     |

    | One | Two | Three |

    |-----|-----|-------|

    | a   | b   | c     |

    """

results in the spec as:

"description": "| One | Two | Three | |-----|-----|-------| | a | b | c |\n\n| One | Two | Three |\n\n|-----|-----|-------|\n\n| a | b | c |"

I did not find a possiblity to render single newlines. Can you help me? PS: I am referring to this line: https://github.com/0b01001001/spectree/blob/f04c9b79927cf4bc39eaf3ae2694297e611af2ef/spectree/utils.py#L46 Thanks!

dfkki123508 avatar Sep 13 '22 07:09 dfkki123508

Hi, @dfkki123508 thanks for your feedback.

I think the parse_comments function doesn't support single newlines. There are two parts.

https://github.com/0b01001001/spectree/blob/f04c9b79927cf4bc39eaf3ae2694297e611af2ef/spectree/utils.py#L41

This line ensures that users can write long descriptions in multiple lines.

https://github.com/0b01001001/spectree/blob/f04c9b79927cf4bc39eaf3ae2694297e611af2ef/spectree/utils.py#L46

This line ensures that different sections (split by \n\n) will have a clear separation in the document.

I admit that we didn't cover your use case. I'll try to find a better way to handle this.

kemingy avatar Sep 13 '22 08:09 kemingy

Thanks for the quick answer! I think a workaround is probably to use html tags, but have to try it out :)

dfkki123508 avatar Sep 13 '22 09:09 dfkki123508

Thanks for the quick answer! I think a workaround is probably to use html tags, but have to try it out :)

HTML should work. BTW, for this kind of Markdown flavor table, I guess I can only provide a <code><\code> HTML tag. I guess swagger/redoc won't render it to the real HTML table.

So, maybe using the HTML code directly will be better for your use case?

kemingy avatar Sep 13 '22 09:09 kemingy