Html generated links have nofollow? #647

Closed
opened 2026-01-29 14:41:58 +00:00 by claunia · 3 comments
Owner

Originally created by @NetTecture on GitHub (Nov 29, 2023).

Any reference how to control that? Would like to not have nofollow for links that are - well - internal (and some external).

Originally created by @NetTecture on GitHub (Nov 29, 2023). Any reference how to control that? Would like to not have nofollow for links that are - well - internal (and some external).
claunia added the invalid label 2026-01-29 14:41:58 +00:00
Author
Owner

@xoofx commented on GitHub (Nov 30, 2023):

I don't think this is enabled by default. How do you create your MarkdownPipelineBuilder?

@xoofx commented on GitHub (Nov 30, 2023): I don't think this is enabled by default. How do you create your `MarkdownPipelineBuilder`?
Author
Owner

@NetTecture commented on GitHub (Dec 1, 2023):

static readonly MarkdownPipeline pipeline = new MarkdownPipelineBuilder()
    .UseAdvancedExtensions()
    .UseAutoLinks()
    .UseBootstrap()
    .Build();

public static string RenderToHtml(string text, bool inline = false)
{
    if (inline)
    {
        return RenderToHtmlInline(text);
    }
    return Markdown.ToHtml(text, pipeline);
}

public static string RenderToHtmlInline(string text)
{
    var document = Markdown.Parse(text, pipeline);

    StringWriter writer = new();
    var renderer = new HtmlRenderer(writer)
    {
        ImplicitParagraph = true // note this change
    };
    pipeline.Setup(renderer);

    renderer.Render(document); // using the renderer directly
    writer.Flush();
    string html = writer.ToString();
    html = html.Replace(" rel=\"nofollow\"", "");
    return html;
}

This is literally the complete code for my render pipeline at the moment.
@NetTecture commented on GitHub (Dec 1, 2023): static readonly MarkdownPipeline pipeline = new MarkdownPipelineBuilder() .UseAdvancedExtensions() .UseAutoLinks() .UseBootstrap() .Build(); public static string RenderToHtml(string text, bool inline = false) { if (inline) { return RenderToHtmlInline(text); } return Markdown.ToHtml(text, pipeline); } public static string RenderToHtmlInline(string text) { var document = Markdown.Parse(text, pipeline); StringWriter writer = new(); var renderer = new HtmlRenderer(writer) { ImplicitParagraph = true // note this change }; pipeline.Setup(renderer); renderer.Render(document); // using the renderer directly writer.Flush(); string html = writer.ToString(); html = html.Replace(" rel=\"nofollow\"", ""); return html; } This is literally the complete code for my render pipeline at the moment.
Author
Owner

@xoofx commented on GitHub (Dec 12, 2023):

I cannot see any usage of nofollow in the current codebase. I just created an exe with the latest Markdig 0.33 and I'm getting the correct output:

internal class Program
{
    static void Main(string[] args)
    {
        MarkdownPipeline pipeline = new MarkdownPipelineBuilder()
            .UseAdvancedExtensions()
            .UseAutoLinks()
            .UseBootstrap()
            .Build();

        var document = Markdown.Parse("Hello with a link [Hello](https://google.com)", pipeline);
        var html = document.ToHtml(pipeline);

        Console.WriteLine(html);
    }
}

Outputs:

<p>Hello with a link <a href="https://google.com">Hello</a></p>

So closing this bug as invalid because it is not reproduced.

@xoofx commented on GitHub (Dec 12, 2023): I cannot see any usage of nofollow in the current codebase. I just created an exe with the latest Markdig 0.33 and I'm getting the correct output: ```c# internal class Program { static void Main(string[] args) { MarkdownPipeline pipeline = new MarkdownPipelineBuilder() .UseAdvancedExtensions() .UseAutoLinks() .UseBootstrap() .Build(); var document = Markdown.Parse("Hello with a link [Hello](https://google.com)", pipeline); var html = document.ToHtml(pipeline); Console.WriteLine(html); } } ``` Outputs: ``` <p>Hello with a link <a href="https://google.com">Hello</a></p> ``` So closing this bug as invalid because it is not reproduced.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#647