--To all,
Recently I decided to document approx 260 constants in an API I work with. I created markdowntemplates, and loaded them with Ruby code. The 260 constants were spread throughout the templatesin tables. Being an OCD coding type, I decided to have my code create html tables instead of bar ( | )markdown tables.
## Style Elements in markdown
\[UPDATE\] Now RubyDoc is having issues again. Showing errors intermittently.
The two below links show the formatting on RubyDoc, and the formatting on GitHub.io, which is usingthe html file I generated locally using yard and the same md file. Scroll up from the link to thelong table and you'll see the difference.
the md file is at --
For these tables, I added a style element as shown below --
```<style scoped>#filecontents table.gjl15 { border:none; border-collapse:collapse; margin-bottom:2em;}#filecontents table.gjl15 thead { border-bottom:2px solid #aaa; background-color:transparent;}#filecontents table.gjl15 tr { border:none; background-color:transparent;}#filecontents table.gjl15 tr:nth-child(5n) { border-bottom:1px solid #bbb;}#filecontents table.gjl15 th { border:none; padding: 2px 10px 2px 3px; background-color:transparent; text-align:left;}#filecontents table.gjl15 td { border:none; padding: 2px 10px 2px 3px; background-color:transparent;}#filecontents table.gjl15 td.c, #filecontents table.gjl15 th.c { text-align:center;}#filecontents table.gjl15 td.r, #filecontents table.gjl15 th.r { text-align:right;}#filecontents table.gjl15 td.clr, #filecontents table.gjl15 th.clr { border-bottom:none; width:10em;}</style>```
yard added the style element as the first child of the \<div id='filecontents'\> element, which allows it towork correctly.
RubyDoc wrapped the \<style scoped\>. element in a \<p\> element, which causes it to have no effect.
## Script Elements in markdown
Originally, I added the following script to add the CSS styles I wanted to the last style sheet in the html file.
This worked fine with yard and yard server, but seemed to cause all sorts of issues with RubyDoc.
```<script>var ss_last = document.styleSheets.length - 1,ss = document.styleSheets[ss_last],rules = ss.cssRules,rT1 = "#filecontents table.gjl15 ";ss.insertRule(rT1 + "{ border:none;}", rules.length );ss.insertRule(rT1 + "thead { border-bottom:2px solid #aaa; background-color:transparent;}", rules.length );ss.insertRule(rT1 + "tr { border:none; background-color:transparent;}", rules.length );ss.insertRule(rT1 + "tr:nth-child(5n) { border-bottom:1px solid #aaa;}", rules.length );ss.insertRule(rT1 + "th { border:none; padding: 2px 10px 2px 3px; background-color:transparent; text-align:left;}", rules.length );ss.insertRule(rT1 + "td { border:none; padding: 2px 10px 2px 3px; background-color:transparent;}", rules.length );ss.insertRule(rT1 + "td.c, " + rT1 + "th.c { text-align:center;}", rules.length );ss.insertRule(rT1 + "td.r, " + rT1 + "th.r { text-align:right;}" , rules.length );ss.insertRule(rT1 + "td.clr, " + rT1 + "th.clr { border-bottom:none; width:10em;}" , rules.length );</script>```
## Blank lines & markdown formatting
The following rendered fine in yard & yard server:
```Found the following:* 177 Constants defined in Object (global)* 79 Constants defined in SketchUp objects (namespaced)* 86 SketchUp objects with no defined constants```
At RubyDoc, it all ran together as one paragraph and needed to be formatted as follows(additional blank line):
```Found the following:
* 177 Constants defined in Object (global)* 79 Constants defined in SketchUp objects (namespaced)* 86 SketchUp objects with no defined constants```
## Ruby singleton methods
Ruby allows one to add methods to plain vanilla fudge objects.
```rubyobj = Object.newdef obj.your_methodend```
I found this syntax caused issues possibly everywhere (yard doc, yard server, & RubyDoc). Some of theissues went away if, instead of using a simple variable, obj, I used a class variable (@@obj) or instancevariable (@obj). Better yet, I wrapped all method definitions in a instance_eval block:
```rubyobj = Object.newobj.instance_eval {def method1#enddef method2#end}```
Regardless, the first syntax style is valid Ruby, and shouldn't throw so many errors and/or warnings.
Thanks,
Greg
---
You received this message because you are subscribed to the Google Groups "YARD" group.
To unsubscribe from this group and stop receiving emails from it, send an email to yardoc+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loren,
Thanks for the response.
Both GitHub and my local .yardopts file have the following line in them –
--markup markdown
I would agree that <script> tags are probably inappropriate in md, but if the author needs them, I guess I’m undecided.
As to <style scoped> tags, I think they allow a great deal of flexibility for control, if required or desired.
Hence, it would certainly be helpful if RubyDoc supported them and added them at the root of the md content, unless they are contained in an html tag in the md. I didn’t want to repeat the
<style> element in every table, so I was happy to see that yard added the single <style scoped> element at the top.
As an aside, for those unfamiliar with some particulars of ‘proper’ html, <script> elements are *only* permitted as children of the <head> element. Conversely, <script scoped> elements can exist anywhere. But, they essentially only affect the styling of descendants of its parent element. Hence, RubyDoc’s placing it a <p> element broke my md parsing.
As an aside, that’s one thing I haven’t really seen in the CommonMark spec (which supports <style> tags). It doesn’t seem to clearly define the html generated from md; things like white space between elements, etc. I need to read the whole thing, but…
Re the singleton_methods, thanks for the info. I abbreviated the example a bit too far, the object is normally an instance of an API class, and its methods are used for callbacks/event sinks for domain environment changes by the UI or other API consumers. Since Ruby has no connection between inner & outer classes (unlike some other languages), and since these objects are typically singletons and used in or with a mediator type object, singleton_methods are helpful and simpler from my perspective, and don’t require defining another class.
Thanks for all your work on yard and RubyDoc.info. I wish I knew yard better, but I haven’t had the time. I’d rather propose a fix that you can choose to accept or not.
Hence, I’m not saying ‘fix this’; I’m just trying to point out to others some of the things that have caught me up.
Greg
Both GitHub and my local .yardopts file have the following line in them –
--markup markdown
Hence, it would certainly be helpful if RubyDoc supported them and added them at the root of the md content, unless they are contained in an html tag in the md. I didn’t want to repeat the
As an aside, for those unfamiliar with some particulars of ‘proper’ html, <script> elements are *only* permitted as children of the <head> element. Conversely, <script scoped> elements can exist anywhere. But, they essentially only affect the styling of descendants of its parent element. Hence, RubyDoc’s placing it a <p> element broke my md parsing.
Re the singleton_methods, thanks for the info. I abbreviated the example a bit too far, the object is normally an instance of an API class, and its methods are used for callbacks/event sinks for domain environment changes by the UI or other API consumers. Since Ruby has no connection between inner & outer classes (unlike some other languages), and since these objects are typically singletons and used in or with a mediator type object, singleton_methods are helpful and simpler from my perspective, and don’t require defining another class.