-
-
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
OpenDocument writer: Allow references for internal links #6774
OpenDocument writer: Allow references for internal links #6774
Conversation
Thank you for opening this PR, that seems to be a useful pair of features. In order to make this a good experience for everyone, I'd like to learn a bit about your motivation and expectation for this PR: Which statements fits best?
Both options work for us and will cost us similar amounts of time, so feel free to indicate your choice. |
Hi Albert, I am in situation 1. with regards to the code. This code is already in use - but I am very open to improving it. My total Haskell experience (and knowledge) constitutes one course at university 19 years ago - and now a number of patches to pandoc. I'm sure the code is very crude from an experienced Haskell programmers perspective. Thank you for your time. |
Great, thanks for the feedback! I'll do an in-depth review within the next few days. |
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.
There is a joke in the Haskell community that there are no advanced Haskellers, as everybody is intermediate forever. Hope my comments are helpful regardless.
7e15ce2
to
8697ccd
Compare
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.
LGTM!
8697ccd
to
5f8f16c
Compare
a76e73e
to
287784c
Compare
@jgm any chance you could give this one a review as well? |
I'm not sure I understand what these extensions do. Can you explain a bit more, maybe with an example? |
Well, the first option changes from links to references - in OpenDocument a reference is something that updates with the target text, so a heading of "Introduction" will have a reference called "Introduction", and if a later editor of the generated document changes "Introduction" to "Background" then the reference will also change to "Background" which the link will not. The second option number prefixes references to headings. So instead of in the generated text having "(see Introduction)" we would have "(see 1. Introduction)" This is especially useful for printed documents where there are no links - chapter numbers become really useful. I've tried to describe this quite thoroughly in the manual changes. |
287784c
to
5d98582
Compare
@jgm I'm wondering if you've had time to consider this and whether you would like me to look at alternative approaches. The fact is I'm not the happiest with this approach. In the original format in my case the "References" identified here are of the type "xref" which do not have a "link text". Because the Link type in pandoc expects a link text the Docbook reader constructs one, and essentially what I'm doing the OpenDocument writer is removing the Link text from identified references and turning them back into references. This could probably be done better by creating an Xref or InternalReference or similar inline type in the pandoc-types repo and extending the AST in that way. This is a bit more work - but I suspect there are many other formats that would make better use of xrefs rather than links. Let me know how you wish to proceed. |
So with no extension a link looks like <text:a xlink:type="simple" xlink:href="#chapter1" office:name=""><text:span text:style-name="Definition">The
Chapter</text:span></text:a> With <text:bookmark-ref text:reference-format="text" text:ref-name="chapter1">The
Chapter</text:bookmark-ref> And with <text:bookmark-ref text:reference-format="number" text:ref-name="chapter1"></text:bookmark-ref><text:s /><text:bookmark-ref text:reference-format="text" text:ref-name="chapter1">The
Chapter</text:bookmark-ref> Correct? |
Yes - the interesting thing to keep in mind is that the contents of:
is dynamic - i.e. if it header for |
So, do I understand correctly that the text provided, "The Chapter" , is just ignored in the second two cases? |
It's a placeholder until the document is refreshed, visible but temporary. We could also skip it - and just have this empty until the document is refreshed. |
So, this means that if someone specifies a link in Markdown like
then these extensions will ignore the description they write and substitute the actual name of the linked resource? |
I think this could be made clearer in the documentation. People who understand the odt/opendocument format well will understand what you wrote, but many users won't. Saying explicitly that the link text in links to internal targets will be replaced by the text from the linked section heading (or image or?) would be helpful. |
5d98582
to
de2b2e3
Compare
Ok, done. Hope this is clear now. |
MANUAL.txt
Outdated
#### Extension: `references_over_links` #### | ||
|
||
Links to headings, figures and tables inside the document are | ||
substituted with (cross-)references. References use the text | ||
of the referenced document element such as the heading text, | ||
figure or table caption. The original link text is replaced once | ||
the generated document is refreshed. | ||
|
||
This extension can be enabled/disabled for the following formats: | ||
|
||
output formats | ||
: `odt`, `opendocument` | ||
|
||
#### Extension: `number_prefix_references` #### | ||
|
||
Add a number prefix to references within the document that lack one. | ||
For example a first heading of "Introduction" that is number prefixed | ||
in the final document as "1 Introduction" will in references also be | ||
number prefixed as "1 Introduction". | ||
|
||
This typically requires the final document to have indexes refreshed | ||
in a native editor such as libreoffice as pandoc is not aware of the | ||
number style of the document. | ||
|
||
This further assumes that references are used within the document | ||
instead of links - see the `references_over_links` extension. | ||
|
||
output formats | ||
: `odt`, `opendocument` | ||
|
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.
I'm concerned that a reader might think "references" refers to markdown link references or something like that. Lots of formats have things called "references."
Would using the term "crossreferences" or something like "xrefs" be clearer? Maybe the extension should be crossrefs
and numbered_crossrefs
? (The latter could automatically enable use of cross-references, so people wouldn't have to specify both.)
Do you think these would apply to other formats besides opendocument/docx?
It may be that these names are the best, but I think we should hash out alternatives first, because this is an API change and hard to reverse.
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.
What about xrefs_for_internal_links
and numbered_xrefs
? I think that should be very clear - but my perception is slanted.
This should be applicable to OpenDocument, Docx most probably, and DocBook output formats. At least.
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, I like that better.
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.
One thing that occurs to me, though, is that with xrefs_for_internal_links
one might expect that all internal links would become xrefs. xrefs
by itself doesn't imply this and may for that reason be better (also shorter). I think you'd probably need to look in the manual to figure out what it does, but that is probably true regardless of the name.
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.
Ok - xrefs
and numbered_xrefs
it is. And numbered_xrefs
enables xrefs
. Thanks for your patience.
de2b2e3
to
cbfa73e
Compare
Just a thought: why not have the |
I guess it becomes very ODT specific then - and also a bit inconsistent. The This isn't quite the pick-and-choose scenario I'm afraid.
This is quite hairy I'm afraid - not at all a clear cut case - ODT was not designed with this use-case in mind. |
Hm. What does the xrefs extension now return for the "name and number" for figures and tables? Is it "Figure 1" or is it "1 The caption of the figure" or what? If the extension returns "Figure 1" for figures and the text of the section heading (e.g. "Introduction") for headings, that seems quite inconsistent. I would have expected it to work in the same way in both cases. |
cbfa73e
to
f8d4584
Compare
You were right to push on this - I've now done quite a bit of work to make this make more sense and managed to find the right XML syntax to accomplish the Now Quite a long journey - but it looks much better. |
This commit adds two extensions to the OpenDocument writer, `xrefs_name` and `xrefs_number`. Links to headings, figures and tables inside the document are substituted with cross-references that will use the name or caption of the referenced item for `xrefs_name` or the number for `xrefs_number`. For the `xrefs_number` to be useful heading numbers must be enabled in the generated document and table and figure captions must be enabled using for example the `native_numbering` extension. In order for numbers and reference text to be updated the generated document must be refreshed.
f8d4584
to
69f95ed
Compare
@jgm Is this good to go? Let me know if there's anything more we need. |
Looks good! |
Thanks! |
This commit adds two extensions to the OpenDocument writer,
references_over_links
andnumber_prefix_references
.The first extension,
references_over_links
, substitutes documentinternal links for references to headers, figures and tables.
Text in references is kept consistent with the referenced header,
table or figure which is an improvement if the document is edited
after being generated by pandoc.
The second extension
number_prefix_references
will prefix theheader references with the number according to the style of the
referenced heading in the final document. As noted in the MANUAL.txt
the document will need to have indexes updated for these numbers
to be generated - similarly to table of contents in OpenDocument.
Figure and table references are not number prefixed as the numbers
for those are inline in the caption.