New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

serve-markdown-it

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serve-markdown-it

Configurable static file server with markdown-it for parsing Markdown.

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

serve-markdown-it

TODO

Usage

serve-markdown-it

Description TODO.

Configurable static file server with markdown-it for parsing Markdown.

License: MIT
Example (sermit help)

sermit [path] [options]

Serve local files

Commands:
  sermit print-config            Log the merged configuration to the console
  sermit gen-config              Generate a new configuration file
  sermit render                  Render local files to static HTML
  sermit serve [path] [options]  Serve local files                     [default]

Options:
  --log-level, -l  Log level, increase to debug
         [string] [choices: 'error', 'info', 'warn', 'debug'] [default: 'error']
  --path, -p       Root directory
    [string] [required] [default: '/home/user/code/personal/serve-markdown-it']
  --help           Show help                                           [boolean]
  --version        Show version number                                 [boolean]
  --port           Port number to spawn HTTP server on
                                             [number] [required] [default: 8960]

Examples:
  sermit gen-config > .sermitrc.json  Generate basic configuration

Example (sermit)

[cli] › ★  star      read config from /.sermitrc.json
[cli] › ★  star      using template default
[cli] › ★  star      using md plugin markdown-it-smartarrows
[cli] › ★  star      using md plugin markdown-it-anchor
[cli] › ★  star      using md plugin markdown-it-highlightjs
[cli] › ★  star      serving content from /home/user/code/personal/serve-markdown-it
[cli] › ★  star      listening at http://localhost:8960

Example (sermit gen-config > .sermitrc.json)

{
  minify: true,
  excludeGitIgnore: true,
  template: {
    name: 'serve-markdown-it-template-default',
    config: {
      maxWidth: '960px',
      sections: {
        contentHeader: true,
        settings: true,
        debug: true,
        content: true,
        order: [
          'settings',
          'content',
          'debug'
        ]
      },
      explorer: {
        icons: true,
        columns: [
          'name',
          'user',
          'group',
          'mode',
          'type',
          'size'
        ],
        dataTable: {
          searchable: true,
          sortable: true,
          perPage: 25,
          perPageSelect: [
            10,
            25,
            50,
            100
          ],
          fixedHeight: false,
          layout: {
            top: '{select}{search}',
            bottom: '{pager}'
          }
        }
      },
      headerBar: false,
      settingsBar: false,
      dataTable: false
    }
  },
  markdownIt: {
    typographer: true,
    linkify: true,
    html: true,
    plugins: [
      {
        name: 'markdown-it-smartarrows',
        init: 'after',
        config: {
          auto: true,
          code: true
        }
      },
      {
        name: 'markdown-it-anchor',
        config: {
          permalink: true,
          permalinkBefore: true,
          permalinkSymbol: '§'
        },
        init: 'after'
      },
      {
        name: 'markdown-it-highlightjs',
        config: {
          auto: true,
          code: true
        },
        init: 'after'
      }
    ]
  }
}

API Docs

Modules

serve-markdown-it

Description TODO.

Configurable static file server with markdown-it for parsing Markdown.

Constants

DefaultMDPlugins : object

Default markdown-it plugin configuration.

DefaultConfig : object

Default configuration data; any loaded user configuration is applied on top of the default values, using cosmiconfig.

Functions

getConfig(params)Promise

Resolve the runtime configuration, loading the first user config file found. Searches directories up the path for any of the following files:

  • .sermitrc
  • .sermitrc.js
  • .sermitrc.json
  • .sermitrc.yaml
  • .sermitrc.yml

Any discovered user config file is merged with the default DefaultConfig object.

createServer(params)Promise

Starts an HTTP server on the configured port, and serves static files out of the specified basePath. If the basePath is a file, only that file will be rendered, excluding any resolved assets.

Files provided by the configured template are rendered from disk. Any URLs ending in /raw have the suffix removed and cause any matching file in basePath to be rendered like an asset. This allows file contents to be rendered with a link to the file itself.

If a URL is not an asset or raw file, it is checked against the matchMarkdownFileNames regex on the provided Config object. Files that match are passed through markdown-it.

Any remaining URLs are assumed to map to the basePath; if they are files, they are rendered as source within markdown code fences. Directories trigger the file explorer if allowed by the configuration.

getLogger(scope)Signale

Creates a new scoped signale logger instance.

getRelativePath(absPath, config)string

Converts the provided absolute path to a path relative to the configured content root, with a / prefix for linking in rendered HTML.

Typedefs

PluginConfig : object

Plugin configuration data.

PluginDefinition : string | PluginConfig

Plugin definition, either a raw module name or config object.

Config : object

Configuration data.

serve-markdown-it

Description TODO.

Configurable static file server with markdown-it for parsing Markdown.

License: MIT
Example (sermit help)

sermit [path] [options]

Serve local files

Commands:
  sermit print-config            Log the merged configuration to the console
  sermit gen-config              Generate a new configuration file
  sermit render                  Render local files to static HTML
  sermit serve [path] [options]  Serve local files                     [default]

Options:
  --log-level, -l  Log level, increase to debug
         [string] [choices: 'error', 'info', 'warn', 'debug'] [default: 'error']
  --path, -p       Root directory
    [string] [required] [default: '/home/user/code/personal/serve-markdown-it']
  --help           Show help                                           [boolean]
  --version        Show version number                                 [boolean]
  --port           Port number to spawn HTTP server on
                                             [number] [required] [default: 8960]

Examples:
  sermit gen-config > .sermitrc.json  Generate basic configuration

Example (sermit)

[cli] › ★  star      read config from /.sermitrc.json
[cli] › ★  star      using template default
[cli] › ★  star      using md plugin markdown-it-smartarrows
[cli] › ★  star      using md plugin markdown-it-anchor
[cli] › ★  star      using md plugin markdown-it-highlightjs
[cli] › ★  star      serving content from /home/user/code/personal/serve-markdown-it
[cli] › ★  star      listening at http://localhost:8960

Example (sermit gen-config > .sermitrc.json)

{
  minify: true,
  excludeGitIgnore: true,
  template: {
    name: 'serve-markdown-it-template-default',
    config: {
      maxWidth: '960px',
      sections: {
        contentHeader: true,
        settings: true,
        debug: true,
        content: true,
        order: [
          'settings',
          'content',
          'debug'
        ]
      },
      explorer: {
        icons: true,
        columns: [
          'name',
          'user',
          'group',
          'mode',
          'type',
          'size'
        ],
        dataTable: {
          searchable: true,
          sortable: true,
          perPage: 25,
          perPageSelect: [
            10,
            25,
            50,
            100
          ],
          fixedHeight: false,
          layout: {
            top: '{select}{search}',
            bottom: '{pager}'
          }
        }
      },
      headerBar: false,
      settingsBar: false,
      dataTable: false
    }
  },
  markdownIt: {
    typographer: true,
    linkify: true,
    html: true,
    plugins: [
      {
        name: 'markdown-it-smartarrows',
        init: 'after',
        config: {
          auto: true,
          code: true
        }
      },
      {
        name: 'markdown-it-anchor',
        config: {
          permalink: true,
          permalinkBefore: true,
          permalinkSymbol: '§'
        },
        init: 'after'
      },
      {
        name: 'markdown-it-highlightjs',
        config: {
          auto: true,
          code: true
        },
        init: 'after'
      }
    ]
  }
}

DefaultMDPlugins : object

Default markdown-it plugin configuration.

Kind: global constant
Read only: true
Properties

NameTypeDefaultDescription
0objectmarkdown-it-highlightjs plugin, used to generate highlighted code blocks with highlightjs.
['0.name']string"'markdown-it-highlightjs'"module name.
['0.init']string"'after'"module init method.
'0.config'objectmodule config.
['0.config.auto']booleantrueenables automatic language detection
['0.config.code']booleantruewraps inner markup in <code>/<code> tags.

DefaultConfig : object

Default configuration data; any loaded user configuration is applied on top of the default values, using cosmiconfig.

Kind: global constant
Read only: true
See: DefaultMDPlugins
Properties

NameTypeDefaultDescription
[minify]booleantrueenables HTML minification for the server and when rendering, uses html-minifier.
[excludeGitIgnore]booleantrueif true, any .gitignore file in the target path is loaded and used to filter directory listings.
[matchMarkdownFileNames]RegExp/.(mdwiki
templateobjecttemplate configuration.
[template.name]string"'serve-markdown-it-template-default'"default template; @see serve-markdown-it-template-default
template.configobjectconfiguration options passed to the template on initialisation
markdownItobjectmarkdown-it parser configuration options.
[markdownIt.typographer]booleantrueenables conversion of quotes beautification (smartquotes).
[markdownIt.linkify]booleantrueenables automatic conversion of text links to <a> tags.
[markdownIt.html]booleantrueallows HTML tags in markdown source.
[markdownIt.plugins]Array.<PluginDefinition>DefaultMDPLuginsarray of plugins for markdown-it to be loaded.

getConfig(params) ⇒ Promise

Resolve the runtime configuration, loading the first user config file found. Searches directories up the path for any of the following files:

  • .sermitrc
  • .sermitrc.js
  • .sermitrc.json
  • .sermitrc.yaml
  • .sermitrc.yml

Any discovered user config file is merged with the default DefaultConfig object.

Kind: global function
Returns: Promise - p - resolves with the final Config object.

ParamTypeDefaultDescription
paramsobjectparams.
[params.basePath]string"cwd"path to start searching in.
[params.configPath]stringpath to pre-loaded user config file, required if config is provided.
[params.config]objectuser config file if already found, search is skipped if provided.

Example

const config = await getConfig({ basePath: basePath })
const { state } = config
const { md, configPath, template } = state

if (configPath) {
  l.star('read config from %s', colors.bgGreen.black(configPath))
}

if (_isEmpty(command) || command === 'serve' || command === 'render') {
  l.star('using template %s', colors.cyan(template.name))

  md.pluginNames.forEach((name) => {
    l.star('using md plugin %s', colors.yellow(name))
  })
}

createServer(params) ⇒ Promise

Starts an HTTP server on the configured port, and serves static files out of the specified basePath. If the basePath is a file, only that file will be rendered, excluding any resolved assets.

Files provided by the configured template are rendered from disk. Any URLs ending in /raw have the suffix removed and cause any matching file in basePath to be rendered like an asset. This allows file contents to be rendered with a link to the file itself.

If a URL is not an asset or raw file, it is checked against the matchMarkdownFileNames regex on the provided Config object. Files that match are passed through markdown-it.

Any remaining URLs are assumed to map to the basePath; if they are files, they are rendered as source within markdown code fences. Directories trigger the file explorer if allowed by the configuration.

Kind: global function
Returns: Promise - p - resolves to koa instance.

ParamTypeDescription
paramsobjectparams.
params.basePathstringabsolute path to the root content directory.
params.configConfigconfig data.

Example

const SERVE_HANDLER = async (argv) => {
  const { l, port, config, path } = argv
  const server = await createServer({ basePath: path, config })

  server.listen(port)

  l.star('serving content from %s', colors.underline(path))
  l.star(
    '%s',
    colors.cyan.underline(
      `listening at ${colors.bold(`http://localhost:${port}`)}`
    )
  )
}

getLogger(scope) ⇒ Signale

Creates a new scoped signale logger instance.

Kind: global function
Returns: Signale - l

ParamTypeDescription
scopestringscope

Example

const l = getLogger('template:render-md')

getRelativePath(absPath, config) ⇒ string

Converts the provided absolute path to a path relative to the configured content root, with a / prefix for linking in rendered HTML.

Kind: global function
Returns: string - relPath

ParamTypeDescription
absPathstringabsolute path
configConfigconfig

Example

const { state } = config
const { template } = state
const { genRawSrcMarkdown } = template
const relPath = getRelativePath('/home/user/markdown-it/README.md', config)

await genRawSrcMarkdown({ relPath, ...genData })

PluginConfig : object

Plugin configuration data.

Kind: global typedef
Properties

NameTypeDefaultDescription
namestringmodule name.
[init]string"'after'"controls how the plugin is initialized, if 'after' the config is passed after it to markdown-it. If 'call' the module's default export is called with the config data, and the result passed to markdown-it.
[config]objectconfig data passed to the plugin on initialisation.

PluginDefinition : string | PluginConfig

Plugin definition, either a raw module name or config object.

Kind: global typedef

Config : object

Configuration data.

Kind: global typedef
Properties

NameTypeDescription
[minify]booleanenables HTML minification for the server and when rendering, uses html-minifier.
[excludeGitIgnore]booleanif true, any .gitignore file in the target path is loaded and used to filter directory listings.
[matchMarkdownFileNames]RegExpregular expression used to detect files with Markdown-formatted content.
[template]objecttemplate configuration.
[template.name]stringtemplate module name.
[template.config]objectconfiguration options passed to the template on initialisation.
[markdownIt]objectmarkdown-it parser configuration options. All keys besides plugins are passed to the markdown-it constructor.
[markdownIt.plugins]Array.<PluginDefinition>array of plugins for markdown-it to be loaded.

Keywords

FAQs

Package last updated on 28 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc