Skip to content

Commit

Permalink
Merge pull request #184 from elifesciences/figure-fixes
Browse files Browse the repository at this point in the history
Apply all rules for showing figures within math environments.
  • Loading branch information
Michael Aufreiter authored Jul 17, 2016
2 parents f04bbda + d21cfed commit c807f2c
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions extensions/math/math_converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ MathConverter.Prototype = function MathConverterPrototype() {
targetNode = state.doc.getNodeBySourceId(anno.target) || state.doc.get(anno.target);
if (targetNode) {
anno.target = targetNode.id;
targetNode.isReferenced = true;
} else {
console.log("Could not lookup targetNode for annotation", anno);
continue;
Expand All @@ -754,18 +755,12 @@ MathConverter.Prototype = function MathConverterPrototype() {
};

function _showFigure(state, node) {
// show figures without captions are only in-flow
if (!node.caption) {
// show all figures in the figures panel
state.doc.show('figures', node.id);
// show unreferenced and anchored figures in the main content
if (!node.isReferenced || node.position === 'anchor') {
state.doc.show('content', node.id);
}
// all others are shown in the figures panel
else {
state.doc.show('figures', node.id);
// in addition a figure can be shown in-flow using position='anchor'
if (node.position === 'anchor') {
state.doc.show('content', node.id);
}
}
}

function _showFormulaOrEnvironment(state, node, nested) {
Expand All @@ -791,15 +786,18 @@ MathConverter.Prototype = function MathConverterPrototype() {

function _showNestedContent(state, nodeIds) {
var referencedMath = state.referencedMath;
nodeIds.forEach(function(nodeId) {
for (var i = 0; i < nodeIds.length; i++) {
var nodeId = nodeIds[i]
var node = state.doc.get(nodeId);
var info = state.nodeInfo[nodeId];
switch (node.type) {
case 'figure':
// only show figures in the figures panel,
// which have a caption
if (node.caption) {
state.doc.show('figures', nodeId);
// show all figures in the figures panel
state.doc.show('figures', nodeId);
// hide referenced and unanchored figures from the environment
if (node.isReferenced && node.position !== 'anchor') {
nodeIds.splice(i, 1);
i--;
}
break;
case 'formula':
Expand All @@ -809,7 +807,7 @@ MathConverter.Prototype = function MathConverterPrototype() {
default:
// nothing
}
});
}
}

function _showProof(state, node) {
Expand All @@ -823,7 +821,7 @@ MathConverter.Prototype = function MathConverterPrototype() {
var referencedMath = state.referencedMath;
var node, child, info;
for (var i = 0; i < state.shownNodes.length; i++) {
node = state.shownNodes[i];
node = doc.get(state.shownNodes[i].id);
switch (node.type) {
case 'figure':
_showFigure(state, node);
Expand Down

0 comments on commit c807f2c

Please sign in to comment.