arrow-kt / ank

ΛNK: Compile time docs verification and evaluation for Kotlin and Java (Temporarily moved to Arrow-kt)
https://github.com/arrow-kt/arrow/tree/master/modules/ank
Apache License 2.0
53 stars 3 forks source link

Strip modifiers from language indicators #34

Closed calvellido closed 5 years ago

calvellido commented 5 years ago

Currently ΛNK produces code snippets with class selectors like:

<code class="language-kotlin:ank">
   import arrow.*
   import arrow.core.*

   val throwsSomeStuff: (Int) -> Double = {x -> x.toDouble()}
   val throwsOtherThings: (Double) -> String = {x -> x.toString()}
   val moreThrowing: (String) -> List<String> = {x -> listOf(x)}
   val magic = throwsSomeStuff.andThen(throwsOtherThings).andThen(moreThrowing) 
   magic
</code>
<code class="language-kotlin:ank:silent">
   // Either Style

   fun parse(s: String): Either&lt;NumberFormatException, Int&gt; =
       if (s.matches(Regex("-?[0-9]+"))) Either.Right(s.toInt())
       else Either.Left(NumberFormatException("$s is not a valid integer."))

   fun reciprocal(i: Int): Either&lt;IllegalArgumentException, Double&gt; =
       if (i == 0) Either.Left(IllegalArgumentException("Cannot take reciprocal of 0."))
       else Either.Right(1.0 / i)

   fun stringify(d: Double): String = d.toString()

   fun magic(s: String): Either&lt;Exception, String&gt; =
       parse(s).flatMap{reciprocal(it)}.map{stringify(it)}
</code>

Colon prefixed properties are pseudo-classes in W3C selector spec.

For a better intercommunication with other libraries, highlighters, document queries etc. would be better to have ΛNK to strip modifiers from final generated class names, unless those modifiers are intentionally trying to indicate something at the DOM level.

So having something like this fence:

```kotlin:ank:silent
class Contact(val id: Int, var email: String)

fun main(args: Array<String>) {
    val contact = Contact(1, "mary@gmail.com")
    println(contact.id)
}

The generated code block will be like this after ΛNK process it:
class Contact(val id: Int, var email: String)

fun main(args: Array<String>) {
    val contact = Contact(1, "mary@gmail.com")
    println(contact.id)
}
And finally, after Rouge (default Jekyll highlighter) process it,  will get us to the following:

```kotlin
<pre>
   <code class="language-kotlin">
      class Contact(val id: Int, var email: String)

      fun main(args: Array<String>) {
          val contact = Contact(1, "mary@gmail.com")
          println(contact.id)
      }
   </code>
</pre>

For reference, that is the behaviour tut applies, treating the modifier accordingly and then leaving the final language indicator as simply scala:

http://tpolecat.github.io/tut/modifiers.html

calvellido commented 5 years ago

Closing this, as this is the current actual behaviour of ΛNK.