christopher-ramirez / secretary

Take the power of Jinja2 templates to OpenOffice and LibreOffice.
Other
190 stars 48 forks source link

Can I create links? #46

Open allenkim67 opened 6 years ago

allenkim67 commented 6 years ago

I read the hyperlink section in the readme but it looks like it only applies to links with variable in them? I would like to make a text link such as some text like "click me" that takes you to a link when you click it and the link destination itself is variable. Is something like this currently possible with this library?

allenkim67 commented 6 years ago

I've tried using the markdown filter and getting a strange result:

template: {{ abc|markdown }}

python file: engine.render(file_path, {'abc': '[asdf](http://google.com)'})

resulting odt file: b'<text:p text:style-name="Standard"><text:a xlink:href="http://google.com" xlink:type="simple">asdf</text:a></text:p>\n'

I just want the resulting file to contain the text asdf that you can click and go to google. Instead I am seeing the the xml code I pasted above. Any pointers to how to fix this problem?

RomainTT commented 6 years ago

What do you mean by "seeing the xml code" ?

allenkim67 commented 6 years ago

I was seeing raw xml code. Actually I found through reading the issues that you can use the safe filter like {{ abc|markdown|safe }}. This got around the problem of seeing raw xml, but still the output has some problems. In one editor I was seeing b'asdf. So pretty much correct except theb' part. In another editor i was seeing b'\n, so totally unusable.

I'm wondering if markdown is the only way to create links where the url is a variable?

christopher-ramirez commented 6 years ago

Hello! Recently I've made some code changes in the section handling XML reserved chars escaping and encoding of \n and \t into their corresponding ODF entities. I have to try if the issue with the mysterious b you are reporting is related to this. See #44.

Now, with:

I would like to make a text link such as some text like "click me" that takes you to a link when you click it and the link destination itself is variable

This is something Secretary already supports and documented in [Hyperlink Section)[https://github.com/christopher-ramirez/secretary#hyperlink--support].

In the link's target property you can include a viable prepending it with the secretary: scheme. .e.g: secrerary:{{ url_containing_variable }}

Would appreciate more comments or information on this.

christopher-ramirez commented 6 years ago

I could not reproduce the mysterious b' bug using latest pip version nor the last version on master branch.

Please double check your template or provide more context to track this issue.