julianshapiro / blast Goto Github PK
View Code? Open in Web Editor NEWBlast text apart to make it manipulable.
Home Page: julian.com/research/blast
License: MIT License
Blast text apart to make it manipulable.
Home Page: julian.com/research/blast
License: MIT License
Blast treats spaces between words as non-characters. This causes the character delimiter to return improper indexes. Because of this, lining up character index data with blast's generated blast-indexes is very difficult.
There should be an option to treat whitespace as characters in order to maintain the actual index of characters from start to finish in a string of text.
By the way... this could be handled simply (I think) by adding a "preserveWhitespace" option that would only apply to characters. Then, you could do this inside the delimiter creation section:
case "character":
/* Matches every non-space character. */
/* Note: This is the slowest delimiter. However, its slowness is only noticeable when it's used on larger bodies of text (of over 500 characters) on <=IE8.
(Run Blast with opts.debug=true to monitor execution times.) */
if (opts.preserveWhitespace)
delimiterRegex = /(.)/;
else
delimiterRegex = /\S/;
break;
I don't know if "." is the best way to do this. Perhaps it should only preserve the actual space character.
As a sidenote, to render properly you would need to give white-space: pre|pre-line|pre-wrap to the blasted element to make the spaces not collapse in their own HTML elements.
@julianshapiro , did you consider any of this during initial development?
Hi,
I don't think it's an issue, more a request: Blast is awesome, I have so many ideas I could use it for my projects. The only thing I found annoying, and I'm not good enough with js to figure how to change it, is that if I want to style sentences, Blast leaves the space right after the end of every sentence outside of span tags, leaving an unstyled space between every sentence. Is that clear ? Is there an easy fix for this ?
For now, i do this in js :
$("document").ready(function() {
$("p").blast({
delimiter: "sentence"
});
$('.blast').prepend(' ');
});
and hide the last space with font-size:0 in css. But then there is an extra space before the first sentence of every paragraph. Anyway, far from perfect.
Again, this is really great otherwise, so many thanks !
best,
Robin
On Line 419, thisParentNode.normalize(); is called in order to combine and clean up all child nodes. On certain versions/certain settings in IE, the normalize(); function does not work correctly. It does not combine the child nodes, which in turn leads to faulty results.
For example:
Both will return no matches. The correct functionality should be:
I know this is mostly a bug in IE, but maybe changing the code to not use this function, and instead doing it manually might be the better choice. Another solution might be to combine all child nodes into one, before searching through them. Although this is not necessary a bug with blast, it does affect it.
Here is more information: http://stackoverflow.com/questions/12972090/ie-9-standards-mode-normalize-method-does-not-work
It would be great to have a directive for blast :)
Within a contenteditable div, I will execute a blast as the user is typing to highlight the last group of nouns entered into the div by the user (using an NLP package). After the blast, the cursor is positioned at the beginning of the blast style DOM object, as opposed to the end of it. When the user continues typing, the blast is removed and the cursor actually is positioned where expected -- however, while the blast is shown, the cursor blinks at the beginning of the blast span and would lead the user to think that any typing that is about to be done will occur before the blast span of text.
Can I haz RTL support?
After effect in iOS 5 blink the last word.
$("#lastnews .ticker_tick")
.html(data.title)
.attr("href", data.hash)
.blast({ delimiter: "character", aria: false })
.velocity("fadeIn", {
display: null,
duration: 600,
stagger: 60,
delay: 600,
mobileHA: !conditionizr.ios,
complete: $$.last_news_home.after_magic
});
Hey, I've noticed a problem when you try to use the same function twice on 2 divs with the same class. I've made a demo on codepen here, illustrating the problem. The function only works on the last div.
http://codepen.io/sdras/pen/8d7f8116818ec9ec00f8f82be65838d5
I forked your demo on delimiters, just so that we know for sure I'm using versions of jquery, velocity, velocity ui, and blast that do work in isolation.
I have to make speed reader .... a set of three words gets highlighted ... how can i achieve this quickly ?
http://velocityjs.org/research/blast hits 404
Feature request: Allow paragraph lines to be identified.
I've been looking all over for a library to split articles into paragraphs, sentences and words. As you know its not as easy as splitting at every '.'
Is there any way to use Blast to return an array of sentences without referencing the Dom elements?
OR
Is Blast based on some library logic somewhere?
Please and thank you for the assistance.
I am having an issue where emoji aren't showing up after the character blast apart. Works in Firefox just fine, but no other browser. Is this related to the utf-8 character separation thing?
Hi Julian,
Gotta start with saying this is awesome work. Haven't seen anything that comes close to transforming a webpage of text into a DOM structure that can be manipulated at the word/sentence level. So thank you!
I can peer into source at some point, but off the top of your head, is it possible to use Blast, either as is or modified, such that I can manipulate text at the word level and at the sentence level at the same time? Not sure if that makes sense but let me try to explain in code:
<div>
Hello World. How are you?
<div>
into:
<div class="blast-root">
<div class="sentence-1">
<span class="blast">Hello</span>
<span class="blast">World.</span>
</div>
<div class="blast-sentence-2">
<span class="blast">How</span>
<span class="blast">are</span>
<span class="blast">you?</span>
</div>
</div>
Thanks also for still replying to issues and continuing to support this work!
for working example, see http://codepen.io/anon/pen/pyYJzv
If you have
<div>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do. Eiusmod tempor incididunt ut labore et dolore magna aliqu.
Lorem IPSUM dolor sit amet, consectetur adipisicing elit, sed do. Eiusmod tempor incididunt ut labore et dolore magna aliqu.
</div>
and search for ipsum
$("div").blast({ delimiter: /ipsum/gi, debug:true });
notice the case of ipsum in both sentences. The result is
<div aria-label="..." class="blast-root">
Lorem<span class="blast" aria-hidden="true" style="background-color: rgb(7, 93, 154);"> ipsu</span>m dolor sit amet, consectetur adipisicing elit, sed do. Eiusmod tempor incididunt ut labore et dolore magna aliqu.
Lorem <span class="blast" aria-hidden="true" style="background-color: rgb(241, 33, 133);">IPSUM</span> dolor sit amet, consectetur adipisicing elit, sed do. Eiusmod tempor incididunt ut labore et dolore magna aliqu.
</div>
notice that the first instance is offset by 1
<span ...> ipsu</span>m
My workaround is to lower-case the comparison of matchText and subMatchText, although I don't think this is the correct solution as simple lowercase comparisons are not necessarily appropriate in all locales:
https://github.com/saviourofdp/blast/commit/1a171d62c3af3fa2e980cebe76e1cd9a39e7dbc8
When a first name is abbreviated, the library doesn't normally catch it. A good solution might be to add the following regex as an exception for this case:
[A-Z][a-z]*\.\ [A-Z]
In action: Regex101.com
It accounts for all the instances of F. Presencia or similar first names abbreviations.
Here a list of examples of first names, all follow this pattern.
A small bug at http://julian.com/research/blast/ in "Options Overview" code example, there are missing commas that should be after each parameter in the sample code. Great libraries velocity & blast ๐
Where it says:
npm install --save julianshapiro/blast
bower install blast
It should say:
npm install --save blast-text
bower install blast-text
and the version in bower is not the lastest.
I am using Blast and wondered if it is expected that the original sequence of an array is not honoured, instead blast returns according to position in the DOM.
Here is an illustration: http://jsfiddle.net/9gogkww5/
I need to blast fragments with or without spanish diacritics. Is that possible now? Any suggestion?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.