Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mdast-comment-marker

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdast-comment-marker - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

90

index.js
'use strict'
/* Expose. */
module.exports = marker
/* HTML type. */
var T_HTML = 'html'
var whiteSpaceExpression = /\s+/g
/* Expression for eliminating extra spaces */
var SPACES = /\s+/g
var parametersExpression = /\s+([-a-z0-9_]+)(?:=(?:"((?:\\[\s\S]|[^"])+)"|'((?:\\[\s\S]|[^'])+)'|((?:\\[\s\S]|[^"'\s])+)))?/gi
/* Expression for parsing parameters. */
var PARAMETERS = new RegExp(
'\\s+' +
'(' +
'[-a-z0-9_]+' +
')' +
'(?:' +
'=' +
'(?:' +
'"' +
'(' +
'(?:' +
'\\\\[\\s\\S]' +
'|' +
'[^"]' +
')+' +
')' +
'"' +
'|' +
"'" +
'(' +
'(?:' +
'\\\\[\\s\\S]' +
'|' +
"[^']" +
')+' +
')' +
"'" +
'|' +
'(' +
'(?:' +
'\\\\[\\s\\S]' +
'|' +
'[^"\'\\s]' +
')+' +
')' +
')' +
')?',
'gi'
)
var commentExpression = /\s*([a-zA-Z0-9-]+)(\s+([\s\S]*))?\s*/
var MARKER = new RegExp(
'(' +
'\\s*' +
'<!--' +
'\\s*' +
'([a-zA-Z0-9-]+)' +
'(\\s+([\\s\\S]*?))?' +
'\\s*' +
'-->' +
'\\s*' +
')'
var markerExpression = new RegExp(
'(\\s*<!--' + commentExpression.source + '-->\\s*)'
)
/* Parse a comment marker */
// Parse a comment marker.
function marker(node) {
var type
var value

@@ -72,15 +22,23 @@ var match

if (!node || node.type !== T_HTML) {
if (!node) {
return null
}
type = node.type
if (type !== 'html' && type !== 'comment') {
return null
}
value = node.value
match = value.match(MARKER)
match = value.match(type === 'comment' ? commentExpression : markerExpression)
if (!match || match[1].length !== value.length) {
if (!match || match[0].length !== value.length) {
return null
}
params = parameters(match[3] || '')
match = match.slice(node.type === 'comment' ? 1 : 2)
params = parameters(match[1] || '')
if (!params) {

@@ -91,4 +49,4 @@ return null

return {
name: match[2],
attributes: match[4] || '',
name: match[0],
attributes: match[2] || '',
parameters: params,

@@ -99,8 +57,8 @@ node: node

/* Parse `value` into an object. */
// Parse `value` into an object.
function parameters(value) {
var attributes = {}
var rest = value.replace(PARAMETERS, replacer)
var rest = value.replace(parametersExpression, replacer)
return rest.replace(SPACES, '') ? null : attributes
return rest.replace(whiteSpaceExpression, '') ? null : attributes

@@ -107,0 +65,0 @@ /* eslint-disable max-params */

{
"name": "mdast-comment-marker",
"version": "1.0.3",
"version": "1.1.0",
"description": "Parse a comment marker in mdast",

@@ -14,5 +14,5 @@ "license": "MIT",

"bugs": "https://github.com/syntax-tree/mdast-comment-marker/issues",
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"Masayuki Izumi <masayuki@izumin.info> (http://izumin.info)"

@@ -26,9 +26,9 @@ ],

"browserify": "^16.0.0",
"nyc": "^12.0.0",
"nyc": "^13.0.0",
"prettier": "^1.14.2",
"remark-cli": "^5.0.0",
"remark-cli": "^6.0.0",
"remark-preset-wooorm": "^4.0.0",
"tape": "^4.0.0",
"tinyify": "^2.4.3",
"xo": "^0.22.0"
"xo": "^0.23.0"
},

@@ -35,0 +35,0 @@ "scripts": {

@@ -1,4 +0,4 @@

# mdast-comment-marker [![Build Status][build-badge]][build-status] [![Coverage Status][coverage-badge]][coverage-status] [![Chat][chat-badge]][chat]
# mdast-comment-marker [![Build][build-badge]][build] [![Coverage][coverage-badge]][coverage] [![Downloads][downloads-badge]][downloads] [![Chat][chat-badge]][chat]
Parse an [MDAST][] comment marker.
Parse [mdast][] comment markers.

@@ -32,2 +32,8 @@ ## Installation

}));
// Also supports MDX comment nodes.
console.log(marker({
type: 'comment',
value: 'bar'
}));
```

@@ -49,2 +55,6 @@

null
{ name: 'bar',
attributes: '',
parameters: {},
node: { type: 'comment', value: 'bar' } }
```

@@ -94,15 +104,19 @@

[build-status]: https://travis-ci.org/syntax-tree/mdast-comment-marker
[build]: https://travis-ci.org/syntax-tree/mdast-comment-marker
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-comment-marker.svg
[coverage-status]: https://codecov.io/github/syntax-tree/mdast-comment-marker
[coverage]: https://codecov.io/github/syntax-tree/mdast-comment-marker
[chat-badge]: https://img.shields.io/gitter/room/wooorm/remark.svg
[downloads-badge]: https://img.shields.io/npm/dm/mdast-comment-marker.svg
[chat]: https://gitter.im/wooorm/remark
[downloads]: https://www.npmjs.com/package/mdast-comment-marker
[chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
[chat]: https://spectrum.chat/unified/remark
[license]: license
[author]: http://wooorm.com
[author]: https://wooorm.com

@@ -109,0 +123,0 @@ [npm]: https://docs.npmjs.com/cli/install

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