Giter Club home page Giter Club logo

antora-xref-extension's Introduction

Antora Xref Extension

The Antora Xref Extension augments Antora to improve xref macro handling.

Warning
This is ALPHA software! That means the extension is experimental and likely to change at any time without notice. You’re welcome to test it and give feedback, but take caution when relying on it in a production site.

Overview

The Antora Xref Extension augments Antora’s support for xref macros with the following features:

  • Validate that the target file contains an anchor that matches the fragment.

  • Use default link text from the title or reftext of the target.

  • Stub links that don’t yet exist

  • Produce warnings if link text is unnecessary

Note
This extension will slightly increase build times since .adoc files are parsed twice.

Prerequisites

In order to use this extension, you must be using Node.js 16 and Antora 3.1.0. The following instructions assume you’ve already set up an Antora playbook file (i.e., antora-playbook.yml) to build your site.

To learn about using extensions with Antora, see the Antora extension documentation.

Install

Use the following command to install the extension into your playbook project:

$ npm i @springio/antora-xref-extension

Register

Open your Antora playbook file and register the extension as an entry in the antora.extensions key. If this key doesn’t yet exist in your playbook, first create it.

antora-playbook.yml
antora:
  extensions:
  - require: '@springio/antora-xref-extension'

Configure

By default no configuration is required to use the extension. Once the extension has been registered macros of the form xref:version@component:module:file.adoc#fragment[] will:

  • Be validated to ensure the target file contains an anchor that matches the fragment.

  • Use default link text from the title or reftext of the target.

Additional configuration is only required for the additional features listed below.

Stubbed References

In some situations you may want to build an Antora content source that includes reference to sources that won’t be built until later.

For example, you may publish a complete docs site that aggregates several sources, but also want to be able to build those individual sources independently in order to catch errors early. In these situations it can be useful to defer errors and use stubbed links so that an individual build can run.

In order to stub xrefs you can provide regular expression patterns in the stub extension configuration. Any xref that matches the pattern will be replaced replaced with a link to the source document that defines it.

Note
If the xref doesn’t include link text then the full reference will be used as a placeholder.

The following example shows how any xref patterns that reference missingmodule can be stubbed:

antora-playbook.yml
antora:
  extensions:
  - require: '@springio/antora-xref-extension'
    stub:
    - 'missingmodule:.*'

Xref Text Warnings

If you have an existing document that uses fragment based xrefs, it’s likely that the link text will also be specified. This is necessary with a stock Antora installation because without the link text the URL of the published target page is displayed.

Since this extension can deduce the text to use for fragment links, you may want to simplify your markup.

For example, with the following files:

welcome.adoc
= Welcome

Hello

[[getting-started]]
== Getting Started
...
details.adoc
= Details
For details see xref:welcome.adoc#getting-started[Getting Started] for details.

The xref:welcome.adoc#getting-started[Getting Started] link can be simplified to xref:welcome.adoc#getting-started[].

To help catch links that can be simplified, you can configure the extension to log warnings when it finds unnecessary link text:

antora-playbook.yml
antora:
  extensions:
  - require: '@springio/antora-xref-extension'
    log-unnecessary-link-text-warnings: true

antora-xref-extension's People

Contributors

philwebb avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.