@marp-team/marpit
Advanced tools
Comparing version 0.1.3 to 0.2.0
@@ -5,2 +5,12 @@ # Change Log | ||
## v0.2.0 - 2018-10-10 | ||
### Added | ||
- Collect HTML comments per page to be usable as presenter note ([#82](https://github.com/marp-team/marpit/issues/82), [#83](https://github.com/marp-team/marpit/pull/83)) | ||
### Changed | ||
- Update license author to marp-team ([#81](https://github.com/marp-team/marpit/pull/81)) | ||
## v0.1.3 - 2018-10-05 | ||
@@ -7,0 +17,0 @@ |
@@ -20,2 +20,3 @@ declare module '@marp-team/marpit' { | ||
css: string | ||
comments: string[][] | ||
} | ||
@@ -40,2 +41,3 @@ | ||
protected lastComments?: MarpitRenderResult['comments'] | ||
protected lastGlobalDirectives?: { [directive: string]: any } | ||
@@ -42,0 +44,0 @@ protected lastStyles?: string[] |
@@ -52,5 +52,10 @@ "use strict"; | ||
const isComment = token => token.type === 'marpit_comment' && token.meta.marpitParsedDirectives; // Parse global directives | ||
const isComment = token => token.type === 'marpit_comment' && token.meta.marpitParsedDirectives; | ||
const markAsParsed = token => { | ||
token.meta = token.meta || {}; | ||
token.meta.marpitCommentParsed = 'directive'; | ||
}; // Parse global directives | ||
md.core.ruler.after('inline', 'marpit_directives_global_parse', state => { | ||
@@ -61,6 +66,14 @@ if (state.inlineMode) return; | ||
const applyDirectives = obj => { | ||
let recognized = false; | ||
for (const key of Object.keys(obj)) { | ||
const globalKey = key.startsWith('$') ? key.slice(1) : key; | ||
if (_directives.globals[globalKey]) globalDirectives = _objectSpread({}, globalDirectives, _directives.globals[globalKey](obj[key], marpit)); | ||
if (_directives.globals[globalKey]) { | ||
recognized = true; | ||
globalDirectives = _objectSpread({}, globalDirectives, _directives.globals[globalKey](obj[key], marpit)); | ||
} | ||
} | ||
return recognized; | ||
}; | ||
@@ -71,7 +84,7 @@ | ||
for (const token of state.tokens) { | ||
if (isComment(token)) { | ||
applyDirectives(token.meta.marpitParsedDirectives); | ||
if (isComment(token) && applyDirectives(token.meta.marpitParsedDirectives)) { | ||
markAsParsed(token); | ||
} else if (token.type === 'inline') { | ||
for (const t of token.children) { | ||
if (isComment(t)) applyDirectives(t.meta.marpitParsedDirectives); | ||
if (isComment(t) && applyDirectives(t.meta.marpitParsedDirectives)) markAsParsed(t); | ||
} | ||
@@ -94,11 +107,23 @@ } | ||
const applyDirectives = obj => { | ||
let recognized = false; | ||
for (const key of Object.keys(obj)) { | ||
if (_directives.locals[key]) cursor.local = _objectSpread({}, cursor.local, _directives.locals[key](obj[key], marpit)); // Spot directives | ||
if (_directives.locals[key]) { | ||
recognized = true; | ||
cursor.local = _objectSpread({}, cursor.local, _directives.locals[key](obj[key], marpit)); | ||
} // Spot directives | ||
// (Apply local directive to only current slide by prefix "_") | ||
if (key.startsWith('_')) { | ||
const spotKey = key.slice(1); | ||
if (_directives.locals[spotKey]) cursor.spot = _objectSpread({}, cursor.spot, _directives.locals[spotKey](obj[key], marpit)); | ||
if (_directives.locals[spotKey]) { | ||
recognized = true; | ||
cursor.spot = _objectSpread({}, cursor.spot, _directives.locals[spotKey](obj[key], marpit)); | ||
} | ||
} | ||
} | ||
return recognized; | ||
}; | ||
@@ -118,7 +143,7 @@ | ||
cursor.spot = {}; | ||
} else if (isComment(token)) { | ||
applyDirectives(token.meta.marpitParsedDirectives); | ||
} else if (isComment(token) && applyDirectives(token.meta.marpitParsedDirectives)) { | ||
markAsParsed(token); | ||
} else if (token.type === 'inline') { | ||
for (const t of token.children) { | ||
if (isComment(t)) applyDirectives(t.meta.marpitParsedDirectives); | ||
if (isComment(t) && applyDirectives(t.meta.marpitParsedDirectives)) markAsParsed(t); | ||
} | ||
@@ -125,0 +150,0 @@ } |
@@ -20,2 +20,4 @@ "use strict"; | ||
var _collect_comment = _interopRequireDefault(require("./markdown/collect_comment")); | ||
var _comment = _interopRequireDefault(require("./markdown/comment")); | ||
@@ -161,3 +163,3 @@ | ||
filters | ||
}).use(_sweep.default).use(_inline_svg.default, this).use(_assign.default, this); | ||
}).use(_sweep.default).use(_inline_svg.default, this).use(_assign.default, this).use(_collect_comment.default, this); | ||
if (backgroundSyntax) md.use(_background_image.default); | ||
@@ -169,2 +171,4 @@ } | ||
* @property {string} css Rendered CSS. | ||
* @property {string[][]} comments Parsed HTML comments per slide pages, | ||
* excepted YAML for directives. It would be useful for presenter notes. | ||
*/ | ||
@@ -183,3 +187,4 @@ | ||
html: this.renderMarkdown(markdown), | ||
css: this.renderStyle(this.lastGlobalDirectives.theme) | ||
css: this.renderStyle(this.lastGlobalDirectives.theme), | ||
comments: this.lastComments | ||
}; | ||
@@ -186,0 +191,0 @@ } |
{ | ||
"name": "@marp-team/marpit", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"description": "The skinny framework for creating slide deck from Markdown", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
113178
43
2546