Comparing version 4.0.2 to 5.0.0
"use strict"; | ||
var detab = require('detab'); | ||
/* Expose. */ | ||
module.exports = code; | ||
var codeBlockParamsMapping = [null, 'hl_lines=', 'linenostart=']; | ||
var defaultMacro = function defaultMacro(content, lang) { | ||
if (!lang) lang = 'text'; | ||
var param = ''; | ||
var defaultMacro = function defaultMacro(content, lang, attrs) { | ||
// Default language is "text" | ||
if (!lang) lang = 'text'; // Create a list of attributes to be serialized | ||
if (lang.indexOf('hl_lines=') > -1) { | ||
var lines = lang.split('hl_lines=')[1].trim(); | ||
var localCodeBlockParams = Array(codeBlockParamsMapping.length).fill(''); // Check for attributes and enumerate them | ||
if (lines.startsWith('"') && lines.endsWith('"') || lines.startsWith("'") && lines.endsWith("'")) { | ||
lines = lines.slice(1, -1).trim(); | ||
if (attrs !== null) { | ||
for (var i = 0; i < codeBlockParamsMapping.length; i++) { | ||
var _param = codeBlockParamsMapping[i]; // Skip unwanted parameters | ||
if (_param === null) continue; | ||
var location = attrs.indexOf(_param); // Parse the attributes we know | ||
if (location > -1) { | ||
var begin = location + _param.length; | ||
var remaining = attrs.slice(begin); | ||
var length = remaining.indexOf(' '); | ||
var value = length > -1 ? attrs.slice(begin, begin + length) : remaining; // Remove string-delimiters | ||
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) { | ||
value = value.slice(1, -1).trim(); | ||
} | ||
localCodeBlockParams[i] = value; | ||
} | ||
} | ||
} // If we matched something, return optional arguments | ||
// Note that we do stop serialization on a chain of empty arguments | ||
param += "[][".concat(lines, "]"); | ||
} | ||
lang = lang.split(' ')[0]; | ||
var matched = localCodeBlockParams.reduce(function (a, v, i) { | ||
return v !== '' ? i : a; | ||
}, -1) + 1; | ||
var param = matched > 0 ? "[".concat(localCodeBlockParams.slice(0, matched).join(']['), "]") : ''; | ||
return "\\begin{CodeBlock}".concat(param, "{").concat(lang, "}\n").concat(content, "\n\\end{CodeBlock}\n\n"); | ||
}; | ||
/* Stringify a Blockquote `node`. */ | ||
/* Stringify a code `node`. */ | ||
module.exports = function code(ctx, node) { | ||
var value = node.value ? detab("".concat(node.value, "\n")) : ''; | ||
function code(ctx, node) { | ||
var macro = ctx.code || defaultMacro; | ||
return macro(value, node.lang); | ||
}; | ||
return "".concat(macro(node.value, node.lang, node.meta, node)); | ||
} | ||
code.macro = defaultMacro; |
{ | ||
"name": "rebber", | ||
"version": "4.0.2", | ||
"version": "5.0.0", | ||
"description": "Stringifies MDAST to LaTeX", | ||
@@ -34,10 +34,7 @@ "repository": "https://github.com/zestedesavoir/zmarkdown/tree/master/packages/rebber", | ||
"dependencies": { | ||
"collapse-white-space": "^1.0.5", | ||
"detab": "^2.0.2", | ||
"has": "^1.0.1", | ||
"mdast-util-definitions": "^1.2.3", | ||
"trim-lines": "^1.1.2", | ||
"xtend": "^4.0.1" | ||
"has": "^1.0.3", | ||
"mdast-util-definitions": "^2.0.0", | ||
"xtend": "^4.0.2" | ||
}, | ||
"gitHead": "86ca62fff4fbc11a45ce795ca8863f8e847eea08" | ||
"gitHead": "c2bf169996c4adfdf75a55290080947a2384c09f" | ||
} |
@@ -1,25 +0,59 @@ | ||
const detab = require('detab') | ||
/* Expose. */ | ||
module.exports = code | ||
const defaultMacro = (content, lang) => { | ||
const codeBlockParamsMapping = [ | ||
null, | ||
'hl_lines=', | ||
'linenostart=', | ||
] | ||
const defaultMacro = (content, lang, attrs) => { | ||
// Default language is "text" | ||
if (!lang) lang = 'text' | ||
let param = '' | ||
if (lang.indexOf('hl_lines=') > -1) { | ||
let lines = lang.split('hl_lines=')[1].trim() | ||
if ( | ||
(lines.startsWith('"') && lines.endsWith('"')) || | ||
(lines.startsWith("'") && lines.endsWith("'")) | ||
) { | ||
lines = lines.slice(1, -1).trim() | ||
// Create a list of attributes to be serialized | ||
const localCodeBlockParams = Array(codeBlockParamsMapping.length).fill('') | ||
// Check for attributes and enumerate them | ||
if (attrs !== null) { | ||
for (let i = 0; i < codeBlockParamsMapping.length; i++) { | ||
const param = codeBlockParamsMapping[i] | ||
// Skip unwanted parameters | ||
if (param === null) continue | ||
const location = attrs.indexOf(param) | ||
// Parse the attributes we know | ||
if (location > -1) { | ||
const begin = location + param.length | ||
const remaining = attrs.slice(begin) | ||
const length = remaining.indexOf(' ') | ||
let value = length > -1 ? attrs.slice(begin, begin + length) : remaining | ||
// Remove string-delimiters | ||
if ( | ||
(value.startsWith('"') && value.endsWith('"')) || | ||
(value.startsWith("'") && value.endsWith("'")) | ||
) { | ||
value = value.slice(1, -1).trim() | ||
} | ||
localCodeBlockParams[i] = value | ||
} | ||
} | ||
param += `[][${lines}]` | ||
} | ||
lang = lang.split(' ')[0] | ||
// If we matched something, return optional arguments | ||
// Note that we do stop serialization on a chain of empty arguments | ||
const matched = localCodeBlockParams.reduce((a, v, i) => v !== '' ? i : a, -1) + 1 | ||
const param = matched > 0 ? `[${localCodeBlockParams.slice(0, matched).join('][')}]` : '' | ||
return `\\begin{CodeBlock}${param}{${lang}}\n${content}\n\\end{CodeBlock}\n\n` | ||
} | ||
/* Stringify a Blockquote `node`. */ | ||
module.exports = function code (ctx, node) { | ||
const value = node.value ? detab(`${node.value}\n`) : '' | ||
/* Stringify a code `node`. */ | ||
function code (ctx, node) { | ||
const macro = ctx.code || defaultMacro | ||
return macro(value, node.lang) | ||
return `${macro(node.value, node.lang, node.meta, node)}` | ||
} | ||
code.macro = defaultMacro |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48759
3
1184
1
+ Added@types/unist@2.0.11(transitive)
+ Addedmdast-util-definitions@2.0.1(transitive)
+ Addedunist-util-is@4.1.0(transitive)
+ Addedunist-util-visit@2.0.3(transitive)
+ Addedunist-util-visit-parents@3.1.1(transitive)
- Removedcollapse-white-space@^1.0.5
- Removeddetab@^2.0.2
- Removedtrim-lines@^1.1.2
- Removedcollapse-white-space@1.0.6(transitive)
- Removeddetab@2.0.4(transitive)
- Removedmdast-util-definitions@1.2.5(transitive)
- Removedrepeat-string@1.6.1(transitive)
- Removedtrim-lines@1.1.3(transitive)
- Removedunist-util-is@3.0.0(transitive)
- Removedunist-util-visit@1.4.1(transitive)
- Removedunist-util-visit-parents@2.1.2(transitive)
Updatedhas@^1.0.3
Updatedxtend@^4.0.2