Skip to content

Commit 105aa87

Browse files
committed
Blog Scaladoc tables
1 parent af99785 commit 105aa87

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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+
<img alt="Example Table 1"
33+
src="/resources/img/blog/scaladoc-tables/example-table-1.png">
34+
35+
On an incidental note, there is no requirement to align header and cell markdown pipes. This is done in the examples
36+
to make them easier to scan.
37+
38+
39+
### GitHub Flavored Markdown Conformance
40+
41+
Scaladoc tables support the [GitHub Flavored Markdown Spec Table Extension](https://github.github.com/gfm/#tables-extension-).
42+
43+
There are some restrictions,
44+
45+
* Every row must start and end with the pipe `|`
46+
* Rows markdown must start on the left edge of the Scala comment
47+
* The final row must be followed by a blank line
48+
49+
These restrictions do not restrict the types of tables that can be created but do have the benefit of allowing simple Scaladoc parsing code.
50+
51+
Picking a popular markdown flavor brings several advantages over creating yet another table markdown variation including,
52+
- No need to explain a new approach
53+
- IDEs and documentation tools can take advantage of existing markdown parsing libraries
54+
55+
### Header Cells, Data Cells
56+
57+
Cell content supports the standard inline styling syntax including bold, italic, monospace, underline, superscript, subscript and links.
58+
59+
This two table example includes bold, monospace, italic, superscript and a link,
60+
61+
```
62+
/**
63+
* | Title | ISBN | Authors |
64+
* | :---: | --- | --- |
65+
* | '''Structured Programming''' | `0-12-200550-3` | ''Dahl, Dijkstra and Hoare'' |
66+
* | '''Purely functional data structures'''^1^ | `0-521-66350-4` | ''Okasaki'' |
67+
*
68+
* | Note | Comment |
69+
* | ---: | --- |
70+
* | 1 | [[https://cambridge.org Cambridge University Press]], 1998|
71+
*/
72+
trait Bibliography
73+
```
74+
75+
Markdown paid, we get this reward,
76+
77+
<img alt="Example Table 2"
78+
src="/resources/img/blog/scaladoc-tables/example-table-2.png">
79+
80+
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.
81+
82+
### Column Alignment
83+
84+
Specify column alignments using hyphen and colon patterns.
85+
86+
| Delimiter Cell Content | Alignment Type |
87+
| --- | --- |
88+
| `---` | Left |
89+
| `:---` | Left |
90+
| `---:` | Right |
91+
| `:---:` | Center |
92+
93+
### Including pipe (`|`) in content.
94+
95+
Scala 2.12.8 will support the [escaping of the cell delimiter in cell content](https://github.com/scala/scala/pull/7247) with `\|`.
96+
97+
### More Examples
98+
99+
For a smorgasbord of examples take a look at [examples](http://janekdb.github.io/scala/PR-7247/scala/test/scaladoc/tables/code/index.html).
100+
101+
### How can I help?
102+
103+
Use Scaladoc tables and share your feedback on [Discourse/Documentation](https://users.scala-lang.org/c/documentation).
104+
105+
Loading
Loading

0 commit comments

Comments
 (0)