2.2.0 • Published 12 months ago

@yozora/gatsby-transformer v2.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

A gatsby plugin for transforming markdown files to markdown ast through Yozora Parser, Inspired by gatsby-transformer-remark.

Install

This plugin depends on Yozora Parser, as of now, you can choose @yozora/parser (Recommend) or @yozora/parser-gfm or @yozora/parser-gfm-ex.

  • npm

    npm install @yozora/gatsby-transformer @yozora/parser --save-dev
  • yarn

    yarn add @yozora/gatsby-transformer @yozora/parser --dev

Usage

Add configs in gatsby-config.mjs:

// gatsby-config.mjs
import { YozoraParser } = from '@yozora/parser'

module.exports = {
  plugins: [
    {
      resolve: '@yozora/gatsby-transformer',
      options: {
        parser: new YozoraParser(),
        preferFootnoteReferences: true,
        frontmatter: {
          excerpt_separator: '<!-- more -->',
        }
      }
    }
  ]
}

Options

NameRequiredDefault
parsertrue-
preferFootnoteReferencesfalsefalse
presetDefinitionsfalse-
presetFootnoteDefinitionsfalse-
headingIdentifierPrefixfalseheading-
footnoteIdentifierPrefixfalsefootnote-
shouldStripChineseCharsfalsefalse
wordsPerMinutefalse80
frontmatterfalse-
pluginsfalse-
  • parser: A yozora parser.

  • preferFootnoteReferences: Replace footnotes into footnote references and footnote reference definitions.

  • presetDefinitions: Preset link reference definitions.

  • presetFootnoteDefinitions: Preset footnote reference definitions.

  • headingIdentifierPrefix: The identifier prefix of the headings that constitutes the toc (Table of Content).

  • footnoteIdentifierPrefix: The identifier prefix of the footnote references and footnote reference definitions.

  • shouldStripChineseChars: Whether to remove line end between two chinese characters.

  • wordsPerMinute: The number of words read per minute.

  • frontmatter: Options for gray-matter.

  • plugins: Plugins of @yozora/gatsby-transformer, similar with the plugins option of gatsby-transformer-remark.

    /**
    * Api passed to the options.plugins
    */
    export interface AstMutateApi {
      files: Node[]
      markdownNode: Node
      markdownAST: Root
      pathPrefix: string
      getNode(id: string): Node
      reporter: Reporter
      cache: GatsbyCache
    }
    
    function plugin(api: AstMutateApi, pluginOptions: any): void
    • api: passed by @yozora/gatsby-transformer
    • pluginOptions: defined in gatsby-config.js, such as the highlighted line in the following code (line eight)

      const presetDefinitions = []
      const presetFootnoteDefinitions = []
      
      {
        resolve: '@yozora/gatsby-transformer',
        options: {
          parser: new YozoraParser({
            defaultParseOptions: {
              shouldReservePosition: false,
              presetDefinitions,
              presetFootnoteDefinitions,
            },
          }),
          presetDefinitions,
          presetFootnoteDefinitions,
          preferFootnoteReferences: true,
          shouldStripChineseCharacters: true,
          frontmatter: {
            excerpt_separator: '<!-- more -->',
          },
          plugins: [
            {
              resolve: '@yozora/gatsby-images',
              options: {},    // this is the pluginOptions.
            },
          ],
        },
      }

Features

  • Code (Yozora Code node) support sourcefile and sourceline meta options, for example:

    ```cpp sourcefile="./solution.cpp" sourceline="2-8"
    ```

    In the above code, sourcefile specifies the source file location, then @yozora/gatsby-transformer will read the solution.cpp under that directory where the current markdown file is located. If this file (solution.cpp) exists, it will read the contents of the file. sourceline specifies which lines will be intercepted (in the above example, intercept lines 2-8 and 10), these lines will be concat and used as the value of the Code node.

FAQ

Related

2.2.0

12 months ago

2.1.2

1 year ago

2.1.1

1 year ago

2.1.3

1 year ago

2.0.0-alpha.4

2 years ago

2.0.0-alpha.5

2 years ago

2.1.0

1 year ago

2.1.0-alpha.7

1 year ago

2.1.0-alpha.6

1 year ago

2.1.0-alpha.5

1 year ago

2.1.0-alpha.4

1 year ago

2.1.0-alpha.3

1 year ago

2.1.0-alpha.2

1 year ago

2.1.0-alpha.1

1 year ago

2.1.0-alpha.0

1 year ago

2.0.0-alpha.3

2 years ago

2.0.0-alpha.0

2 years ago

2.0.0-alpha.1

2 years ago

2.0.0-alpha.2

2 years ago

1.0.0-alpha.20

3 years ago

1.0.0-alpha.19

3 years ago

1.0.0-alpha.18

3 years ago

1.0.0-alpha.17

3 years ago

1.0.0-alpha.16

3 years ago

1.0.0-alpha.15

3 years ago

1.0.0-alpha.14

3 years ago

1.0.0-alpha.13

3 years ago

1.0.0-alpha.12

3 years ago

1.0.0-alpha.11

3 years ago

1.0.0-alpha.10

3 years ago

1.0.0-alpha.7

3 years ago

1.0.0-alpha.9

3 years ago

1.0.0-alpha.8

3 years ago

1.0.0-alpha.6

3 years ago

1.0.0-alpha.5

3 years ago

1.0.0-alpha.4

3 years ago

1.0.0-alpha.3

3 years ago

1.0.0-alpha.2

3 years ago

1.0.0-alpha.1

3 years ago

1.0.0-alpha.0

3 years ago