Neverending Perpetual Motion

    @dimerapp/dfile

    1.1.5 • Public • Published
    Dimer App

    Dimer is an open source project and CMS to help you publish your documentation online.


    We believe every project/product is incomplete without documentation.
    We want to help you publish user facing documentation, without worrying about tools or code to write.


    Dimer Dfile

    Converts the markdown file to vFile

    travis-image npm-image

    This module will convert the markdown file by reading it from the disk, and also reports the errors via vfile interface.

    Installation

    npm i --save-dev @dimerapp/dfile
     
    # yarn 
    yarn add @dimerapp/dfile

    Usage

    const Dfile = require('@dimerapp/dfile')
     
    const file = new Dfile(join(__dirname, 'readme.md'))
    await file.parse()
     
    if (file.messages) {
      // has errors
    }
     
    // JSON AST
    file.contents

    Computing base name

    You can instruct dFile to compute the base name of the file from a given directory by providing the base path

    const Dfile = require('@dimerapp/dfile')
    const docsDir = join(__dirname, 'docs')
    const filePath = join(docsDir, 'getting-started/intro.md')
     
    const file = new Dfile(filePath, docsDir)
    console.log(file.baseName) // getting-started/intro.md

    Extend Markdown library

    The @dimerapp/markdown library exposes an option to add macros. This library also exposes the library as Markdown property.

    Dfile.Markdown.addMacro('button', callback)

    API

    The following properties/methods are available on the file instance.

    constructor(filePath, [basePath], [markdownOptions])

    new Dfile(filePath, basePath, {
      async onUrl () {
      },
      title: 'Custom title',
      skipToc: false
    })

    parse()

    Parse the file by reading it from the disk.

    const file = new Dfile(join(__dirname, 'readme.md'))
    await file.parse()

    fatalMessage(message, ruleId)

    Add a new fatal message with rule id

    file.fatalMessage('Missing title', 'missing-title')

    warningMessage(message, ruleId)

    Add a new warning with rule id

    file.warningMessage('Missing title', 'missing-title')

    contents

    File JSON AST

    file.contents

    messages

    File error messages. The messages fatal property are hard errors.

    file.messages

    fatalMessages

    Returns an array of fatal messages.

    file.fatalMessages

    warningMessages

    Returns an array of warnings.

    file.warningMessages

    filePath

    File absolute path

    file.filePath

    metaData

    File yaml front matter meta data

    file.metaData

    toJSON()

    Returns the JSON representation of the file

    file.toJSON()

    Change log

    The change log can be found in the CHANGELOG.md file.

    Contributing

    Everyone is welcome to contribute. Please take a moment to review the contributing guidelines.

    Authors & License

    thetutlage and contributors.

    MIT License, see the included MIT file.

    Keywords

    Install

    npm i @dimerapp/dfile

    DownloadsWeekly Downloads

    10

    Version

    1.1.5

    License

    MIT

    Unpacked Size

    15.8 kB

    Total Files

    5

    Last publish

    Collaborators

    • atinux
    • prasanjit
    • virk