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

Automatic hyperlinks #1

Open
anseljh opened this issue Aug 22, 2015 · 9 comments
Open

Automatic hyperlinks #1

anseljh opened this issue Aug 22, 2015 · 9 comments

Comments

@anseljh
Copy link
Member

anseljh commented Aug 22, 2015

Sometimes I have URLs in my contracts. It would be nice if this package would detect them and create hyperlink objects in the output Word file.

I think the right approach is to keep written-out URLs in the text, and just wrap them with hyperlink markup.

Some possbily helpful info on how to accomplish this:

@kemitchell
Copy link
Member

I see two parts here:

  1. Detect when URLs appear in fully resolved forms. It's all strings at that point, whether the URL was written into a form or placed as a fill-in-the-blank value.
  2. Output the correct XML.

A few leads:

https://www.npmjs.com/package/get-urls

https://github.com/commonform/commonform-docx/blob/master/templates/run.js#L47

@anseljh
Copy link
Member Author

anseljh commented Sep 22, 2015

Note to self, for later:

<w:hyperlink r:id="rId7" w:history="1"><w:r w:rsidRPr="009B49CC"><w:rPr><w:rStyle w:val="Hyperlink"/></w:rPr><w:t>Link content</w:t></w:r></w:hyperlink>

@anseljh anseljh self-assigned this Sep 22, 2015
@anseljh
Copy link
Member Author

anseljh commented Sep 24, 2015

@kemitchell
Copy link
Member

This looks promising: url-regex

@kemitchell
Copy link
Member

@anseljh
Copy link
Member Author

anseljh commented Sep 25, 2015

Cool, thanks. I may have some time over the weekend to put this together.

@kemitchell
Copy link
Member

Be warned: DOCX makes this kind of subtle. A nice first cut might be:

  1. hyperlink a fill-in-the-blank value if it's a valid URI
  2. hyperlink URI substrings of plain text

I personally wouldn't be too worried about links in headings, terms, or their combination with plain text.

@anseljh
Copy link
Member Author

anseljh commented Sep 25, 2015

Right, makes sense. I'm looking forward to this because I put links in my
website terms forms, and have to go linkify them manually after building
the .DOCX files. Obviously this will be great for HTML rendering too (and
presumably much easier).

@kemitchell
Copy link
Member

This came up again, and I looked at it again.

Basically, we can do the hyperlinks in the document easily enough. But we have to put the URLs they point do in a different XML file within the .docx ZIP archive.

document.xml.rels needs something like this:

<Relationship Id="example" Type="http://. . ./hyperlink" Target="http://www.example.com/" TargetMode="External"/>

in order to do this in document.xml:

<w:hyperlink r:id="example">
<w:r>
<w:rPr>
<w:rStyle w:val="Hyperlink"/>
</w:rPr>
<w:t>example.com</w:t>
</w:r>
</w:hyperlink>

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

2 participants