diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2017-01-24 10:23:10 +0100 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2017-01-31 14:32:41 +0100 |
commit | 269c24b92a2cf15e90344430291b74ee30441d3a (patch) | |
tree | 7d1a2870aa25991adc4562180930a410b4e84575 | |
parent | f56a8b3246adca23ed76beefb0eb5102e70f6d97 (diff) | |
download | dotty-269c24b92a2cf15e90344430291b74ee30441d3a.tar.gz dotty-269c24b92a2cf15e90344430291b74ee30441d3a.tar.bz2 dotty-269c24b92a2cf15e90344430291b74ee30441d3a.zip |
Fix codeblocks in shortened markdown
-rw-r--r-- | compiler/src/dotty/tools/backend/jvm/LabelDefs.scala | 45 | ||||
-rw-r--r-- | doc-tool/src/dotty/tools/dottydoc/model/comment/MarkdownShortener.scala | 15 |
2 files changed, 33 insertions, 27 deletions
diff --git a/compiler/src/dotty/tools/backend/jvm/LabelDefs.scala b/compiler/src/dotty/tools/backend/jvm/LabelDefs.scala index 371396e36..654507991 100644 --- a/compiler/src/dotty/tools/backend/jvm/LabelDefs.scala +++ b/compiler/src/dotty/tools/backend/jvm/LabelDefs.scala @@ -37,44 +37,47 @@ import StdNames.nme /** * Verifies that each Label DefDef has only a single address to jump back and - * reorders them such that they are not nested and this address is a fall-through address for JVM - * - * ei such code - * + * reorders them such that they are not nested and this address is a + * fall-through address for the JVM. * + * ```scala * <label> def foo(i: Int) = { * <label> def bar = 0 * <label> def dough(i: Int) = if (i == 0) bar else foo(i-1) * dough(i) - * } + * } * * foo(100) + * ``` * - * will get rewritten to + * will get rewritten to: * - * \ + * ```scala * <label> def foo(i: Int) = dough(i) * <label> def dough(i: Int) = if (i == 0) bar else foo(i-1) * <label> def bar = 2 * foo(100) + * ``` * - * Proposed way to generate this pattern in backend is: + * Proposed way to generate this pattern in backend is: * - * foo(100) - * <jump foo> - * <label> def foo(i: Int) = dough(i) - * // <jump a> // unreachable - * <label> def dough(i: Int) = if (i == 0) bar else foo(i-1) - * // <jump a> // unreachable - * <label> def bar = 2 - * // <jump a> // unreachable - * <asm point a> + * ```scala + * foo(100) + * <jump foo> + * <label> def foo(i: Int) = dough(i) + * // <jump a> // unreachable + * <label> def dough(i: Int) = if (i == 0) bar else foo(i-1) + * // <jump a> // unreachable + * <label> def bar = 2 + * // <jump a> // unreachable + * <asm point a> + * ``` * - * Unreachable jumps will be eliminated by local dead code analysis. - * After JVM is smart enough to remove next-line jumps + * Unreachable jumps will be eliminated by local dead code analysis. + * After JVM is smart enough to remove next-line jumps * - * Note that Label DefDefs can be only nested in Block, otherwise no one would be able to call them - * Other DefDefs are eliminated + * Note that Label DefDefs can be only nested in Block, otherwise no one would + * be able to call them Other DefDefs are eliminated */ class LabelDefs extends MiniPhaseTransform { def phaseName: String = "labelDef" diff --git a/doc-tool/src/dotty/tools/dottydoc/model/comment/MarkdownShortener.scala b/doc-tool/src/dotty/tools/dottydoc/model/comment/MarkdownShortener.scala index f7d970959..311f1e2cb 100644 --- a/doc-tool/src/dotty/tools/dottydoc/model/comment/MarkdownShortener.scala +++ b/doc-tool/src/dotty/tools/dottydoc/model/comment/MarkdownShortener.scala @@ -14,11 +14,11 @@ class MarkdownShortener { def shorten(node: Node, maxLen: Int = 150): Node = { var len = 0 - var didUnlinkListItem = false + var didUnlink = false def count(node: Node, length: => Int, shortenOrUnlink: Int => Unit) = { val remaining = math.max(maxLen - len, 0) - if (remaining == 0) node.unlink() + if (didUnlink || remaining == 0) node.unlink() else { if (length <= remaining) len += length else { @@ -50,25 +50,28 @@ class MarkdownShortener { new VisitHandler(classOf[Image], new Visitor[Image] { override def visit(node: Image) = count(node, maxLen, _ => node.unlink()) }), + new VisitHandler(classOf[FencedCodeBlock], new Visitor[FencedCodeBlock] { + override def visit(node: FencedCodeBlock) = count(node, maxLen, _ => node.unlink()) + }), new VisitHandler(classOf[BulletListItem], new Visitor[BulletListItem] { override def visit(node: BulletListItem) = count( node, - if (didUnlinkListItem) maxLen + if (didUnlink) maxLen else node.getSegments.map(_.length).reduceLeft(_ + _), _ => { node.unlink() - didUnlinkListItem = true // unlink all following bullets + didUnlink = true // unlink all following bullets } ) }), new VisitHandler(classOf[OrderedListItem], new Visitor[OrderedListItem] { override def visit(node: OrderedListItem) = count( node, - if (didUnlinkListItem) maxLen + if (didUnlink) maxLen else node.getSegments.map(_.length).reduceLeft(_ + _), _ => { node.unlink() - didUnlinkListItem = true // unlink all following bullets + didUnlink = true // unlink all following bullets } ) }) |