mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-05 15:32:55 +02:00
Handle misses in epubcfi
This commit is contained in:
parent
f01c2c9e8e
commit
7cad24b414
7 changed files with 747 additions and 187 deletions
|
@ -1,4 +1,5 @@
|
|||
var assert = require('assert');
|
||||
// var assert = require('chai').assert;
|
||||
var fs = require('fs');
|
||||
|
||||
describe('EpubCFI', function() {
|
||||
|
@ -225,11 +226,24 @@ describe('EpubCFI', function() {
|
|||
assert.equal( cfi.toString(), "epubcfi(/6/4[chap01ref]!/4/2/32/2[c001p0017]/1:43)" );
|
||||
|
||||
});
|
||||
// TODO: might need to have double ranges in front
|
||||
it('get a cfi from a range past a highlight', function() {
|
||||
var t1 = doc.getElementById('c001s0001').childNodes[1];
|
||||
var range = doc.createRange();
|
||||
var cfi;
|
||||
|
||||
range.setStart(t1, 25);
|
||||
|
||||
cfi = new EpubCFI(range, base);
|
||||
|
||||
assert.equal( cfi.toString(), "epubcfi(/6/4[chap01ref]!/4/2/4/2[c001s0001]/1:25)" );
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('#fromRange()', function() {
|
||||
describe('#toRange()', function() {
|
||||
var base = "/6/4[chap01ref]";
|
||||
var contents = fs.readFileSync(__dirname + '/fixtures/chapter1.xhtml', 'utf8');
|
||||
var doc = new DOMParser().parseFromString(contents, "application/xhtml+xml");
|
||||
|
@ -303,11 +317,35 @@ describe('EpubCFI', function() {
|
|||
// Check the range
|
||||
newRange = cfi.toRange(doc);
|
||||
|
||||
assert.ok(newRange.startContainer);
|
||||
|
||||
assert.equal( newRange.startContainer, t1);
|
||||
assert.equal( newRange.startOffset, 6);
|
||||
|
||||
});
|
||||
|
||||
it('get a cfi from a range inside a highlight range', function() {
|
||||
var t1 = doc.getElementById('highlight-2').childNodes[0];
|
||||
var t2 = doc.getElementById('c001s0001').childNodes[1];
|
||||
var ogRange = doc.createRange();
|
||||
var cfi;
|
||||
var newRange;
|
||||
|
||||
ogRange.setStart(t1, 5);
|
||||
ogRange.setEnd(t2, 25);
|
||||
|
||||
cfi = new EpubCFI(ogRange, base);
|
||||
|
||||
assert.equal( cfi.toString(), "epubcfi(/6/4[chap01ref]!/4/2/4/2[c001s0001],/1:5,/1:25)" );
|
||||
|
||||
// Check the range
|
||||
newRange = cfi.toRange(doc);
|
||||
|
||||
assert.strictEqual( newRange.startContainer, t1);
|
||||
assert.equal( newRange.startOffset, 5);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
2
test/fixtures/chapter1.xhtml
vendored
2
test/fixtures/chapter1.xhtml
vendored
|
@ -13,7 +13,7 @@ Moby-Dick</title>
|
|||
|
||||
|
||||
|
||||
<p><span class="audio" id="c001s0001">Call me Ishmael.</span> <span class="audio" id="c001s0002">Some years ago—never mind how long precisely—having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world.</span> <span class="audio" id="c001s0003">It is a way I have of driving off the spleen and regulating the circulation.</span> <span class="audio" id="c001s0004">Whenever I find myself growing grim about the mouth; whenever it is a damp, drizzly November in my soul; whenever I find myself involuntarily pausing before coffin warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos get such an upper hand of me, that it requires a strong moral principle to prevent me from deliberately stepping into the street, and methodically knocking people’s hats off—then, I account it high time to get to sea as soon as I can.</span> <span class="audio" id="c001s0005">This is my substitute for pistol and ball.</span> <span class="audio" id="c001s0006">With a philosophical flourish Cato throws himself upon his sword; I quietly take to the ship.</span> <span class="audio" id="c001s0007">There is nothing surprising in this.</span> <span class="audio" id="c001s0008">If they but knew it, almost all men in their degree, some time or other, cherish very nearly the same feelings towards the ocean with me.</span></p>
|
||||
<p><span class="audio" id="c001s0001"><span id="highlight-2" class='annotator-hl'>Call me Ishmael.</span> Some years ago—never mind how long precisely—having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world.</span> <span class="audio" id="c001s0003">It is a way I have of driving off the spleen and regulating the circulation.</span> <span class="audio" id="c001s0004">Whenever I find myself growing grim about the mouth; whenever it is a damp, drizzly November in my soul; whenever I find myself involuntarily pausing before coffin warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos get such an upper hand of me, that it requires a strong moral principle to prevent me from deliberately stepping into the street, and methodically knocking people’s hats off—then, I account it high time to get to sea as soon as I can.</span> <span class="audio" id="c001s0005">This is my substitute for pistol and ball.</span> <span class="audio" id="c001s0006">With a philosophical flourish Cato throws himself upon his sword; I quietly take to the ship.</span> <span class="audio" id="c001s0007">There is nothing surprising in this.</span> <span class="audio" id="c001s0008">If they but knew it, almost all men in their degree, some time or other, cherish very nearly the same feelings towards the ocean with me.</span></p>
|
||||
<p><span class="audio" id="c001p0002">There now is your insular city of the Manhattoes, belted round by wharves as Indian isles by coral reefs—commerce surrounds it with her surf. Right and left, the streets take you waterward. Its extreme downtown is the battery, where that noble mole is washed by waves, and cooled by breezes, which a few hours previous were out of sight of land. Look at the crowds of water-gazers there.</span></p>
|
||||
<p><span class="audio" id="c001p0003">Circumambulate the city of a dreamy Sabbath afternoon. Go from Corlears Hook to Coenties Slip, and from thence, by Whitehall, northward. What do you see?—Posted like silent sentinels all around the town, stand thousands upon thousands of mortal men fixed in ocean reveries. Some leaning against the spiles; some seated upon the pier-heads; some looking over the bulwarks of ships from China; some high aloft in the rigging, as if striving to get a still better seaward peep. But these are all landsmen; of week days pent up in lath and plaster—tied to counters, nailed to benches, clinched to desks. How then is this? Are the green fields gone? What do they here?</span>
|
||||
</p>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue