Skip to content

docx: Links in endnotes get mangled when converting to Markdown #2258

Closed
gohai opened this Issue · 12 comments

3 participants

@gohai

Converting endnotes that (solely?) contain a hyperlink produce an unexpected output in Markdown. Tested against 1.15.0.1. A link to "http://wikipedia.org/" would e.g. be converted to

This is a test[^1].

[^1]: [http://wikipedia.org/](styles.xml)

(Notice the styles.xml.) Any idea what is going on? I am using Word for Mac 2011.

The relevant part of the document.xml looks like this:

<w:r><w:rPr><w:rStyle w:val="EndnoteReference"/></w:rPr><w:endnoteReference w:id="1"/></w:r>

and endnotes.xml

<w:endnote w:id="1"><w:p w14:paraId="47FFD4FF" w14:textId="77777777" w:rsidR="00B723A8" w:rsidRDefault="00B723A8"><w:pPr><w:pStyle w:val="EndnoteText"/></w:pPr><w:r><w:rPr><w:rStyle w:val="EndnoteReference"/></w:rPr><w:endnoteRef/></w:r><w:r><w:t xml:space="preserve"> </w:t></w:r><w:hyperlink r:id="rId1" w:history="1"><w:r w:rsidR="008D3915" w:rsidRPr="008D3915"><w:rPr><w:rStyle w:val="Hyperlink"/></w:rPr><w:t>http://wikipedia.org/</w:t></w:r></w:hyperlink><w:bookmarkStart w:id="0" w:name="_GoBack"/><w:bookmarkEnd w:id="0"/></w:p></w:endnote>
@jgm
Owner
jgm commented

@jkr, any ideas?

@jkr
Collaborator
jkr commented

I'll take a look -- @gohai, would it be possible to get the problematic docx file, or a minimal example deminstrating the problem? Either uploaded to dropbox, or sent to my email address in the docx reader source? (I'm linux-only for the holiday weekend, so can't reliably generate the files myself.) Also, is this only with endnotes, or do footnotes display the same problem?

@gohai

@jkr Just checked: also happens with footnotes for me. I am sending you docx via email. Thanks for looking into it!

@jkr
Collaborator
jkr commented

@gohai: Got it -- thanks. I'll try to have a look at it by the end of the weekend.

@jgm jgm added the bug label
@jgm
Owner

@jkr, any luck figuring this one out?

@jkr
Collaborator

Well, I diagnosed the problem, anyway. The issue is that there is a separate relationships file for footnotes and endnotes (and presumably for every .xml file). So we have to look in word/_rels/{foot,end}notnotes.xml.rels instead of the document-level one. We can't just merge them either because there are overlapping relationship numbers. (that's where the "styles.xml" link came from).

I made a sort of braindead fix that works, but I'd been hoping to polish it a bit with time that never came. I'll post it one way or another later today.

@jgm
Owner
@gohai

@jkr I'd love to take the braindead fix for a spin if I can!

@jkr
Collaborator
jkr commented

It turned out to be too braindead.

I'm really sorry -- my book is overdue with my publishers, and I've been forsaking all else to get those last few changes in. It should be off within the week, and then I can turn to this. Of course, if anyone else wants to take a crack at it, I'd be happy to offer any insight I can. The problem is pretty simple (see above) but the solution seems fairly tough to get right without adding a bunch of spaghetti.

(Essentially, we need to know whether we're parsing from a footnote or main text, which is difficult at the moment, due to the recursive way we deal with parsing. We can always throw more state at the problem, but the attempts I made spun out of control pretty quickly.)

In any case, if no one else has a go at it, I should be able to turn my attention back to it pretty soon.

Sorry again,
Jesse

@gohai

@jkr I'd give it a try myself, but my proficiency of the language doesn't go beyond the hack'y one-liner unfortunately.. So thanks a ton for your work on the module, and we're happy to try out the bugfix whenever you find the time to spend on it really!

@jkr
Collaborator

I finally fixed this with e5b374e. Of course, as soon as I was able to give it some serious concentration the problem evaporated (at the expense of perhaps a bit more spaghetti in the parser). Many apologies for the long wait.

@jkr jkr closed this
@gohai

Thanks a ton @jkr! Will give this a try early next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.