Skip to content

Commit dff9fb9

Browse files
authored
Merge pull request #959 from janekdb/topic/scaladoc-tables-part-one
Blog Scaladoc tables
2 parents af99785 + 974c65b commit dff9fb9

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed
+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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 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+
### GitHub Flavored Markdown Conformance
38+
39+
Scaladoc tables support the [GitHub Flavored Markdown Spec Table Extension](https://github.github.com/gfm/#tables-extension-).
40+
41+
There are some restrictions,
42+
43+
* Every row must start and end with the pipe `|`
44+
* Rows markdown must start on the left edge of the Scala comment
45+
* The final row must be followed by a blank line
46+
47+
These restrictions do not restrict the types of tables that can be created but do have the benefit of allowing simple Scaladoc parsing code.
48+
49+
Picking a popular markdown flavor brings several advantages over creating yet another table markdown variation including,
50+
- No need to explain a new approach
51+
- IDEs and documentation tools can take advantage of existing markdown parsing libraries
52+
53+
### Header Cells, Data Cells
54+
55+
Cell content supports the standard inline styling syntax including bold, italic, monospace, underline, superscript, subscript and links.
56+
57+
This two table example includes bold, monospace, italic, superscript and a link,
58+
59+
```
60+
/**
61+
* | Title | ISBN | Authors |
62+
* | :---: | --- | --- |
63+
* | '''Structured Programming''' | `0-12-200550-3` | ''Dahl, Dijkstra and Hoare'' |
64+
* | '''Purely functional data structures'''^1^ | `0-521-66350-4` | ''Okasaki'' |
65+
*
66+
* | Note | Comment |
67+
* | ---: | --- |
68+
* | 1 | [[https://cambridge.org Cambridge University Press]], 1998|
69+
*/
70+
trait Bibliography
71+
```
72+
73+
Markdown paid, we get this reward,
74+
75+
![Example Table 2](/resources/img/blog/scaladoc-tables/example-table-2.png)
76+
77+
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.
78+
79+
### Column Alignment
80+
81+
Specify column alignments using hyphen and colon patterns.
82+
83+
| Delimiter Cell Content | Alignment Type |
84+
| --- | --- |
85+
| `---` | Left |
86+
| `:---` | Left |
87+
| `---:` | Right |
88+
| `:---:` | Center |
89+
90+
### Including pipe (`|`) in content.
91+
92+
Scala 2.12.8 will support the [escaping of the cell delimiter in cell content](https://github.com/scala/scala/pull/7247) with `\|`.
93+
94+
### More Examples
95+
96+
For a smorgasbord of examples take a look at [examples](http://janekdb.github.io/scala/PR-7247/scala/test/scaladoc/tables/code/index.html).
97+
98+
### Dotty and Scala 3
99+
100+
With `dotty` now boosting its share of the development horizon it's important to place GFM into a [dottydoc](https://dotty.epfl.ch/docs/usage/dottydoc.html) and hence Scaladoc 3 context.
101+
102+
In overview `dottydoc` supports the current Scaladoc 2.12 MediaWiki flavored markdown, but it also supports more contemporary flavors of markdown.
103+
104+
Within the realm of table markdown `dottydoc` supports some extensions via the [flexmark-java table extension](https://github.com/vsch/flexmark-java/wiki/Tables-Extension).
105+
106+
[flexmark-java](https://github.com/vsch/flexmark-java) allows tables to be defined using a more expressive variant of GFM table markdown. Tables you create now will have a route to being reused for `dottydoc` API documentation.
107+
108+
### Scala 2.11 Compatibility
109+
110+
Table markdown will not be interpreted by Scala 2.11 nor will it interfere with parsing.
111+
112+
Content using pipes will display in the generated Scaladoc with the pipes included as literal characters. Bear this in mind if cross compiling.
113+
114+
### How can I help?
115+
116+
* Use Scaladoc tables
117+
* Share your feedback on [Discourse/Documentation](https://users.scala-lang.org/c/documentation)
118+
Loading
Loading

0 commit comments

Comments
 (0)