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

Local links to use <<anchor,text>> format #21

Open
briandominick opened this issue Jul 21, 2016 · 6 comments
Open

Local links to use <<anchor,text>> format #21

briandominick opened this issue Jul 21, 2016 · 6 comments

Comments

@briandominick
Copy link
Contributor

Right now when a hyperlink to a local anchor gets processed, it looks something like this:

#heading=h.cughuow97z4o[local link]

This seems to just be a direct copy, but I bet that ID is getting carried with the element being linked to, and we can grab that and use it to form proper local xref. We don't actually use a lot of local links, but these can be a little hard to convert since that hash string doesn't actually appear elsewhere in the converted, so it's not clear just what that local link lined up with.

<<anchor-to-heading-id-or-explicit-anchor,local link>>
@ggrossetie
Copy link
Owner

http://stackoverflow.com/a/12244248

I think we can only support this feature if the document has a TOC 😒

@briandominick
Copy link
Contributor Author

That's really interesting... but it's a fine workaround, right? If you have a lot of internal links, you could add a TOC before converting. I would find that useful.

@ggrossetie
Copy link
Owner

That's really interesting... but it's a fine workaround, right? If you have a lot of internal links, you could add a TOC before converting. I would find that useful.

Yes with this workaround I think it will be possible to resolve "link ids" (ie. #heading=h.cughuow97z4o) to their corresponding headings titles. So I may be able to create proper local xrefs.

However it's not possible to create a Table Of Contents. So basically if a TOC is not already present in the document we can't do nothing.

@briandominick
Copy link
Contributor Author

So we can detect the presence of a toc, and we can detect internal
hyperlinks. If a doc has internal links but no toc, we can echo to the ui
that adding a toc will enable those links.

I'm happy to take a swipe at this one if you want. I just haven't looked at
the DOM or seen what we're working with yet, so can't tell if I'll be in
over my head wrestling with this stuff.

On Jul 23, 2016 16:40, "Guillaume Grossetie" notifications@github.com
wrote:

That's really interesting... but it's a fine workaround, right? If you
have a lot of internal links, you could add a TOC before converting. I
would find that useful.

Yes with this workaround I think it will be possible to resolve "link ids"
(ie. #heading=h.cughuow97z4o) to their corresponding headings titles. So
I may be able to create proper local xrefs.

However it's not possible to create a Table Of Contents. So basically if a
TOC is not already present in the document we can't do nothing.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#21 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABNKMXGUbxkihXqXtcRrG8MVv716oHoOks5qYnxagaJpZM4JR-O6
.

@ggrossetie
Copy link
Owner

I'm happy to take a swipe at this one if you want. I just haven't looked at
the DOM or seen what we're working with yet, so can't tell if I'll be in
over my head wrestling with this stuff.

Sure!
The entry point is the document body : Code.gs#L49

Then we iterate on children : Code.gs#L50

Each child is an Element: https://developers.google.com/apps-script/reference/document/element

An Element can be a TableOfContents: https://developers.google.com/apps-script/reference/document/table-of-contents

The Google Apps Scripts documentation is pretty clear and you should find all the information there. When in doubt you can use a Logger to debug: https://developers.google.com/apps-script/reference/base/logger

Let me know if you need help 😉

@briandominick
Copy link
Contributor Author

Very cool; thanks for the cheat sheet.

On Sat, Jul 23, 2016 at 6:21 PM, Guillaume Grossetie <
notifications@github.com> wrote:

I'm happy to take a swipe at this one if you want. I just haven't looked at
the DOM or seen what we're working with yet, so can't tell if I'll be in
over my head wrestling with this stuff.

Sure!
The entry point is the document body
https://developers.google.com/apps-script/reference/document/document#getBody()
: Code.gs#L49
https://github.com/Mogztter/asciidoc-googledocs-addon/blob/master/app/Code.gs#L49

Then we iterate on children
https://developers.google.com/apps-script/reference/document/body#getChild(Integer)
: Code.gs#L50
https://github.com/Mogztter/asciidoc-googledocs-addon/blob/master/app/Code.gs#L50

Each child is an Element:
https://developers.google.com/apps-script/reference/document/element

An Element can be a TableOfContents:
https://developers.google.com/apps-script/reference/document/table-of-contents

The Google Apps Scripts documentation is pretty clear and you should find
all the information there. When in doubt you can use a Logger to debug:
https://developers.google.com/apps-script/reference/base/logger

Let me know if you need help 😉


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#21 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABNKMVRupt9Il7D1VDyXAAs_M3KWoOp1ks5qYpP1gaJpZM4JR-O6
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants