Giter VIP home page Giter VIP logo

mdast-comment-marker's Introduction

mdast-comment-marker

Build Coverage Downloads Size Sponsors Backers Chat

mdast utility to parse comment markers.

Contents

What is this?

This package is a utility that tries to parse a structured marker from a comment.

When should I use this?

Comments are a hidden part of markdown, so they can be used as processing instructions. For example, this utility is used in remark-lint to control whether lint rules are turned on or ignored, and by mdast-zone to replace sections between two markers.

Install

This package is ESM only. In Node.js (version 16+), install with npm:

npm install mdast-comment-marker

In Deno with esm.sh:

import {commentMarker} from 'https://esm.sh/mdast-comment-marker@3'

In browsers with esm.sh:

<script type="module">
  import {commentMarker} from 'https://esm.sh/mdast-comment-marker@3?bundle'
</script>

Use

import {commentMarker} from 'mdast-comment-marker'

console.log(commentMarker({type: 'html', value: '<!--foo-->'}));

console.log(commentMarker({
  type: 'html',
  value: '<!--foo bar baz=12.4 qux="test test" quux=\'false\'-->'
}));

console.log(commentMarker({type: 'html', value: '<!doctype html>'}));

// Also supports MDX expressions:
console.log(commentMarker({
  type: 'mdxFlowExpression',
  value: '/* lint disable heading-style */'
}));

Yields:

{
  name: 'foo',
  attributes: '',
  parameters: {},
  node: { type: 'html', value: '<!--foo-->' }
}
{
  name: 'foo',
  attributes: `bar baz=12.4 qux="test test" quux='false'`,
  parameters: { bar: true, baz: 12.4, qux: 'test test', quux: false },
  node: {
    type: 'html',
    value: `<!--foo bar baz=12.4 qux="test test" quux='false'-->`
  }
}
undefined
{
  name: 'lint',
  attributes: 'disable heading-style',
  parameters: { disable: true, 'heading-style': true },
  node: {
    type: 'mdxFlowExpression',
    value: '/* lint disable heading-style */'
  }
}

API

This package exports the identifier commentMarker. There is no default export.

commentMarker(value)

Parse a comment marker.

Parameters
  • value (unknown) — thing to parse, typically Node
Returns

Info (Marker) when applicable or undefined.

Marker

Comment marker (TypeScript type).

Properties
  • name (string) — name of marker
  • attributes (string) — value after name
  • parameters (MarkerParameters) — parsed attributes
  • node (Node) — reference to given node

MarkerParameters

Parameters (TypeScript type).

type
type MarkerParameters = Record<string, MarkerParameterValue>

MarkerParameterValue

Value (TypeScript type).

If it looks like a number (to JavaScript), it’s cast as number. The strings true and false are turned into their corresponding booleans. The empty string is also considered the true boolean.

type
type MarkerParameterValue = number | string | boolean

Types

This package is fully typed with TypeScript. This package exports the types Marker, MarkerParameters, and MarkerParameterValue

Compatibility

Projects maintained by the unified collective are compatible with maintained versions of Node.js.

When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, mdast-comment-marker@^3, compatible with Node.js 16.

Security

Use of mdast-comment-marker does not involve hast, user content, or change the tree, so there are no openings for cross-site scripting (XSS) attacks.

Related

  • mdast-zone — change or replace a section marked by comments

Contribute

See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer

mdast-comment-marker's People

Contributors

greenkeeperio-bot avatar tmelliottjr avatar wooorm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mdast-comment-marker's Issues

regression after update to `1.1.0`

I use remark-message-control for disable linting on some files and no-file-name-irregular-characters rule to validate filenames.

Before update no errors for remark-link for this file:

CODE_OF_CONDUCT.md

<!-- lint disable -->

My custom syntax where linting is disabled.

Now it is doesn't work and remark-lint throw error Do not use _ in a file name no-file-name-irregular-characters remark-lint

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.