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

Warning if reference cannot be found #2268

Closed
vogella opened this issue Jun 19, 2017 · 8 comments · Fixed by #2270
Closed

Warning if reference cannot be found #2268

vogella opened this issue Jun 19, 2017 · 8 comments · Fixed by #2270
Assignees
Milestone

Comments

@vogella
Copy link

vogella commented Jun 19, 2017

I frequently find that a reference is not working anymore. Would be great if Asciidoctor could (either always or optional) issue a warning for that.

We use a small Gradle extension to fail our documentation builds if a warning is issued.

Would be great if we could avoid having missing cross-references also.

Example:

[[testing]]
== Section 1

== Section 2

See <<testing1>>.
@vogella
Copy link
Author

vogella commented Jun 19, 2017

@fap- can you please have a look?

@mojavelinux
Copy link
Member

This is all part of the fix I'm working on for #858. Pulling one thread tugs on a whole row of related behaviors.

The reason we aren't warning for invalid xrefs is because we don't yet catalog all the targets (i.e., anchors). We've added some additional ones, but we still have some to go. What we could do in the meantime is report any mismatches when the verbose flag is on. Once we can validate all of them, we can warn even when the verbose flag is not on.

Related: #2257.

@mojavelinux
Copy link
Member

Btw, this required some design work because AsciiDoc Python never tracked references at all. So we've had to define what it means to catalog the references so we're in a position to validate them. It's definitely a process.

@mojavelinux
Copy link
Member

Here's the line in substitutors.rb where the xref is matched to a ref:

# handles: id or Section Title
else
# resolve fragment as reftext if it's not a known ID and resembles reftext (includes space or has uppercase char)
if !(@document.catalog[:ids].key? fragment) &&
((fragment.include? ' ') || fragment.downcase != fragment) &&
(resolved_id = @document.catalog[:ids].key fragment)
fragment = resolved_id
end
refid, target = fragment, %(##{fragment})
end

Notice we don't yet validate there. But we could.

fapdash added a commit to vogellacompany/asciidoctor that referenced this issue Jun 20, 2017
The warning has the following form:
asciidoctor: WARNING: could not resolve xref:

closes asciidoctor#2268
fapdash added a commit to vogellacompany/asciidoctor that referenced this issue Jun 20, 2017
The warning has the following form:
asciidoctor: WARNING: could not resolve xref:

closes asciidoctor#2268
mojavelinux pushed a commit to vogellacompany/asciidoctor that referenced this issue Jun 23, 2017
@vogella
Copy link
Author

vogella commented Jun 26, 2017

Thanks, @mojavelinux for applying the patch and thanks to @fap- for providing the patch. This is very, very helpful to avoid errors in our documentation build.

@mojavelinux
Copy link
Member

👍

And this will only get better as we continue to map out more of the reference graph. I'm looking forward to #44, #1918, and #2257, all slated for 1.5.7.

@astubbs
Copy link

astubbs commented Aug 30, 2018

This doesn't seem to work from the gradle plugin..? I don't get any warnings printed out..

@mojavelinux
Copy link
Member

Most reference warnings only show when verbose mode is enabled. I can't remember if this setting is available via the Gradle plugin. I would follow-up there: https://github.com/asciidoctor/asciidoctor-gradle-plugin

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

Successfully merging a pull request may close this issue.

4 participants