-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Implement support for internal document links in ICML (#5541) #6606
Conversation
I see that I forgot to update the standard ICML tests. Will do... |
src/Text/Pandoc/Writers/ICML.hs
Outdated
makeContent :: Doc Text -> Doc Text | ||
makeContent cont | isEmpty cont = empty | ||
| length (show cont) < 25 = vcat [ | ||
selfClosingTag "HyperlinkTextDestination" | ||
[("Self", "HyperlinkTextDestination/"<>makeDestName (render Nothing cont)), ("Name","Destination"), ("DestinationUniqueKey","1")] | ||
, inTagsSimple "Content" $ flush cont | ||
] | ||
| otherwise = inTagsSimple "Content" $ flush cont |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm... not sure I understand what's going on here... why do add the HyperlinkTextDestination
only if the content is less than 25 long?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment above the method says it all
-- | NOTE: since we have no easy way to get actual named dests, we just create them for any short content blocks
AFAICT, there isn't anything in the Pandoc AST for a "destination", "bookmark" or "anchor", which is what I need here. I know I could do it with a custom span attribute that I would read in filter, but here I need it in the "core" writer. Instead, as a bit of a "hack", I just make any short content fragment as a link destination.
If you have a suggestion about how to set these bookmarks in the source - that I can find in the writer - I'm all ears!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, for that, the pandoc AST follows the HTML/markdown approach where you just can have an id
attribute on any element (that has Attr
), then link to it with #
. (and yes, for headers, the id
are auto-generated..) e.g.
$ pandoc -t native
# my title
my [span]{#anchor}
link [to title](#my-title)
link [to span](#anchor)
^D
[Header 1 ("my-title",[],[]) [Str "my",Space,Str "title"]
,Para [Str "my",Space,Span ("anchor",[],[]) [Str "span"]]
,Para [Str "link",Space,Link ("",[],[]) [Str "to",Space,Str "title"] ("#my-title","")]
,Para [Str "link",Space,Link ("",[],[]) [Str "to",Space,Str "span"] ("#anchor","")]]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - that was 1/3 of what I needed. The second third was figuring out how that shows up inside the writer itself, and in looking at the HTML and DocX writers, I worked that out (first param to the element!).
Now I have to figure out how to pass it through to the actual content writer...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accomplished!
@mb21 I've implemented proper support for named destinations/links/anchors (whatever they are called) for most of the standard types. I didn't do it for images and special divs - and will file a separate issue for those. Hopefully with these changes, we should be good to merge... |
I'll try to take a closer look tomorrow... by just skimming the code so far I'm wondering:
|
Thanks a lot! Really appreciate your time!
only those that have an
That's a good question! I will investigate how InDesign writes that out...
I don't know anything about the WriterState, so I just went with the extra arguments. If you give me some insight into WriterState - and think that is the better approach - I'll make the changes. You have more insight into Haskell and the "pandoc way" than I... |
would indeed end up with two Which is what my code would currently output... |
currently, the pandoc AST is somewhat limited: not all elements have Yeah, moving more stuff into the WriterState is probably best left to another pull request... since |
and what about a more contrived example?
I guess we should just output four |
@mb21 I added a test with your specific multilevel HTML. it only puts in the span IDs since destinations are tied to character ranges and not specific blocks (from what I can tell). |
Okay, yeah... guess that will be a little surprising, but maybe nested ids are a rare enough use-case to not hold up this pull. It's been quite some time since I worked with ICML, and when I wrote this writer, I was quite new to Haskell... so the longer I look at it, the more things I discover I would do different today... but yes, if you've tested this enough in InDesign, and feel people exporting to ICML could use this, then we should probably merge it :-) |
This looks good to me. I think @mb21 is right that using State to keep track of the style and identifier would be more elegant than threading through the parameters -- but of course it amounts to the same thing under the hood. The one issue remaining is the overlong line in the commit message, flagged by CI above. But actually it's probably best if you rebase your changes into one commit with a nice message summing up the changes. |
Ugh! I just messed up the rebase... @jgm Should I just start this PR over off another branch or are you OK with this? |
@lrosenthol it appears that there are git conflicts which would prevent merging, so I'm afraid these have to be resolved first. Can you rebase again? |
c3a9a19
to
5f71f79
Compare
OK - had to learn some new git commands, but I believe that everything is now good...watching the checks (definitely pass the commit length, so that's good - and no conflicts with base) |
Thanks! The macos CI failure is not related to the changes, it seems to affect all PRs. |
@jgm back to you for merging... |
@tarleb I wish I could figure out that macos failure, which keeps happening. |
Many thanks and congrats on your first Haskell PR! |
This PR addresses #5541 by supporting internal links when generating ICML. I added two tests - one for testing that URL links aren't broken and one for testing the new inter-doc functionality.
This is my first PR for Pandoc and my first time writing Haskell, so all comments welcome!