Skip to content

Commit 5f8b27f

Browse files
committed
Add support for tables in wiki syntax
1 parent e23f815 commit 5f8b27f

File tree

6 files changed

+392
-52
lines changed

6 files changed

+392
-52
lines changed

scaladoc-testcases/src/example/level2/Documentation.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,19 @@ abstract class Documentation[T, A <: Int, B >: String, -X, +Y](c1: String, val c
149149
*/
150150
def loremIpsum[T](a: T): Map[T, T] = ???
151151

152+
/**
153+
* &nbsp;
154+
* | How to convert ... | to a [[PartialFunction]] | to an optional [[Function]] | to an extractor |
155+
* | :---: | --- | --- | --- |
156+
* | from a [[PartialFunction]] | [[Predef.identity]] | [[lift]] | [[Predef.identity]] |
157+
* | from optional [[Function]] | [[Function1.UnliftOps#unlift]] or [[Function.unlift]] | [[Predef.identity]] | [[Function1.UnliftOps#unlift]] |
158+
* | from an extractor | `{ case extractor(x) => x }` | `extractor.unapply _` | [[Predef.identity]] |
159+
* &nbsp;
160+
*
161+
* @syntax wiki
162+
*/
163+
def table(foo: String) = ???
164+
152165
protected[example] val valWithScopeModifier = ???
153166
protected[this] val valWithScopeModifierThis = ???
154167

scaladoc/src/dotty/tools/scaladoc/renderers/DocRenderer.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ class DocRender(signatureRenderer: SignatureRenderer)(using DocContext):
4242
val tooltip = s"Problem linking $query: $msg"
4343
signatureRenderer.unresolvedLink(linkBody(query), titleAttr := tooltip)
4444

45+
private def renderHeader(header: Row): AppliedTag =
46+
tr(
47+
header.cells.map(c => th(c.blocks.map(renderElement)))
48+
)
49+
50+
private def renderRow(row: Row): AppliedTag =
51+
tr(
52+
row.cells.map(c => td(c.blocks.map(renderElement)))
53+
)
54+
4555
private def renderElement(e: WikiDocElement): AppliedTag = e match
4656
case Title(text, level) =>
4757
val content = renderElement(text)
@@ -55,6 +65,15 @@ class DocRender(signatureRenderer: SignatureRenderer)(using DocContext):
5565
case Paragraph(text) => p(renderElement(text))
5666
case Code(data: String) => pre(code(raw(data.escapeReservedTokens))) // TODO add classes
5767
case HorizontalRule => hr
68+
case Table(header, columns, rows) =>
69+
table(
70+
thead(
71+
renderHeader(header)
72+
),
73+
tbody(
74+
rows.map(renderRow)
75+
)
76+
)
5877

5978
case UnorderedList(items) => ul(listItems(items))
6079
case OrderedList(items, style) => ol(listItems(items)) // TODO use style

scaladoc/src/dotty/tools/scaladoc/tasty/comments/Comments.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ class WikiCommentParser(repr: Repr)(using DocContext)
230230
case wiki.OrderedList(elems, _) => elems.headOption.fold("")(flatten)
231231
case wiki.DefinitionList(items) => items.headOption.fold("")(e => flatten(e._1))
232232
case wiki.HorizontalRule => ""
233+
case wiki.Table(header, columns, rows) => (header +: rows).flatMap(_.cells).flatMap(_.blocks).map(flatten).mkString
233234

234235
def markupToString(str: wiki.Body) = str.blocks.headOption.fold("")(flatten)
235236

scaladoc/src/dotty/tools/scaladoc/tasty/comments/wiki/Entities.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ final case class UnorderedList(items: Seq[Block]) extends Block
5050
final case class OrderedList(items: Seq[Block], style: String) extends Block
5151
final case class DefinitionList(items: SortedMap[Inline, Block]) extends Block
5252
object HorizontalRule extends Block
53+
final case class Table(header: Row, columnOptions: Seq[ColumnOption], rows: Seq[Row]) extends Block
54+
final case class ColumnOption(option: 'L' | 'C' | 'R')
55+
object ColumnOption {
56+
val ColumnOptionLeft = ColumnOption('L')
57+
val ColumnOptionCenter = ColumnOption('C')
58+
val ColumnOptionRight = ColumnOption('R')
59+
}
60+
final case class Row(cells: Seq[Cell])
61+
final case class Cell(blocks: Seq[Block])
5362

5463
/** An section of text inside a block, possibly with formatting. */
5564
sealed abstract class Inline extends WikiDocElement:

0 commit comments

Comments
 (0)