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

Internal links don't work on ODT writer #4358

Closed
josineto opened this issue Feb 12, 2018 · 3 comments
Closed

Internal links don't work on ODT writer #4358

josineto opened this issue Feb 12, 2018 · 3 comments

Comments

@josineto
Copy link
Contributor

josineto commented Feb 12, 2018

When I convert from markdown to ODT all the internal links (to headings) get broken. Example: using the following markdown file (named test.md):

# Heading {#foo}

Text with a reference to [Heading](#foo)

And the command below (pandoc 2.1.1):

pandoc -s -t odt test.md -o test.odt

Gives me an ODT file without the internal link. Looking inside the file, in content.xml, I found this:

<text:h text:style-name="Heading_20_1" text:outline-level="1">Heading</text:h>
<text:p text:style-name="First_20_paragraph">Text with a reference to <text:a xlink:type="simple" xlink:href="#foo" office:name="">
    <text:span text:style-name="Definition">Heading</text:span>
  </text:a>
</text:p>

Pandoc is not creating the anchor on the Heading, so any link points to nothing. The correct link would be something like this:

<text:h text:style-name="Heading_20_1" text:outline-level="1">
  <text:bookmark-start text:name="foo"/>Heading<text:bookmark-end text:name="foo"/>
</text:h>
<text:p text:style-name="First_20_paragraph">Text with a reference to <text:a xlink:type="simple" xlink:href="#foo" office:name="">
    <text:span text:style-name="Definition">Heading</text:span>
  </text:a>
</text:p>

To temporarily address this, I've written a Lua filter, that corrects the links using RawInline elements with format opendocument (as suggested by @jgm in this discussion ). But I think internal links are a common feature that needs to work in ODT "natively", without filters.

I've searched in pandoc-discuss and the issues, but it seems that there isn't much discussion about this.

@josineto
Copy link
Contributor Author

josineto commented Feb 12, 2018

Here goes the code of my Lua filter, if it helps.

local function getBookmarkById(id)
  local bookmarkStart = '<text:bookmark-start text:name=\"' .. id .. '\"/>'
  local bookmarkEnd = '<text:bookmark-end text:name=\"' .. id .. '\"/>'
  return bookmarkStart, bookmarkEnd
end

local function putMarksOnContent(textContent, id)
  local markStart, markEnd = getBookmarkById(id)
  local newContent = {}

  table.insert(newContent, pandoc.RawInline("opendocument", markStart))
  for i,el in pairs(textContent) do
    table.insert(newContent, el)
  end
  table.insert(newContent, pandoc.RawInline("opendocument", markEnd))
  return newContent
end

function Header (hx)
  if FORMAT == 'odt' then
    hx.content = putMarksOnContent(hx.content, hx.attr.identifier)
  end
  return hx
end

@josineto
Copy link
Contributor Author

josineto commented Feb 16, 2018

I've added a repository with some lua filters that workaround problems in ODT writer. Internal links are treated by odt-anchors.lua (it's almost exactly the same filter I put here). But that's a workaround, it would be very nice if that wasn't even necessary.

@mb21 mb21 added the writer label Mar 11, 2018
@josineto
Copy link
Contributor Author

Any points here?

@jgm jgm closed this as completed in 2b89aaf May 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants