initial spike for KT-1451 to enable wiki markup in kotlin/kdoc comments and support for wiki links (just need to resolve the links to class names/functions/properties now to make wiki links active

This commit is contained in:
James Strachan
2012-03-05 21:35:15 +00:00
parent 9e1f037232
commit 0e928685de
9 changed files with 172 additions and 6 deletions
+27
View File
@@ -128,6 +128,33 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../lib/parboiled-core-1.0.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../lib/parboiled-java-1.0.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../lib/pegdown-1.1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
+6
View File
@@ -4,6 +4,12 @@ fun project() {
module("kdoc") {
classpath += "dist/kotlinc/lib/intellij-core.jar"
classpath += "dist/kotlinc/lib/kotlin-compiler.jar"
// TODO its a bit sad we can't use patterns here...
addClasspathEntry("dist/kotlinc/lib/pegdown-1.1.0.jar")
addClasspathEntry("dist/kotlinc/lib/parboiled-core-1.0.2.jar")
addClasspathEntry("dist/kotlinc/lib/parboiled-java-1.0.2.jar")
addSourceFiles("src/main/kotlin")
}
}
+7
View File
@@ -39,6 +39,13 @@
<scope>system</scope>
<systemPath>${kotlin-sdk}/lib/kotlin-compiler.jar</systemPath>
</dependency>
<dependency>
<groupId>org.pegdown</groupId>
<artifactId>pegdown</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -63,9 +63,15 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
print("""<TD><CODE><B><A HREF="${href(function)}">${function.name}</A></B>""")
printParameters(function)
println("""</CODE>""")
println("""""")
println("""<BR>""")
println("""&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${deprecated}&nbsp;${function.detailedDescription}</TD>""")
println("")
if (true) {
val detail = function.detailedDescription
println("""${detail}""")
} else {
println("""<BR>""")
println("""&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${deprecated}&nbsp;${function.detailedDescription}</TD>""")
}
println("""</TD>""")
println("""</TR>""")
}
@@ -21,6 +21,14 @@ import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor
import org.jetbrains.jet.lang.psi.JetFile
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor
import org.pegdown.PegDownProcessor
import org.pegdown.LinkRenderer
import org.pegdown.ast.WikiLinkNode
import org.pegdown.LinkRenderer.Rendering
import org.pegdown.ast.RefLinkNode
import org.pegdown.ast.AutoLinkNode
import org.pegdown.ast.ExpLinkNode
import org.pegdown.Extensions
fun containerName(descriptor: DeclarationDescriptor): String = qualifiedName(descriptor.getContainingDeclaration())
@@ -132,6 +140,8 @@ class KModel(var context: BindingContext, var title: String = "Documentation", v
public val classes: Collection<KClass>
get() = packages.flatMap{ it.classes }
public var markdownProcessor: PegDownProcessor = PegDownProcessor(Extensions.ALL)
/** Loads the model from the given set of source files */
fun load(sources: List<JetFile?>): Unit {
val allNamespaces = HashSet<NamespaceDescriptor>()
@@ -317,8 +327,8 @@ class KModel(var context: BindingContext, var title: String = "Documentation", v
}
buffer.append(text)
}
// TODO convert any macros or wiki text!
return buffer.toString() ?: ""
val linkRenderer = CustomLinkRenderer(descriptor)
return wikiConvert(buffer.toString() ?: "", linkRenderer)
} else {
return text
}
@@ -326,6 +336,9 @@ class KModel(var context: BindingContext, var title: String = "Documentation", v
return ""
}
fun wikiConvert(text: String, linkRenderer: LinkRenderer): String {
return markdownProcessor.markdownToHtml(text, linkRenderer).sure()
}
fun getType(aType: JetType?): KType? {
if (aType != null) {
@@ -361,6 +374,30 @@ class KModel(var context: BindingContext, var title: String = "Documentation", v
}
}
class CustomLinkRenderer(descriptor: DeclarationDescriptor) : LinkRenderer() {
override fun render(node : WikiLinkNode?) : Rendering? {
println("LinkRenderer.render(WikiLinkNode): $node")
// TODO translate the wiki link to a Class/function/property/extensionFunction etc
return super.render(node)
}
override fun render(node : RefLinkNode?, url : String?, title : String?, text : String?) : Rendering? {
// println("LinkRenderer.render(RefLinkNode): $node url: $url title: $title text: $text")
return super.render(node, url, title, text)
}
override fun render(node : AutoLinkNode?) : Rendering? {
// println("LinkRenderer.render(AutoLinkNode): $node")
return super.render(node)
}
override fun render(node : ExpLinkNode?, text : String?) : Rendering? {
// println("LinkRenderer.render(ExpLinkNode): $node text: $text")
return super.render(node, text)
}
}
abstract class KAnnotated {
public open var description: String = ""
@@ -0,0 +1,54 @@
package test.pegdown
import kotlin.*
import kotlin.util.*
import kotlin.test.*
import junit.framework.TestCase
import org.pegdown.*
import org.pegdown.ast.*
import org.pegdown.LinkRenderer.Rendering
class PegdownTest() : TestCase() {
var markdownProcessor = PegDownProcessor(Extensions.ALL)
var linkRenderer = CustomLinkRenderer()
fun testPegDown() {
val markups = arrayList(
"hello **there **",
"a [[WikiLink]] blah",
"a [[WikiLink someText]] blah",
"a [[SomeClass.property]] blah",
"a [[SomeClass.method()]] blah",
"a [Link](somewhere) blah")
for (text in markups) {
val answer = markdownProcessor.markdownToHtml(text, linkRenderer).sure()
println("$text = $answer")
}
}
}
class CustomLinkRenderer() : LinkRenderer() {
override fun render(node : WikiLinkNode?) : Rendering? {
println("LinkRenderer.render(WikiLinkNode): $node")
return super.render(node)
}
override fun render(node : RefLinkNode?, url : String?, title : String?, text : String?) : Rendering? {
println("LinkRenderer.render(RefLinkNode): $node url: $url title: $title text: $text")
return super.render(node, url, title, text)
}
override fun render(node : AutoLinkNode?) : Rendering? {
println("LinkRenderer.render(AutoLinkNode): $node")
return super.render(node)
}
override fun render(node : ExpLinkNode?, text : String?) : Rendering? {
println("LinkRenderer.render(ExpLinkNode): $node text: $text")
return super.render(node, text)
}
}
+1
View File
@@ -11,6 +11,7 @@
<orderEntry type="module" module-name="stdlib" exported="" />
<orderEntry type="module" module-name="testlib" exported="" />
<orderEntry type="module" module-name="kunit" exported="" />
<orderEntry type="module" module-name="kdoc" exported="" />
</component>
</module>
@@ -0,0 +1,28 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package stdlib.testall;
import junit.framework.TestSuite;
import test.pegdown.*;
/**
*/
public class PegdownAllTest {
public static TestSuite suite() {
return new TestSuite(PegdownTest.class);
}
}
+1 -1
View File
@@ -9,7 +9,7 @@ import java.util.Iterator
/**
* Count the number of elements in collection.
*
* If base collection implements Collection<T> interface method Collection<T>#size() will be used.
* If base collection implements [[Collection]] interface method [[Collection.size()]] will be used.
* Otherwise, this method determines the count by iterating through the all items.
*/
fun <T> java.lang.Iterable<T>.count() : Int {