Kotlin / dokka

API documentation engine for Kotlin
https://kotl.in/dokka
Apache License 2.0
3.45k stars 412 forks source link

Unrecognized resource type for valid image URL #1961

Open CommanderTvis opened 3 years ago

CommanderTvis commented 3 years ago

Describe the bug

Unrecognized resource type: ContentEmbeddedResource(children=[], address=https://img.shields.io/badge/dynamic/xml?color=orange&label=Space&query=//metadata/versioning/latest&url=https%3A%2F%2Fmaven.pkg.jetbrains.space%2Fmipt-npm%2Fp%2Fsci%2Fmaven%2Fspace%2Fkscience%2Fkmath-gsl%2Fmaven-metadata.xml, altText=Space, dci=[////PointingToDeclaration/][Comment], sourceSets=[DisplaySourceSet(sourceSetIDs=CompositeSourceSetID(children=[:dokkaHtml/nativeMain]), name=native, platform=native)], style=[], extra=PropertyContainer(map={}))

when compiling the following markdown:

[![Space](https://img.shields.io/badge/dynamic/xml?color=orange&label=Space&query=//metadata/versioning/latest&url=https%3A%2F%2Fmaven.pkg.jetbrains.space%2Fmipt-npm%2Fp%2Fsci%2Fmaven%2Fspace%2Fkscience%2Fkmath-gsl%2Fmaven-metadata.xml)](https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven/space/kscience/)

Space

To Reproduce

Create a project, include a markdown file with affected image and compile it to HTML.

Dokka configuration Configuration of dokka used to reproduce the bug

    tasks.withType<DokkaTask> {
        dokkaSourceSets.all {
            val readmeFile = File(projectDir, "./README.md")
        }
    }

Installation

MarcinAman commented 3 years ago

Hmm it doesn't work since link ends with .xml: https://github.com/Kotlin/dokka/blob/4c6ce7a2581074c9b8f3e82fb51d2d953db0d49b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt#L345

MarcinAman commented 3 years ago

Btw please keep in mind that the content of that link can be updated in the future so if you choose to publish your docs they may get out of sync as the link will point to newer version than is documented

CommanderTvis commented 3 years ago

Btw please keep in mind that the content of that link can be updated in the future so if you choose to publish your docs they may get out of sync as the link will point to newer version than is documented

shields.io more or less guarantees backward compatibility of all services.

vmishenev commented 1 year ago

Some resources do not have extensions at all. For example, the link to Kotlin playground script is https://unpkg.com/kotlin-playground@1 (see #3102) It might require introducing resource type since type is needed to render a resource on HTML pages. (inside head tag)

frne commented 1 month ago

Any update on this? It's not just shields.io, but many other services offering badges / status images (e.g. sonar) not working properly. As if a resource is an image can not be safely determined by URL, does it eventually make sense to remove the node.isImage() check?

whyoleg commented 1 month ago

From first look, removing node.isImage() check should be more or less safe in HtmlRenderer (and in markdown). All usages in Dokka of ContentEmbeddedResource are coming from images. Resources are a different story and don't affect the changes here, as in the end we will not embed this image in Dokka, but just use img HTML tag with remote link.

So I would say it will be rather safe to drop this check, not sure that we need additional customization here (e.g extension point). In worst case, if someone (for some unknown reason) creates ContentEmbeddedResource via external plugin, we will embed unresolved image instead of printing strange message :)

Does anyone want to contribute this fix?

  1. drop the comment
  2. drop the check
  3. write the test similar to this one but for HTML format. There is no tests for HTML content produced from markdown files, but there is for javadoc. In the end the test will look similar to this one, though URLs and paths will be different

Dropping the check should be easy, but writing tests might now, so if someone wants to contribute, I would try to help :)

frne commented 1 month ago

@whyoleg Thx for the update. I can do that :rocket:. Will propose a PR anytime soon.