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

@marp-team/marpit

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@marp-team/marpit - npm Package Compare versions

Comparing version 0.0.10 to 0.0.11

lib/markdown/directives/yaml.js

8

CHANGELOG.md

@@ -5,2 +5,10 @@ # Change Log

## v0.0.11 - 2018-08-12
- Bugfix: Pass `class` attribute to pseudo section on advanced background ([#48](https://github.com/marp-team/marpit/pull/48))
- Lazy yaml support by `lazyYAML` option ([#49](https://github.com/marp-team/marpit/pull/49))
- Migrate coverage report service from [Coveralls](https://coveralls.io/github/marp-team/marpit?branch=master) to [Codecov](https://codecov.io/gh/marp-team/marpit) ([#50](https://github.com/marp-team/marpit/pull/50))
- Support `class` directive defined by array ([#51](https://github.com/marp-team/marpit/pull/51))
- Parse inline comment ([#52](https://github.com/marp-team/marpit/pull/52))
## v0.0.10 - 2018-08-05

@@ -7,0 +15,0 @@

1

index.d.ts

@@ -8,2 +8,3 @@ declare module '@marp-team/marpit' {

inlineStyle?: boolean
lazyYAML?: boolean
markdown?: string | object | [string, object]

@@ -10,0 +11,0 @@ printable?: boolean

@@ -167,2 +167,3 @@ 'use strict';

tag: 'section',
class: open.attrGet('class'),
style: style.toString(),

@@ -169,0 +170,0 @@ 'data-marpit-advanced-background': 'pseudo',

46

lib/markdown/comment.js

@@ -7,5 +7,5 @@ 'use strict';

var _parse_yaml = require('../helpers/parse_yaml');
var _yaml = require('./directives/yaml');
var _parse_yaml2 = _interopRequireDefault(_parse_yaml);
var _yaml2 = _interopRequireDefault(_yaml);

@@ -27,8 +27,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

* @param {MarkdownIt} md markdown-it instance.
* @param {Object} [opts]
* @param {boolean} [opts.lazyYAML=false] Allow lazy YAML for directives.
*/
function comment(md) {
/**
* Based on markdown-it html_block rule
* https://github.com/markdown-it/markdown-it/blob/master/lib/rules_block/html_block.js
*/
function comment(md, opts = {}) {
const parse = (token, content) => {
const parsed = (0, _yaml2.default)(content, !!opts.lazyYAML);
token.meta = Object.assign({}, token.meta || {}, {
marpitParsedDirectives: parsed === false ? {} : parsed
});
};
md.block.ruler.before('html_block', 'marpit_comment', (state, startLine, endLine, silent) => {

@@ -71,7 +77,27 @@ // Fast fail

token.content = matchedContent ? matchedContent[1].trim() : '';
parse(token, token.content);
// Parse YAML
const yaml = (0, _parse_yaml2.default)(token.content);
token.meta = { marpitParsedYAML: yaml === false ? {} : yaml };
return true;
});
md.inline.ruler.before('html_inline', 'marpit_inline_comment', (state, silent) => {
const { posMax, src } = state;
// Quick fail by checking `<` and `!`
if (state.pos + 2 >= posMax || src.charCodeAt(state.pos) !== 0x3c || src.charCodeAt(state.pos + 1) !== 0x21) return false;
const match = src.slice(state.pos).match(commentMatcher);
if (!match) return false;
if (!silent) {
const token = state.push('marpit_comment', '', 0);
token.hidden = true;
token.markup = src.slice(state.pos, state.pos + match[0].length);
token.content = match[1].trim();
parse(token, token.content);
}
state.pos += match[0].length;
return true;

@@ -78,0 +104,0 @@ });

@@ -100,3 +100,3 @@ 'use strict';

class(value) {
return { class: value };
return { class: Array.isArray(value) ? value.join(' ') : value };
},

@@ -117,2 +117,4 @@ color(value) {

exports.default = { globals, locals };
const directiveNames = [...Object.keys(globals), ...Object.keys(locals)];
exports.default = directiveNames;

@@ -11,5 +11,5 @@ 'use strict';

var _parse_yaml = require('../../helpers/parse_yaml');
var _yaml = require('./yaml');
var _parse_yaml2 = _interopRequireDefault(_parse_yaml);
var _yaml2 = _interopRequireDefault(_yaml);

@@ -33,2 +33,3 @@ var _directives = require('./directives');

* first page.
* @param {boolean} [opts.lazyYAML=false] Allow lazy YAML for directives.
*/

@@ -48,17 +49,19 @@ function parse(md, marpit, opts = {}) {

const yaml = (0, _parse_yaml2.default)(fm);
if (yaml !== false) frontMatterObject.yaml = yaml;
const parsed = (0, _yaml2.default)(fm, !!opts.lazyYAML);
if (parsed !== false) frontMatterObject.yaml = parsed;
});
}
const isComment = token => token.type === 'marpit_comment' && token.meta.marpitParsedDirectives;
// Parse global directives
md.core.ruler.after('block', 'marpit_directives_global_parse', state => {
md.core.ruler.after('inline', 'marpit_directives_global_parse', state => {
if (state.inlineMode) return;
let globalDirectives = {};
const applyDirectives = yaml => {
Object.keys(yaml).forEach(key => {
const applyDirectives = obj => {
Object.keys(obj).forEach(key => {
const globalKey = key.startsWith('$') ? key.slice(1) : key;
if (_directives.globals[globalKey]) globalDirectives = Object.assign({}, globalDirectives, _directives.globals[globalKey](yaml[key], marpit));
if (_directives.globals[globalKey]) globalDirectives = Object.assign({}, globalDirectives, _directives.globals[globalKey](obj[key], marpit));
});

@@ -70,3 +73,7 @@ };

state.tokens.forEach(token => {
if (token.type === 'marpit_comment' && token.meta.marpitParsedYAML) applyDirectives(token.meta.marpitParsedYAML);
if (isComment(token)) {
applyDirectives(token.meta.marpitParsedDirectives);
} else if (token.type === 'inline') {
token.children.filter(isComment).forEach(t => applyDirectives(t.meta.marpitParsedDirectives));
}
});

@@ -84,5 +91,5 @@

const applyDirectives = yaml => {
Object.keys(yaml).forEach(key => {
if (_directives.locals[key]) cursor.local = Object.assign({}, cursor.local, _directives.locals[key](yaml[key], marpit));
const applyDirectives = obj => {
Object.keys(obj).forEach(key => {
if (_directives.locals[key]) cursor.local = Object.assign({}, cursor.local, _directives.locals[key](obj[key], marpit));

@@ -94,3 +101,3 @@ // Spot directives

if (_directives.locals[spotKey]) cursor.spot = Object.assign({}, cursor.spot, _directives.locals[spotKey](yaml[key], marpit));
if (_directives.locals[spotKey]) cursor.spot = Object.assign({}, cursor.spot, _directives.locals[spotKey](obj[key], marpit));
}

@@ -114,4 +121,6 @@ });

cursor.spot = {};
} else if (token.type === 'marpit_comment' && token.meta.marpitParsedYAML) {
applyDirectives(token.meta.marpitParsedYAML);
} else if (isComment(token)) {
applyDirectives(token.meta.marpitParsedDirectives);
} else if (token.type === 'inline') {
token.children.filter(isComment).forEach(t => applyDirectives(t.meta.marpitParsedDirectives));
}

@@ -118,0 +127,0 @@ });

@@ -89,2 +89,3 @@ 'use strict';

inlineStyle: true,
lazyYAML: false,
markdown: 'commonmark',

@@ -119,2 +120,3 @@ printable: true,

* style regardless markdown-it's `html` option.
* @param {boolean} [opts.lazyYAML=false] Allow lazy YAML for directives.
* @param {string|Object|Array} [opts.markdown='commonmark'] markdown-it

@@ -175,5 +177,7 @@ * initialize option(s).

applyMarkdownItPlugins(md = this.markdown) {
md.use(_comment2.default).use(_parse4.default, this).use(_slide2.default).use(_parse2.default, this).use(_apply2.default).use(_header_and_footer2.default).use(_heading_divider2.default, this).use(_slide_container2.default, this.slideContainers).use(_container2.default, this.containers).use(_parse_image2.default, { filters: this.options.filters }).use(_unicode_emoji2.default).use(_sweep2.default).use(_inline_svg2.default, this).use(_assign2.default, this);
const { backgroundSyntax, filters, lazyYAML } = this.options;
if (this.options.backgroundSyntax) md.use(_background_image2.default);
md.use(_comment2.default, { lazyYAML }).use(_parse4.default, this).use(_slide2.default).use(_parse2.default, this, { lazyYAML }).use(_apply2.default).use(_header_and_footer2.default).use(_heading_divider2.default, this).use(_slide_container2.default, this.slideContainers).use(_container2.default, this.containers).use(_parse_image2.default, { filters }).use(_unicode_emoji2.default).use(_sweep2.default).use(_inline_svg2.default, this).use(_assign2.default, this);
if (backgroundSyntax) md.use(_background_image2.default);
}

@@ -180,0 +184,0 @@

{
"name": "@marp-team/marpit",
"version": "0.0.10",
"version": "0.0.11",
"description": "The skinny framework for creating slide deck from Markdown",

@@ -37,3 +37,2 @@ "license": "MIT",

"clean": "rimraf lib",
"coveralls": "cat coverage/lcov.info | coveralls",
"docs": "jsdoc src -c .jsdoc.json",

@@ -59,3 +58,3 @@ "format": "prettier **/*.{json,md,ts,yaml,yml}",

"cheerio": "^1.0.0-rc.2",
"coveralls": "^3.0.2",
"codecov": "^3.0.4",
"cross-env": "^5.2.0",

@@ -62,0 +61,0 @@ "dedent": "^0.7.0",

@@ -11,3 +11,3 @@ <div align="center">

[![CircleCI](https://img.shields.io/circleci/project/github/marp-team/marpit/master.svg?style=flat-square)](https://circleci.com/gh/marp-team/marpit/)
[![Coveralls](https://img.shields.io/coveralls/marp-team/marpit/master.svg?style=flat-square)](https://coveralls.io/github/marp-team/marpit?branch=master)
[![Codecov](https://img.shields.io/codecov/c/github/marp-team/marpit/master.svg?style=flat-square)](https://codecov.io/gh/marp-team/marpit)
[![npm](https://img.shields.io/npm/v/@marp-team/marpit.svg?style=flat-square)](https://www.npmjs.com/package/@marp-team/marpit)

@@ -42,3 +42,3 @@ [![LICENSE](https://img.shields.io/github/license/marp-team/marpit.svg?style=flat-square)](./LICENSE)

- Removed directives about slide size. [Use `width` / `height` declaration of theme CSS.](#slide-size)
- Parse directives by YAML parser. ([js-yaml](https://github.com/nodeca/js-yaml) + [`FAILSAFE_SCHEMA`](http://www.yaml.org/spec/1.2/spec.html#id2802346))
- Parse directives by YAML parser. ([js-yaml](https://github.com/nodeca/js-yaml) + [`FAILSAFE_SCHEMA`](http://www.yaml.org/spec/1.2/spec.html#id2802346), but we still support lazy YAML parser by `lazyYAML` option)
- Support [Jekyll style front-matter](https://jekyllrb.com/docs/frontmatter/).

@@ -123,2 +123,4 @@ - _[Global directives](https://github.com/yhatt/marp/blob/master/example.md#global-directives)_ is no longer requires `$` prefix. (but it still supports because of compatibility and clarity)

> :warning: Marpit uses YAML for parsing directives, so **you should wrap with (double-)quotes** when the value includes invalid chars in YAML.
>
> You can enable a lazy YAML parser by `lazyYAML` Marpit constructor option if you want to recognize string without quotes.

@@ -125,0 +127,0 @@ > :information_source: Due to the parsing order of Markdown, you cannot use [slide background images](#slide-background) in `header` and `footer` directives.

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