Skip to content

Commit 364f2e4

Browse files
committed
Blog Scaladoc tables
1 parent af99785 commit 364f2e4

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+
![Example Table 1](/resources/img/blog/scaladoc-tables/example-table-1.png)
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+
![Example Table 2](/resources/img/blog/scaladoc-tables/example-table-2.png)
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+
### Dotty
100+
101+
With `dotty` everyday increasing it's share of the development horizon it's important to place the use of GFM into a [dottydoc](https://dotty.epfl.ch/docs/usage/dottydoc.html) context.
102+
103+
In overview `dottydoc` supports the currrent 2.12 Scaladoc media wiki flavored markdown, but also more contemporary flavors of markdown.
104+
105+
`dottydoc` also supports some extensions via the [flexmark-java](https://github.com/vsch/flexmark-java/wiki/Tables-Extension) which allow tables to be defined using
106+
a more expressive version of GFM table markdown. This means tables you create now will have a route to being reused for `dottydoc` API documentation.
107+
108+
### How can I help?
109+
110+
* Use Scaladoc tables
111+
* Share your feedback on [Discourse/Documentation](https://users.scala-lang.org/c/documentation)
112+
113+
114+
115+
116+
Loading
Loading

0 commit comments

Comments
 (0)