aboutsummaryrefslogtreecommitdiff
path: root/doc-tool
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2017-01-12 13:35:56 +0100
committerFelix Mulder <felix.mulder@gmail.com>2017-01-31 14:31:06 +0100
commitb5179028d01d585f57dd8f84a544943f1c01daae (patch)
tree5b486f2a716be486f2cee56da3ab73646a09d961 /doc-tool
parent3a874d7b5a270d76eaaede1ed3cae5abbeb31872 (diff)
downloaddotty-b5179028d01d585f57dd8f84a544943f1c01daae.tar.gz
dotty-b5179028d01d585f57dd8f84a544943f1c01daae.tar.bz2
dotty-b5179028d01d585f57dd8f84a544943f1c01daae.zip
Add `firstParagraph` to `Page`
Diffstat (limited to 'doc-tool')
-rw-r--r--doc-tool/src/dotty/tools/dottydoc/staticsite/Page.scala28
1 files changed, 28 insertions, 0 deletions
diff --git a/doc-tool/src/dotty/tools/dottydoc/staticsite/Page.scala b/doc-tool/src/dotty/tools/dottydoc/staticsite/Page.scala
index 23619d8f7..0871fae6d 100644
--- a/doc-tool/src/dotty/tools/dottydoc/staticsite/Page.scala
+++ b/doc-tool/src/dotty/tools/dottydoc/staticsite/Page.scala
@@ -29,6 +29,34 @@ trait Page {
_html
}
+ def firstParagraph: String = {
+ if (_html eq null) initFields()
+
+ val sb = new StringBuilder
+ var pos = 0
+ // to handle nested paragraphs in non markdown code
+ var open = 0
+
+ while (pos < _html.length - 4) {
+ val str = _html.substring(pos, pos + 4)
+ val lstr = str.toLowerCase
+ sb append str.head
+
+ pos += 1
+ if (lstr.contains("<p>"))
+ open += 1
+ else if (lstr == "</p>") {
+ open -= 1
+ if (open == 0) {
+ pos = Int.MaxValue
+ sb append "/p>"
+ }
+ }
+ }
+
+ sb.toString
+ }
+
protected[this] var _yaml: Map[String, AnyRef /* String | JList[String] */] = _
protected[this] var _html: String = _
protected[this] def initFields() = {