Skip to content

[BUG] - URL parentheses are not URL-encoded/escaped in Markdown links #32

Description

@oxygen-dioxide

Affected projects

DocSharp.Docx

Description

When converting a .docx document to Markdown using DocSharp, URLs that contain parentheses (e.g., Wikipedia URLs) are not properly escaped or URL-encoded. This causes the resulting Markdown link syntax to break because the closing parenthesis of the URL prematurely terminates the Markdown link syntax [text](url).

To reproduce

  1. Create a Word document (.docx) containing a hyperlink with parentheses, such as https://en.wikipedia.org/wiki/Mole_(unit) (or download docsharp-link-bug.docx )
  2. Convert the file using the following C# snippet:
using DocSharp.Docx;
using System;
using System.IO;
using System.Text;

namespace DocSharpExample
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string inputPath = "docsharp-link-bug.docx"; // Path to test file
            var converter = new DocxToMarkdownConverter();
            string markdown = converter.ConvertToString(inputPath);
            Console.WriteLine(markdown);
        }
    }
}

Expected Behavior:

The URL should have its parentheses URL-encoded (( to %28 and ) to %29) so it doesn't break the Markdown syntax.
(For comparison, Python's markitdown handles this correctly):

35.45g/[mol](https://en.wikipedia.org/wiki/Mole_%28unit%29)

Actual Behavior (Bug):

The raw parentheses are preserved inside the link destination, which causes markdown parsers to fail at rendering the link properly:

35.45g/[<u>mol</u>](https://en.wikipedia.org/wiki/Mole_(unit))

Screenshot

No response

Version

0.20.0

.NET version

.NET framework 4.7.2

OS

Windows 11 26100

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions