Skip to content

Commit

Permalink
Kotlin docs: remove unwanted enum constructors.
Browse files Browse the repository at this point in the history
This is a workaround for a Dokka GFM issue I reported:
Kotlin/dokka#2468

I updated the format_kotlin_doc.py script to
remove the internal constructor calls for members of the Body enum.
  • Loading branch information
cosinekitty committed Apr 25, 2022
1 parent 5708ae3 commit 737fb01
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 39 deletions.
52 changes: 52 additions & 0 deletions generate/kotlindoc/format_kotlin_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@
import shutil


SymbolsWithUnwantedArgs = [
'SSB',
'EMB',
'Moon',
'Sun',
'Mercury',
'Venus',
'Earth',
'Mars',
'Jupiter',
'Saturn',
'Uranus',
'Neptune',
'Pluto'
]


def RemoveJvmTags(text):
fix = text.replace(' | [jvm]', '')
fix = fix.replace('[jvm]\\\n', '')
Expand Down Expand Up @@ -39,9 +56,44 @@ def RemoveEnumProperties(text):
return text


def RemovePrivateConstructors(text):
# enum class Body contains a private constructor where members
# can initialize their internal properties.
# This is leaking into the dokkaGfm output.
# I submitted the following issue about this:
# https://github.com/Kotlin/dokka/issues/2468
# Example:
# | [Saturn](-saturn/index.md) | [jvm]<br>[Saturn](-saturn/index.md)(SATURN_GM, 10759.22, VsopModel(vsopLonSaturn, vsopLatSaturn, vsopRadSaturn))<br>The planet Saturn. |
# should be converted to:
# | [Saturn](-saturn/index.md) | [jvm]<br>The planet Saturn. |
fix = text
for sym in SymbolsWithUnwantedArgs:
prefix = '<br>[' + sym + ']'
front = fix.find(prefix)
if front >= 0:
# Chop out the entire section that contains the unwanted constructor call.
back = fix.find('<br>', front + len(prefix))
if back > front:
fix = fix[:front] + fix[back:]

# Another case: the individual enum member has its own index.md file.
# This has an unwanted constructor call.
if ('# ' + sym + '\n') in fix:
prefix = '\n[' + sym + '](index.md)('
front = fix.find(prefix)
if front >= 0:
suffix = '\n'
back = fix.find(suffix, front + len(prefix))
if back > front:
fix = fix[:front] + fix[back + len(suffix):]

return fix


def FixMarkdown(text):
fix = RemoveEnumProperties(text)
fix = RemoveJvmTags(fix)
fix = RemovePrivateConstructors(fix)
return fix


Expand Down
2 changes: 0 additions & 2 deletions source/kotlin/doc/-body/-e-m-b/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

# EMB

[EMB](index.md)(EARTH_GM + MOON_GM, MEAN_SYNODIC_MONTH, null)

The Earth/Moon Barycenter.

2 changes: 0 additions & 2 deletions source/kotlin/doc/-body/-earth/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

# Earth

[Earth](index.md)(EARTH_GM, EARTH_ORBITAL_PERIOD, VsopModel(vsopLonEarth, vsopLatEarth, vsopRadEarth))

The planet Earth. Some functions that accept a Body parameter will fail if passed this value because they assume that an observation is being made from the Earth, and therefore the Earth is not a target of observation.

2 changes: 0 additions & 2 deletions source/kotlin/doc/-body/-jupiter/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

# Jupiter

[Jupiter](index.md)(JUPITER_GM, 4332.589, VsopModel(vsopLonJupiter, vsopLatJupiter, vsopRadJupiter))

The planet Jupiter.

2 changes: 0 additions & 2 deletions source/kotlin/doc/-body/-mars/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

# Mars

[Mars](index.md)(MARS_GM, 686.98, VsopModel(vsopLonMars, vsopLatMars, vsopRadMars))

The planet Mars.

2 changes: 0 additions & 2 deletions source/kotlin/doc/-body/-mercury/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

# Mercury

[Mercury](index.md)(MERCURY_GM, 87.969, VsopModel(vsopLonMercury, vsopLatMercury, vsopRadMercury))

The planet Mercury.

2 changes: 0 additions & 2 deletions source/kotlin/doc/-body/-moon/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

# Moon

[Moon](index.md)(MOON_GM, MEAN_SYNODIC_MONTH, null)

The Earth's natural satellite, the Moon.

2 changes: 0 additions & 2 deletions source/kotlin/doc/-body/-neptune/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

# Neptune

[Neptune](index.md)(NEPTUNE_GM, NEPTUNE_ORBITAL_PERIOD, VsopModel(vsopLonNeptune, vsopLatNeptune, vsopRadNeptune))

The planet Neptune.

2 changes: 0 additions & 2 deletions source/kotlin/doc/-body/-pluto/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

# Pluto

[Pluto](index.md)(PLUTO_GM, 90560.0, null)

The planet Pluto.

2 changes: 0 additions & 2 deletions source/kotlin/doc/-body/-s-s-b/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

# SSB

[SSB](index.md)(null, null, null)

The Solar System Barycenter.

2 changes: 0 additions & 2 deletions source/kotlin/doc/-body/-saturn/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

# Saturn

[Saturn](index.md)(SATURN_GM, 10759.22, VsopModel(vsopLonSaturn, vsopLatSaturn, vsopRadSaturn))

The planet Saturn.

2 changes: 0 additions & 2 deletions source/kotlin/doc/-body/-sun/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

# Sun

[Sun](index.md)(SUN_GM, null, null)

The Sun.

2 changes: 0 additions & 2 deletions source/kotlin/doc/-body/-uranus/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

# Uranus

[Uranus](index.md)(URANUS_GM, 30685.4, VsopModel(vsopLonUranus, vsopLatUranus, vsopRadUranus))

The planet Uranus.

2 changes: 0 additions & 2 deletions source/kotlin/doc/-body/-venus/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

# Venus

[Venus](index.md)(VENUS_GM, 224.701, VsopModel(vsopLonVenus, vsopLatVenus, vsopRadVenus))

The planet Venus.

26 changes: 13 additions & 13 deletions source/kotlin/doc/-body/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ The enumeration of celestial bodies supported by Astronomy Engine.

| | |
|---|---|
| [SSB](-s-s-b/index.md)<br>[SSB](-s-s-b/index.md)(null, null, null)<br>The Solar System Barycenter. |
| [EMB](-e-m-b/index.md)<br>[EMB](-e-m-b/index.md)(EARTH_GM + MOON_GM, MEAN_SYNODIC_MONTH, null)<br>The Earth/Moon Barycenter. |
| [Moon](-moon/index.md)<br>[Moon](-moon/index.md)(MOON_GM, MEAN_SYNODIC_MONTH, null)<br>The Earth's natural satellite, the Moon. |
| [Sun](-sun/index.md)<br>[Sun](-sun/index.md)(SUN_GM, null, null)<br>The Sun. |
| [Pluto](-pluto/index.md)<br>[Pluto](-pluto/index.md)(PLUTO_GM, 90560.0, null)<br>The planet Pluto. |
| [Neptune](-neptune/index.md)<br>[Neptune](-neptune/index.md)(NEPTUNE_GM, NEPTUNE_ORBITAL_PERIOD, VsopModel(vsopLonNeptune, vsopLatNeptune, vsopRadNeptune))<br>The planet Neptune. |
| [Uranus](-uranus/index.md)<br>[Uranus](-uranus/index.md)(URANUS_GM, 30685.4, VsopModel(vsopLonUranus, vsopLatUranus, vsopRadUranus))<br>The planet Uranus. |
| [Saturn](-saturn/index.md)<br>[Saturn](-saturn/index.md)(SATURN_GM, 10759.22, VsopModel(vsopLonSaturn, vsopLatSaturn, vsopRadSaturn))<br>The planet Saturn. |
| [Jupiter](-jupiter/index.md)<br>[Jupiter](-jupiter/index.md)(JUPITER_GM, 4332.589, VsopModel(vsopLonJupiter, vsopLatJupiter, vsopRadJupiter))<br>The planet Jupiter. |
| [Mars](-mars/index.md)<br>[Mars](-mars/index.md)(MARS_GM, 686.98, VsopModel(vsopLonMars, vsopLatMars, vsopRadMars))<br>The planet Mars. |
| [Earth](-earth/index.md)<br>[Earth](-earth/index.md)(EARTH_GM, EARTH_ORBITAL_PERIOD, VsopModel(vsopLonEarth, vsopLatEarth, vsopRadEarth))<br>The planet Earth. Some functions that accept a Body parameter will fail if passed this value because they assume that an observation is being made from the Earth, and therefore the Earth is not a target of observation. |
| [Venus](-venus/index.md)<br>[Venus](-venus/index.md)(VENUS_GM, 224.701, VsopModel(vsopLonVenus, vsopLatVenus, vsopRadVenus))<br>The planet Venus. |
| [Mercury](-mercury/index.md)<br>[Mercury](-mercury/index.md)(MERCURY_GM, 87.969, VsopModel(vsopLonMercury, vsopLatMercury, vsopRadMercury))<br>The planet Mercury. |
| [SSB](-s-s-b/index.md)<br>The Solar System Barycenter. |
| [EMB](-e-m-b/index.md)<br>The Earth/Moon Barycenter. |
| [Moon](-moon/index.md)<br>The Earth's natural satellite, the Moon. |
| [Sun](-sun/index.md)<br>The Sun. |
| [Pluto](-pluto/index.md)<br>The planet Pluto. |
| [Neptune](-neptune/index.md)<br>The planet Neptune. |
| [Uranus](-uranus/index.md)<br>The planet Uranus. |
| [Saturn](-saturn/index.md)<br>The planet Saturn. |
| [Jupiter](-jupiter/index.md)<br>The planet Jupiter. |
| [Mars](-mars/index.md)<br>The planet Mars. |
| [Earth](-earth/index.md)<br>The planet Earth. Some functions that accept a Body parameter will fail if passed this value because they assume that an observation is being made from the Earth, and therefore the Earth is not a target of observation. |
| [Venus](-venus/index.md)<br>The planet Venus. |
| [Mercury](-mercury/index.md)<br>The planet Mercury. |

0 comments on commit 737fb01

Please sign in to comment.