我正在使用asciidoctor来生成html。我有以下列表:
. one
. two
. three
image::mypic.png[]
. four
当转换为html时,它看起来像这样:
1. one
2. two
3. three
<my picture>
1. four
在html中,我想看看:
1. one
2. two
3. three
<my picture>
4. four
我不想在插入图像后手动重置计数器,因为我有数百种类似的情况。
答案 0 :(得分:4)
受asciidoctor文档(Complex List Content部分)的启发,您可以在图像块之前添加var expect = require('chai').expect;
var Node = function(data) {
this.data = data;
this.children = [];
};
var WordTree = function() {
var node = new Node({});
this.root = node;
};
WordTree.prototype.search = function(word, nodes) {
// code starts here
var currentLetter = word.charAt(0);
if (nodes === undefined) { // if top-level search...
if( !containsLetter(this.root.children, currentLetter) ) {
var newLetter = new Node(currentLetter);
this.root.children.push(newLetter);
this.search(word); // add the rest of the word
return [];
} else { // first letter exists, so let's begin search recursively
var nodeIndex = getNodeIndexWithLetter(this.root.children, currentLetter);
return this.search(word.slice(1), this.root.children[nodeIndex].children );
}
} else { // if 'nodes' is defined, we know recursion is going on
// if last letter in 'word', suggest the next possible words in the tree
if( word.length === 1 ){
var result = [];
if(containsLetter(nodes, currentLetter) ) {
var currLetterChildren = nodes[ getNodeIndexWithLetter(nodes, currentLetter) ].children;
result = currLetterChildren.map(function getChildrenData(childNode) {
return childNode.data;
});
// console.log(result); // <--- *****THIS IS ['o'] ****
return result; // <---- BUT IT RETURNS [].
} else {
nodes.push(new Node(currentLetter))
}
return result;
}
// if there are more letters to traverse...
if( !containsLetter(nodes, currentLetter) ) {
var newLetter = new Node(currentLetter);
nodes.push(newLetter);
this.search(word.slice(1), newLetter.children); // add the rest of the word
} else {
this.search(word.slice(1), nodes[ getNodeIndexWithLetter(nodes, currentLetter)].children);
}
}
return [];
// these are O(n). Something to fix later
function containsLetter(childArray, num){
var found = false;
childArray.forEach(function(child) {
if(child.data === num)
found = true;
})
return found;
}
// O(n). Fix later.
function getNodeIndexWithLetter(nodeArray, num) {
var index = -1;
nodeArray.forEach(function(element, i) {
if(element.data === num)
index = i;
})
return index;
}
};
var tree = new WordTree();
expect(tree.search('Levi')).to.deep.equal([]);
expect(tree.search('Level')).to.deep.equal([]);
expect(tree.search('Lego')).to.deep.equal([]);
expect(tree.search('Le')).to.deep.equal(['v', 'g']);
console.log(
tree.search('Leg')
);
// console.log(JSON.stringify(tree.root));
// expect(tree.search('Leg')).to.deep.equal(['o']); // <-- something is off about this test
而不是空行。
+