Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Samples are not placed in code fences for GFM #1653

Closed
bherbst opened this issue Dec 1, 2020 · 7 comments
Closed

Samples are not placed in code fences for GFM #1653

bherbst opened this issue Dec 1, 2020 · 7 comments
Labels
bug format: gfm An issue/PR related to Dokka's GFM output format

Comments

@bherbst
Copy link

bherbst commented Dec 1, 2020

Describe the bug
Code samples are not placed in code fences with the GFM format, which makes the output very difficult to read since the code will not have syntax highlighting, nor will it be placed in a code block.

Given this documented function:

/**
 * Print a greeting to the standard output
 * 
 * @sample samples.basicSample
 */
fun greet(name: String) {
  println("Hello $name!")
}

And this sample file:

package samples

// This function will print "Hello Everyone!"
fun basicSample() {
  greet("Everyone")
}

./gradlew dokkaGfm will generate an index.md containing this:

## Samples  
 [jvm]
fun basicSample() {
   //sampleStart 
   greet("Everyone") 
   //sampleEnd
}   

Expected behaviour

I'd expect markdown that looks something closer to this:

## Samples  
[jvm]
```kotlin
fun basicSample() {
   //sampleStart 
   greet("Everyone") 
   //sampleEnd
}
```

Screenshots
This is an example of how the current markdown will be rendered:
Screen Shot 2020-12-01 at 2 11 24 PM

Here's what I'd expect to see:
Screen Shot 2020-12-01 at 2 13 34 PM

Ideally the "//sampleStart" and "//sampleEnd" would also be gone, but that's perhaps a different issue.

To Reproduce
See above for a basic example.

Here is a fork of the Dokka Gradle example from Kotlin's examples repo with a sample set up as well: dokka-gradle-example.zip

Dokka configuration
Configuration of dokka used to reproduce the bug

tasks.withType<DokkaTask>().configureEach {
    dokkaSourceSets {
        named("main") {
            // ...
            samples.from("samples/Sample.kt")
        }
    }
}

Installation

  • Operating system: macOS
  • Build tool: Gradle v6.5.1
  • Dokka version: 1.4.0
@bherbst bherbst added the bug label Dec 1, 2020
@MarcinAman MarcinAman added the format: gfm An issue/PR related to Dokka's GFM output format label Apr 15, 2021
@DanielRibeiroMaciel-TomTom
Copy link

We would also like to see that fixed. Code blocks now get pasted without indentation and without formatting.
Even if using code fences in kdoc:

/**
 *```json
 *  (write some json here)
 *```
 */

The triple quotes markup disappears when converted to gfm, it is not present on the md file.

@ghost
Copy link

ghost commented May 3, 2021

Until this is fixed, we're using awk to clean these up. https://gist.github.com/carr-disco/e58b17a75fd102de44cc7312ca4d58db

@nomisRev
Copy link

nomisRev commented Aug 2, 2021

This seems to be broken not just for GFM but also for Jekyll.
Is there any news on this? This is blocking Arrow from migrating away from 0.10.x.

@sayan-chaliha
Copy link

This is definitely a blocker for hosting GFM documentation wikis. Even included *.md files are processed and code-blocks are removed from them.

@IgnatBeresnev
Copy link
Member

IgnatBeresnev commented Jul 12, 2022

Hi, can someone please check it on Dokka 1.7.0? I believe it should be fixed, at least to some degree. Implemented in #2485

For

/**
 * Print a greeting to the standard output
 *
 * @sample samples.basicSample
 */
fun greet(name: String) {
    println("Hello $name!")
}

Dokka generates the following:
2022-07-12_12-30-04

@sayan-chaliha
Copy link

Just checked it on 1.7.0 -- definitely better! Thanks!!

@IgnatBeresnev
Copy link
Member

I'll close the issue as implemented/fixed, but do let us know if you encounter any other problems related to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug format: gfm An issue/PR related to Dokka's GFM output format
Projects
None yet
Development

No branches or pull requests

6 participants