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

[Feature Request] Make <a/> tag in headers optional when outputFormat: markdown #9720

Open
bohyunjung opened this issue Feb 22, 2024 · 5 comments
Labels
dotnet Generate .NET API reference docs

Comments

@bohyunjung
Copy link

Describe the bug

A rendered markdown file includes an empty <a/> tag in the markdown H1 title.
For example:

# <a id="Newtonsoft_Json_Generated_CustomBinding0_4"></a> Delegate CustomBinding0<TSelf, T0, T1, T2\>

Is this rendered for a reason, or is it a bug? What is the role of this element?

To Reproduce
Steps to reproduce the behavior:

Run docfx with metadata.outputFormat: "markdown" option.

Whole docfx.json
{
  "metadata": [
    {
      "src": [
        {
          "src": "..",
          "files": [
            "**/*.cs"
          ]
        }
      ],
      "dest": "api",
      "globalNamespaceId": "Global",
      "allowCompilationErrors": true,
      "namespaceLayout": "nested",
      "outputFormat": "markdown"
    }
  ]
}

Expected behavior

If rendering this empty <a/> element is unnecessary, I expect this not to be included in the markdown file.

Context (please complete the following information):

  • OS: macOS 14.2.1(23C71)
  • Docfx version: 2.75.3+a5c719410037cc288c7adff010b1abf3c0f2e581
  • Dotnet version: 7.0.403

Additional context

I'm working on a Unity package project, and I referenced the docfx settings of https://github.com/CaseyHofland/docfx-unitypackage.

@bohyunjung bohyunjung added the bug A bug to fix label Feb 22, 2024
@bohyunjung
Copy link
Author

FormattableString? ToHeading(int level, string title, string? id = null) =>
$"{new string('#', level)}{(string.IsNullOrEmpty(id) ? null : $" <a id=\"{id}\"></a>")} {Escape(title)}\n\n";

Ah, this should be an intended anchor tag. I see.

There would be some folks like me who aim to use these generated markdowns as a source to build the final HTML... So, making it optional whether to include the anchor tags in headings (and any other stuff intended to be included in the markdown as the final product) should introduce more flexibility to the markdown output usage?

@yufeih
Copy link
Contributor

yufeih commented Feb 22, 2024

The <a> tag creates a permalink and is useful to create links that points to an API on the page, in your example, an URL like <page-url>#Newtonsoft_Json_Generated_CustomBinding0_4 should link to the CustomBinding0 method instead of page top.

@bohyunjung
Copy link
Author

Yes, I understand they act as anchor tags, as you noted.

However, when more markdown rendering options are introduced later, I think the generation of the <a> tag is worth setting optional - especially for those using the docfx-generated markdowns as the source for the final doc. (Also, I didn't expect these docfx-generated markdowns to be ready-to-service since it is metadata outputFormat)

For now, I'll set up a post-process for the trimming the output.

Thank you for introducing the markdown generation feature. 💞

@yufeih
Copy link
Contributor

yufeih commented Feb 24, 2024

Looks like a legitimate request.

@bohyunjung bohyunjung changed the title [Bug] An empty <a/> tag is rendered in markdown H1 title [Feature Request] Make <a/> tag in headers optional when outputFormat: markdown Feb 25, 2024
@bohyunjung
Copy link
Author

Thanks.
I've changed the title to a feature request, but I don't have access to update the label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet Generate .NET API reference docs
Projects
None yet
Development

No branches or pull requests

2 participants