|
| 1 | +--- |
| 2 | +layout: blog-detail |
| 3 | +post-type: blog |
| 4 | +by: Janek Bogucki |
| 5 | +title: "Introducing Scaladoc Tables" |
| 6 | +--- |
| 7 | + |
| 8 | +Scala 2.12.7 adds support for markdown tables in Scaladoc comments. |
| 9 | + |
| 10 | +### A Simple Example |
| 11 | + |
| 12 | +The markdown for tables follows [GitHub Markdown Flavored Markdown](https://github.github.com/gfm/) with some restrictions. |
| 13 | + |
| 14 | +This table shows all three available table elements, |
| 15 | + |
| 16 | +``` |
| 17 | +| Trait | Implementations | |
| 18 | +| --- | --- | |
| 19 | +| Set | HashSet, HashTrieSet | |
| 20 | +| Seq | List, Vector, Empty | |
| 21 | +| Map | HashTrieMap, ListMap | |
| 22 | +``` |
| 23 | + |
| 24 | +A table is comprised of, |
| 25 | + |
| 26 | + - A header row |
| 27 | + - A delimiter row |
| 28 | + - Zero or more data rows |
| 29 | + |
| 30 | +This is how the above markdown renders, |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +On an incidental note, there is no requirement to align header and cell markdown pipes. This is done in the examples |
| 35 | +to make them easier to scan. |
| 36 | + |
| 37 | + |
| 38 | +### GitHub Flavored Markdown Conformance |
| 39 | + |
| 40 | +Scaladoc tables support the [GitHub Flavored Markdown Spec Table Extension](https://github.github.com/gfm/#tables-extension-). |
| 41 | + |
| 42 | +There are some restrictions, |
| 43 | + |
| 44 | +* Every row must start and end with the pipe `|` |
| 45 | +* Rows markdown must start on the left edge of the Scala comment |
| 46 | +* The final row must be followed by a blank line |
| 47 | + |
| 48 | +These restrictions do not restrict the types of tables that can be created but do have the benefit of allowing simple Scaladoc parsing code. |
| 49 | + |
| 50 | +Picking a popular markdown flavor brings several advantages over creating yet another table markdown variation including, |
| 51 | +- No need to explain a new approach |
| 52 | +- IDEs and documentation tools can take advantage of existing markdown parsing libraries |
| 53 | + |
| 54 | +### Header Cells, Data Cells |
| 55 | + |
| 56 | +Cell content supports the standard inline styling syntax including bold, italic, monospace, underline, superscript, subscript and links. |
| 57 | + |
| 58 | +This two table example includes bold, monospace, italic, superscript and a link, |
| 59 | + |
| 60 | +``` |
| 61 | +/** |
| 62 | + * | Title | ISBN | Authors | |
| 63 | + * | :---: | --- | --- | |
| 64 | + * | '''Structured Programming''' | `0-12-200550-3` | ''Dahl, Dijkstra and Hoare'' | |
| 65 | + * | '''Purely functional data structures'''^1^ | `0-521-66350-4` | ''Okasaki'' | |
| 66 | + * |
| 67 | + * | Note | Comment | |
| 68 | + * | ---: | --- | |
| 69 | + * | 1 | [[https://cambridge.org Cambridge University Press]], 1998| |
| 70 | +*/ |
| 71 | +trait Bibliography |
| 72 | +``` |
| 73 | + |
| 74 | +Markdown paid, we get this reward, |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | +Breaking content over several lines is not supported in GFM tables. Use a `<br/>` tag or go with HTML tables if you have needs beyond the simple tables supported by GFM. |
| 79 | + |
| 80 | +### Column Alignment |
| 81 | + |
| 82 | +Specify column alignments using hyphen and colon patterns. |
| 83 | + |
| 84 | +| Delimiter Cell Content | Alignment Type | |
| 85 | +| --- | --- | |
| 86 | +| `---` | Left | |
| 87 | +| `:---` | Left | |
| 88 | +| `---:` | Right | |
| 89 | +| `:---:` | Center | |
| 90 | + |
| 91 | +### Including pipe (`|`) in content. |
| 92 | + |
| 93 | +Scala 2.12.8 will support the [escaping of the cell delimiter in cell content](https://github.com/scala/scala/pull/7247) with `\|`. |
| 94 | + |
| 95 | +### More Examples |
| 96 | + |
| 97 | +For a smorgasbord of examples take a look at [examples](http://janekdb.github.io/scala/PR-7247/scala/test/scaladoc/tables/code/index.html). |
| 98 | + |
| 99 | +### How can I help? |
| 100 | + |
| 101 | +Use Scaladoc tables and share your feedback on [Discourse/Documentation](https://users.scala-lang.org/c/documentation). |
| 102 | + |
| 103 | + |
0 commit comments