lsegal / yard

YARD is a Ruby Documentation tool. The Y stands for "Yay!"
http://yardoc.org
MIT License
1.92k stars 396 forks source link

Code listing titles could be styled in HTML output #1240

Open skalee opened 5 years ago

skalee commented 5 years ago

AsciiDoc allows code listings to have titles (typically file name). However, they look ugly and confusing in YARD documentation. In particular, they are difficult to distinguish from regular paragraphs.

Obviously, using a custom template may help a lot. However, this issue should be addressed in a default template IMO.

I am not sure if this issue belongs to this repository or rather to https://github.com/docmeta/rubydoc.info.

Steps to reproduce

Following AsciiDoc document was used to illustrate the issue:

== In AsciiDoc...

This is a lead paragraph.  Code listing starts right below.

.test.rb
----
two = 1 + 1
eleven = "1" + "1"
raise if Failure.problem
----

This is the second paragraph.  Code listing has just ended.

With default settings, YARD translates it to a following piece of HTML:

<div class="sect1">
<h2 id="_in_asciidoc">In AsciiDoc&#8230;&#8203;</h2>
<div class="sectionbody">
<div class="listingblock">
<div class="title">test.rb</div>
<div class="content">
<pre>two = 1 + 1
eleven = "1" + "1"
raise if Failure.problem</pre>
</div>
</div>
<div class="listingblock">
<div class="title">test2.rb</div>
<div class="content">
<pre class="highlight"><code class="language-ruby" data-lang="ruby">two = 2 + 2
eleven = "2" + "2"
raise if Failure.problem</code></pre>
</div>
</div>
</div>
</div>

Actual Output

![issue3-actual](https://user-images.githubusercontent.com/154287/56109677-e0cc8400-5f51-11e9-877d-5a8652e411aa.png)
## Expected Output Something of similar quality like:
![issue3-expected](https://user-images.githubusercontent.com/154287/56109680-e2964780-5f51-11e9-896a-ecd2f58c54f0.png)
---- I can prepare CSS updates if this is non-controversial. I have read the [Contributing Guide][contrib]. [contrib]: https://github.com/lsegal/yard/blob/master/CONTRIBUTING.md
skalee commented 4 years ago

@lsegal How about this one? Can I implement such feature, or is it something what doesn't fit to YARD for some reason?

skalee commented 4 years ago

@lsegal Few more ideas with different background colors:

Using background color #efeff1 (which is exactly 3% darker than listings' background, i.e. #f7f7f9):

![Zrzut ekranu 2019-12-12 o 03 33 16](https://user-images.githubusercontent.com/154287/70677713-36e3f980-1c90-11ea-8c52-43be5ffd7067.png)

Using background color #eeeeee (which is widely used in the default theme):

![Zrzut ekranu 2019-12-12 o 03 26 06](https://user-images.githubusercontent.com/154287/70677368-49116800-1c8f-11ea-9165-4667fd9284c8.png)

Using background color #e1e1e8 (same as border color):

![Zrzut ekranu 2019-12-12 o 03 30 16](https://user-images.githubusercontent.com/154287/70677561-cd63eb00-1c8f-11ea-97f8-4dca5e946892.png)

Achieved by adding a few lines to templates/default/fulldoc/html/css/style.css:

/* code block titles (supported in AsciiDoc) */
#filecontents .listingblock .title {
  padding: 9px 14px 9px 14px;
  margin-top: 4px;
  border: 1px solid #e1e1e8;
  background: #e1e1e8;
  border-radius: 4px;
  font-size: 1em;
  overflow-x: auto;
  line-height: 1.2em;
  margin-bottom: -9px;
}