Skip to content

dokkaHtml preserves teletype formatting, but dokkaGfm unhelpfully strips it #2477

@cosinekitty

Description

@cosinekitty

Describe the bug
In my Kotlin comments, I often refer to a parameter name or other code symbol using backquotes, as is typical in Markdown to render teletype/monospace text. For example, my remarks about eclipticSeparation in:

/**
 * Determines visibility of a celestial body relative to the Sun, as seen from the Earth.
 *
 * This function returns an [ElongationInfo] object, which provides the following
 * information about the given celestial body at the given time:
 *
 * - `visibility` is an enumerated type that specifies whether the body is more easily seen
 *    in the morning before sunrise, or in the evening after sunset.
 *
 * - `elongation` is the angle in degrees between two vectors: one from the center of the Earth to the
 *    center of the Sun, the other from the center of the Earth to the center of the specified body.
 *    This angle indicates how far away the body is from the glare of the Sun.
 *    The elongation angle is always in the range [0, 180].
 *
 * - `eclipticSeparation` is the absolute value of the difference between the body's ecliptic longitude
 *   and the Sun's ecliptic longitude, both as seen from the center of the Earth. This angle measures
 *   around the plane of the Earth's orbit, and ignores how far above or below that plane the body is.
 *   The ecliptic separation is measured in degrees and is always in the range [0, 180].
 *
 * @param body
 * The celestial body whose visibility is to be calculated.
 *
 * @param time
 * The date and time of the observation.
 */
fun elongation(body: Body, time: Time): ElongationInfo {
    val relativeLongitude = pairLongitude(body, Body.Sun, time)
    val elongation = angleFromSun(body, time)
    return if (relativeLongitude > 180.0)
        ElongationInfo(time, Visibility.Morning, elongation, 360.0 - relativeLongitude)
    else
        ElongationInfo(time, Visibility.Evening, elongation, relativeLongitude)
}

dokkaHtml respects this notation and converts this into

<code class="lang-kotlin">eclipticSeparation</code> is the absolute value of ...

This is the desired behavior. However, dokkaGfm strips out the backquotes and converts into plain text:

- 
   eclipticSeparation is the absolute value of ...

Expected behaviour
Backquotes should be left intact in dokkaGfm's markdown output, so that it is clear which parts of the text are prose, and which are source code excerpts. For example:

-  `eclipticSeparation` is the absolute value of ...

Screenshots
N/A

To Reproduce

  1. Clone the Astronomy Engine repository and change into its directory.
  2. git checkout -b backquote 53f5540f09df94baae112c56b9fb5066175d8a0f
  3. cd source/kotlin
  4. ./gradlew dokkaGfm dokkaHtml
  5. Edit the file source/kotlin/build/dokka/gfm/astronomy/io.github.cosinekitty.astronomy/elongation.md. Notice that the backquotes have been removed from the documented symbols "visibility", "elongation", and "eclipticSeparation".
  6. However, dokkaHtml's output preserves the intended formatting. See the corresponding file source/kotlin/build/dokka/html/astronomy/io.github.cosinekitty.astronomy/-astronomy/elongation.html. This suggests the bug is specific to dokkaGfm.

Dokka configuration
(See repro steps above. The configuration is present in the directory source/kotlin.)

Installation

  • Operating system: Happens in all 3: macOS/Windows/Linux.
  • Build tool: Gradle v7.4.1
  • Dokka version: 1.6.10

Additional context

$ ./gradlew --version

------------------------------------------------------------
Gradle 7.4.1
------------------------------------------------------------

Build time:   2022-03-09 15:04:47 UTC
Revision:     36dc52588e09b4b72f2010bc07599e0ee0434e2e

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          11.0.13 (JetBrains s.r.o. 11.0.13+7-b1751.25)
OS:           Linux 4.19.0-20-amd64 amd64

Are you willing to provide a PR?
I am happy to provide whatever help the maintainers could use to reproduce/diagnose this bug. Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugformat: gfmAn issue/PR related to Dokka's GFM output formatgood first issueA beginner-friendly issue for which some assistance is expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions