Created
July 30, 2012 19:43
-
-
Save aronwoost/3209510 to your computer and use it in GitHub Desktop.
Pseudo example code for saving text fragments in HTML (or epubs)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Looking for "and". | |
Markup is the following: | |
<body> | |
<div id="text">Pride and Prejudice</div> | |
</body> | |
*/ | |
var range = { | |
startContainer:$("text"), | |
startOffset:6, | |
endContainer:$("text"), | |
endOffset:9 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Looking for "Prejudice is a book". | |
Markup is the following: | |
<body> | |
<div id="headline">Pride and Prejudice</div> | |
<div id="text">is a book, that is very popular</div> | |
</body> | |
*/ | |
var range = { | |
startContainer:$("headline"), | |
startOffset:10, | |
endContainer:$("text"), | |
endOffset:9 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
range.getBoundingClientRect(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Looking for "and". | |
Markup is the following: | |
<body> | |
<div id="text">Pride and Prejudice</div> | |
</body> | |
*/ | |
var highlight = { | |
text:"and", | |
startContainer:"//*[@id='text']", | |
startOffset:6, | |
endContainer:"//*[@id='text']", | |
endOffset:9 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Looking for "and". | |
Markup is the following: | |
<body> | |
<div id="text">Pride and Prejudice</div> | |
</body> | |
*/ | |
var highlight = { | |
text:"and", | |
startContainer:"/html/body/node()[1]", | |
startOffset:6, | |
endContainer:"/html/body/node()[1]", | |
endOffset:9 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Looking for "and". | |
Markup is the following: | |
<body> | |
<div id="text">Pride and Prejudice</div> | |
</body> | |
*/ | |
var highlight = { | |
text:"and", | |
startContainer:"0/0", | |
startOffset:6, | |
endContainer:"0/0", | |
endOffset:9 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Looking for "Prejudice". | |
Markup is the following: | |
<body> | |
<div> | |
<div>A classic:</div> | |
<div>Pride <span>and</span> Prejudice</div> | |
</div> | |
</body> | |
*/ | |
var highlight = { | |
text:"Prejudice", | |
startContainer:"0/1/2", | |
startOffset:1, | |
endContainer:"0/1/2", | |
endOffset:10 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment