Fix sections not displaying their text#1600
Conversation
| def markup(comment) | ||
| # Don't try to format the default section. We don't have a store yet. | ||
| return "" if comment.nil? || comment.empty? | ||
| super(normalize_comment(comment.text)) |
There was a problem hiding this comment.
This will double-normalize a comment if comment is already normalized.
# :section: Foo
# # aaa (should be "# aaa")
RDoc::Text#markup will accept RDoc::Comment, so we don't need to use comment.text.
Instead of overriding markup, how about overriding description like this?
def description
markup comment if @comments.any?
endFor reference, RDoc::ClassModule overrides description too
class RDoc::ClassModule
##
# Handy wrapper for marking up this class or module's comment
def description
markup @comment_location
end
endThere was a problem hiding this comment.
Works nicely, thanks
| if @comments.any? | ||
| donor = @comments[0] | ||
| @language = donor.language | ||
| @comment = RDoc::Comment.new(@comments.map(&:text).join, donor.location) |
There was a problem hiding this comment.
If a section comment is separated, I think it should be separated with <p> tag.
# Document1
class A
end
# Document2
class A
endwill generate
<h1 id="class-a" class="anchor-link class">class A</h1>
<section class="description">
<p>Foo</p>
<p>Bar</p>
</section>So
class A
# :section: Section1
# hello
# :section: Section1
# world
endis better to generate
<p>hello</p><p>world</p>One way to create a normalized separated comment is to use:
RDoc::Comment.from_document(to_document)This will create a concatenated normalized comment. comment.text is nil, and the parsed result comment.instance_variable_get(:@document) is present.
There was a problem hiding this comment.
I think using both @comments and @comment is not so great.
Renaming this method to comment, just return a comment without storing to @comment will make the state of this class more simple, I think. To do this, we need to modify def description.
There was a problem hiding this comment.
👍, I applied your suggestion and it's a bit cleaner now.
I removed the tests I added about comment in test_add_comment. Since from_document always sets the comment text to the empty string, they don't hold anymore. I'm not sure how it works but it seems to work out in the end.
|
🚀 Preview deployment available at: https://e227b50d.rdoc-6cd.pages.dev (commit: dfb71ee) |
dfb71ee to
b63d0b8
Compare
There were a few things wrong that made this not work: * Formatting expects `@comment` but there is only `@comments` * The parse method used for marshaling overwrote the markdown parse method * `@store` was not present, which the formatter requires
b63d0b8 to
9b52af3
Compare
I'm currently trying to group methods in the prism docs by topic like "location related", " flag related", etc. so that methods not related to these conceps show up more prominently (not mixed in with potentially many other methods). But I noticed that sections do not currently show their comment.
There were a few things wrong that made this not work:
@commentbut there is only@comments@storewas not present, which the formatter requiresComments can be added/removed, so there still needs to be the array to make it possible to properly modify the section.
Fixes #345, Closes #936
On https://docs.ruby-lang.org/en/master/Prism/Node.html#node-interface there is actually already a comment but it gets swallowed. With this change, it gets properly rendered: