4.14.0 • Published 7 months ago

gatsby-transformer-asciidoc v4.14.0

Weekly downloads
734
License
MIT
Repository
github
Last release
7 months ago

gatsby-transformer-asciidoc

Parses AsciiDoc files using Asciidoctor.js.

Install

npm install gatsby-transformer-asciidoc

How to use

// In your gatsby-config.js
plugins: [`gatsby-transformer-asciidoc`]

A full explanation of asciidoc can be found here: Asciidoctor.js

You can also pass all Asciidoctor's convert options to the transformer. An example would be:

// In your gatsby-config.js
plugins: [
  {
    resolve: `gatsby-transformer-asciidoc`,
    options: {
      attributes: {
        showtitle: true,
      },
    },
  },
]

Parsing algorithm

It recognizes files with the following extensions as AsciiDoc:

  • adoc
  • asciidoc

Additional extensions can be configured via the fileExtensions option:

// In your gatsby-config.js
plugins: [
  {
    resolve: `gatsby-transformer-asciidoc`,
    options: {
      attributes: {
        showtitle: true,
      },
      fileExtensions: [`ad`, `adoc`],
    },
  },
]

Each AsciiDoc file is parsed into a node of type asciidoc.

Set imagesdir

You also can define where the asciidoc file can find the images by setting the imagesdir attribute.

// In your gatsby-config.js
plugins: [
  {
    resolve: `gatsby-transformer-asciidoc`,
    options: {
      attributes: {
        imagesdir: `/images`,
      },
    },
  },
]

In the asciidoc file you can insert your image just by using: image::myimage.png[]

NOTE

  • If no imagesdir is set the default value is /images@
  • Don't use relative images paths because the images might not be copied automatically to the location where the converted asciidoc html file will to located.
  • In case a pathPrefix is set it will altered the images location.
  • In case you want to be able to override the defined imagesdir inside of your asciidoc file you have to end the path with a @ (e.g. /images@).

How to query

A sample GraphQL query to get AsciiDoc nodes:

{
  allAsciidoc {
    edges {
      node {
        html
        document {
          title
          subtitle
          main
        }
        author {
          fullName
          firstName
          lastName
          middleName
          authorInitials
          email
        }
        revision {
          date
          number
          remark
        }
      }
    }
  }
}

Add new node attributes in the asciidoc file

You can define in the asciidoc file your own data that will be automatically be attached to the node attributes.

Example

= AsciiDoc Article Title
Firstname Lastname <author@example.org>
1.0, July 29, 2018, Asciidoctor article template

:page-title: Article
:page-path: /my-blog-entry
:page-category: My Category

Each attribute with the prefix page- will be automatically added under pageAttributes so it can be used with GraphQL.

{
  allAsciidoc {
    edges {
      node {
        pageAttributes {
          title
          path
          category
        }
      }
    }
  }
}

Define a Custom Converter

You can define a custom converter by adding the converterFactory option.

// In your gatsby-config.js, make sure to import or declare CustomConverter
plugins: [
  {
    resolve: `gatsby-transformer-asciidoc`,
    options: {
      converterFactory: CustomConverter,
    },
  },
]

CustomConverter is a custom javascript class you'll need to create. Information on how to write a custom CustomConverter can be found at the asciidoctor docs.

In the example below, we will use a custom converter to convert paragraphs but the other nodes will be converted using the built-in HTML5 converter:

const asciidoc = require(`asciidoctor`)()

class CustomConverter {
  constructor() {
    this.baseConverter = asciidoc.Html5Converter.$new()
  }

  convert(node, transform) {
    if (node.getNodeName() === "paragraph") {
      return `<p>${node.getContent()}</p>`
    }

    return this.baseConverter.convert(node, transform)
  }
}

gatsby-transformer-asciidoc takes then this class, not a instance of CustomConverter, as the converterFactory option. You can also reuse the internal converter of gatsby-transformer-asciidoc, since the constructor of a given CustomConverter will be call with it as parameter.

4.15.0-next.0

7 months ago

4.14.0

8 months ago

4.13.1

1 year ago

4.14.0-next.2

1 year ago

4.14.0-next.1

1 year ago

4.13.0

2 years ago

4.14.0-next.0

2 years ago

4.12.0

2 years ago

4.12.0-next.0

2 years ago

4.11.0-next.0

2 years ago

4.11.0-next.1

2 years ago

4.10.0

2 years ago

4.13.0-next.0

2 years ago

4.11.0

2 years ago

4.9.0

2 years ago

4.10.0-next.0

2 years ago

4.10.0-next.1

2 years ago

4.10.0-next.2

2 years ago

4.8.0

2 years ago

4.7.0

2 years ago

4.8.0-next.0

2 years ago

4.9.0-next.0

2 years ago

4.6.0-next.0

2 years ago

4.7.0-next.0

2 years ago

4.6.0

2 years ago

4.5.0

2 years ago

4.4.0

2 years ago

4.3.0-next.0

3 years ago

4.0.0

3 years ago

4.2.0-next.0

3 years ago

3.25.0

3 years ago

4.0.0-next.1

3 years ago

4.0.0-next.0

3 years ago

4.0.0-next.3

3 years ago

4.0.0-next.2

3 years ago

4.5.0-next.0

2 years ago

4.1.0-next.0

3 years ago

2.15.0

3 years ago

4.3.0

3 years ago

4.2.0

3 years ago

4.4.0-next.1

2 years ago

4.4.0-next.0

3 years ago

4.1.0

3 years ago

3.24.0

3 years ago

3.23.0-next.0

3 years ago

3.22.0

3 years ago

3.23.0

3 years ago

3.24.0-next.0

3 years ago

3.25.0-next.0

3 years ago

3.17.0-next.0

3 years ago

3.22.0-next.0

3 years ago

3.19.0

3 years ago

3.16.0-next.0

3 years ago

3.19.0-next.0

3 years ago

3.19.0-next.1

3 years ago

3.19.0-next.2

3 years ago

3.21.0-next.0

3 years ago

3.20.0

3 years ago

3.17.0

3 years ago

3.21.0

3 years ago

3.18.0

3 years ago

3.18.0-next.1

3 years ago

3.18.0-next.0

3 years ago

3.15.0

3 years ago

3.20.0-next.0

3 years ago

3.16.0

3 years ago

3.15.0-next.0

3 years ago

3.14.0

3 years ago

3.13.0

3 years ago

3.14.0-next.2

3 years ago

3.14.0-next.1

3 years ago

3.14.0-next.0

3 years ago

3.12.1

3 years ago

3.12.0

3 years ago

3.12.0-next.0

3 years ago

3.13.0-next.0

3 years ago

3.10.0

3 years ago

3.11.0-next.0

3 years ago

3.11.0

3 years ago

3.10.0-next.1

3 years ago

3.10.0-next.0

3 years ago

3.9.0

3 years ago

3.6.0-next.0

3 years ago

3.6.0

3 years ago

3.8.0-next.0

3 years ago

3.9.0-next.0

3 years ago

3.4.0-next.0

4 years ago

3.5.0

3 years ago

3.4.0

4 years ago

3.8.0

3 years ago

3.5.0-next.0

4 years ago

3.3.0

4 years ago

3.7.0

3 years ago

3.7.0-next.1

3 years ago

3.7.0-next.0

3 years ago

3.2.0

4 years ago

3.3.0-next.0

4 years ago

3.1.0

4 years ago

3.2.0-next.0

4 years ago

3.1.0-next.0

4 years ago

3.0.0

4 years ago

3.0.0-zz-next.2

4 years ago

2.14.0

4 years ago

3.0.0-zz-next.1

4 years ago

3.0.0-zz-next.8

4 years ago

3.0.0-next.1

4 years ago

3.0.0-next.0

4 years ago

2.14.0-next.2

4 years ago

2.14.0-next.1

4 years ago

2.13.0

4 years ago

2.14.0-next.0

4 years ago

2.12.0

4 years ago

2.13.0-next.0

4 years ago

2.12.0-next.3

4 years ago

2.12.0-next.2

4 years ago

2.12.0-next.1

4 years ago

2.11.0

4 years ago

2.12.0-next.0

4 years ago

2.10.0

4 years ago

2.11.0-next.0

4 years ago

2.10.0-next.1

4 years ago

2.9.0

4 years ago

2.10.0-next.0

4 years ago

2.8.0

4 years ago

2.9.0-next.0

4 years ago

2.7.0

4 years ago

2.7.1

4 years ago

2.6.0

4 years ago

2.7.0-next.1

4 years ago

2.7.0-next.2

4 years ago

2.8.0-next.1

4 years ago

2.8.0-next.0

4 years ago

2.5.0-next.0

4 years ago

2.4.0

4 years ago

2.6.0-next.0

4 years ago

2.7.0-next.0

4 years ago

2.5.0

4 years ago

2.3.0

4 years ago

2.4.0-next.0

4 years ago

2.3.0-next.1

4 years ago

2.2.0

4 years ago

2.3.0-next.0

4 years ago

2.1.0

4 years ago

2.2.0-next.0

4 years ago

2.1.0-next.2

4 years ago

2.0.0

4 years ago

2.1.0-next.1

4 years ago

2.0.0-v3rc.0

4 years ago

2.1.0-next.0

4 years ago

2.0.0-next.0

4 years ago

1.10.0

4 years ago

1.11.0-next.0

4 years ago

1.9.0

4 years ago

1.10.0-next.0

4 years ago

1.8.0

4 years ago

1.9.0-next.0

4 years ago

1.8.0-next.1

5 years ago

1.7.0

5 years ago

1.8.0-next.0

5 years ago

1.6.0

5 years ago

1.7.0-next.0

5 years ago

1.5.0

5 years ago

1.6.0-next.0

5 years ago

1.5.0-next.1

5 years ago

1.4.0

5 years ago

1.4.0-next.1

5 years ago

1.5.0-next.0

5 years ago

1.3.16

5 years ago

1.4.0-next.0

5 years ago

1.3.15

5 years ago

1.3.14

5 years ago

1.3.13

5 years ago

1.3.12

5 years ago

1.3.11

5 years ago

1.3.10

5 years ago

1.3.9

5 years ago

1.3.7

5 years ago

1.3.6

5 years ago

1.3.5

5 years ago

1.3.4

5 years ago

1.3.3

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.26

5 years ago

1.1.25

5 years ago

1.1.24

5 years ago

1.1.23

5 years ago

1.1.22

5 years ago

1.1.21

6 years ago

1.1.20

6 years ago

1.1.18

6 years ago

1.1.17

6 years ago

1.1.16

6 years ago

1.1.15

6 years ago

1.1.14

6 years ago

1.1.13

6 years ago

1.1.12

6 years ago

1.1.10

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.2-alpha.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago