remark-captions
Advanced tools
Comparing version 0.0.11 to 0.0.12
@@ -102,56 +102,54 @@ 'use strict'; | ||
return function (node, index, parent) { | ||
if (index + 1 < parent.children.length && parent.children[index + 1].type === 'paragraph') { | ||
var legendNode = parent.children[index + 1]; | ||
var firstChild = legendNode.children[0]; | ||
if (index > parent.children.length || parent.children[index + 1].type !== 'paragraph') return; | ||
var legendNode = parent.children[index + 1]; | ||
var firstChild = legendNode.children[0]; | ||
if (firstChild.type !== 'text' || !firstChild.value.startsWith(blocks[node.type])) return; | ||
if (firstChild.value.startsWith(blocks[node.type])) { | ||
var legendNodes = []; | ||
var followingNodes = []; | ||
var firstTextLine = firstChild.value.replace(blocks[node.type], '').split('\n')[0]; | ||
if (firstChild.value.includes('\n')) { | ||
followingNodes.push({ type: 'text', | ||
value: firstChild.value.replace(blocks[node.type], '').split('\n')[1] }); | ||
} | ||
legendNodes.push({ | ||
type: 'text', | ||
value: firstTextLine.trimLeft() // remove the " " after the {prefix}: | ||
}); | ||
var legendNodes = []; | ||
var followingNodes = []; | ||
var firstTextLine = firstChild.value.replace(blocks[node.type], '').split('\n')[0]; | ||
if (firstChild.value.includes('\n')) { | ||
followingNodes.push({ type: 'text', | ||
value: firstChild.value.replace(blocks[node.type], '').split('\n')[1] }); | ||
} | ||
legendNodes.push({ | ||
type: 'text', | ||
value: firstTextLine.trimLeft() // remove the " " after the {prefix}: | ||
}); | ||
legendNode.children.forEach(function (node, index) { | ||
if (index === 0) return; | ||
if (node.type === 'text') { | ||
var keepInLegend = node.value.split('\n')[0]; | ||
if (node.value.includes('\n')) { | ||
node.value = node.value.split('\n')[1]; | ||
followingNodes.push(node); | ||
} | ||
legendNodes.push({ type: 'text', value: keepInLegend }); | ||
} else { | ||
legendNodes.push(clone(node)); | ||
} | ||
}); | ||
var figcaption = { | ||
type: 'figcaption', | ||
children: legendNodes, | ||
data: { | ||
hName: 'figcaption' | ||
} | ||
}; | ||
var figure = { | ||
type: 'figure', | ||
children: [clone(node), figcaption], | ||
data: { | ||
hName: 'figure' | ||
} | ||
}; | ||
node.type = figure.type; | ||
node.children = figure.children; | ||
node.data = figure.data; | ||
if (followingNodes.length) { | ||
parent.children.splice(index + 1, 1, { type: 'paragraph', children: followingNodes }); | ||
} else { | ||
parent.children.splice(index + 1, 1); | ||
legendNode.children.forEach(function (node, index) { | ||
if (index === 0) return; | ||
if (node.type === 'text') { | ||
var keepInLegend = node.value.split('\n')[0]; | ||
if (node.value.includes('\n')) { | ||
node.value = node.value.split('\n')[1]; | ||
followingNodes.push(node); | ||
} | ||
legendNodes.push({ type: 'text', value: keepInLegend }); | ||
} else { | ||
legendNodes.push(clone(node)); | ||
} | ||
}); | ||
var figcaption = { | ||
type: 'figcaption', | ||
children: legendNodes, | ||
data: { | ||
hName: 'figcaption' | ||
} | ||
}; | ||
var figure = { | ||
type: 'figure', | ||
children: [clone(node), figcaption], | ||
data: { | ||
hName: 'figure' | ||
} | ||
}; | ||
node.type = figure.type; | ||
node.children = figure.children; | ||
node.data = figure.data; | ||
if (followingNodes.length) { | ||
parent.children.splice(index + 1, 1, { type: 'paragraph', children: followingNodes }); | ||
} else { | ||
parent.children.splice(index + 1, 1); | ||
} | ||
@@ -158,0 +156,0 @@ }; |
{ | ||
"name": "remark-captions", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "url": "https://github.com/zestedesavoir/zmarkdown/tree/master/packages/remark-captions", |
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
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
8798
141