1

I'm converting docx to Markdown using Pandoc.

Some links are converted to Markdown autolinks. I would like switch off the autolinks generation in Pandoc, but did not find a way to do that.

Background: The converted Markdown documents are used with Docusaurus which in term uses mdxjs which does not support autolinks.

Any ideas how to switch off autolinks in Pandoc?

1
  • what are autolinks? but either way, see pandoc.org/MANUAL.html perhaps there's an extension. Commented Feb 24 at 12:05

1 Answer 1

1

I'm assuming that "autolink" in the question refers to links such as <https://example.com>. We can use an implementation detail to prevent pandoc from generating these.

First, let's see how pandoc represents this kind of link internally:

$ pandoc -t native <<< '<https://example.org>' 
[ Para
    [ Link
        ( "" , [ "uri" ] , [] )
        [ Str "https://example.org" ]
        ( "https://example.org" , "" )
    ]
]

This means that pandoc treats this as a link that has the link target as title. But we also see that the link has a class uri. The Markdown generating code expects this exact structure for autolinks.

We can modify these links so it no longer matches the expected structure: for that, we remove the class and add an empty Str element to the link label with a Lua filter:

--- file: unautolink.lua
function Link (link)
  if link.classes == pandoc.List{"uri"} then
    -- remove uri class
    link.classes[1] = nil
    -- add an empty string to the link label
    link.content:insert(pandoc.Str '')
  end
  return link
end

Autolinks are turned into normal links when using this filter:

$ pandoc -t gfm -L noautolink.lua <<< '<https://example.org>'
[https://example.org](https://example.org)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.