Giter Club home page Giter Club logo

text-vide's Introduction

TextVide (vide; Latin for "see")

npm bundle size npm downloads jsDelivr hits (npm) GitHub package.json version (subfolder of monorepo) changelog

ci codecov

logo

Support all languages that separate words with spaces

Try on Runkit or Online Sandbox

This module is an open source implementation that mimics the behavior of the Bionic Reading API.

It does not require any additional licenses, except for MIT. (#38)

💫 Features

Feature State
Support all languages
Support ESM and CommonJS
Custom sep Style
Fixation-Points
Ignore HTML Tags
Ignore HTML Entity
Saccade

Benchmark

Sun Aug 07 2022 01:33:40 GM +0900
length of normal text: 590
length of text with html tags: 1579

normal#ignoreHtmlTags x 46,106 ops/sec ±4.22% (86 runs sampled)
normal#notIgnoreHtmlTags x 53,200 ops/sec ±0.93% (89 runs sampled)
withHtmlTags#ignoreHtmlTags x 3,213 ops/sec ±0.92% (87 runs sampled)
withHtmlTags#notIgnoreHtmlTags x 3,605 ops/sec ±1.59% (87 runs sampled)

code

⚙️ Install

npm i text-vide
yarn add text-vide
pnpm add text-vide

CDN

<script src="https://cdn.jsdelivr.net/npm/text-vide/dist/index.iife.js"></script>

📖 Usage

Browser

<script src="https://cdn.jsdelivr.net/npm/text-vide/dist/index.iife.js"></script>
<script>
  const text =
    'Bionic Reading is a new method facilitating the reading process by guiding the eyes through text with artificial fixation points. As a result, the reader is only focusing on the highlighted initial letters and lets the brain center complete the word. In a digital world dominated by shallow forms of reading, Bionic Reading aims to encourage a more in-depth reading and understanding of written content.';

  const highlightedText = textVide.textVide(text);

  console.log(highlightedText); // '<b>Bion</b>ic <b>Readi</b>ng ... <b>writt</b>en <b>conte</b>nt.'
</script>

ESM

import { textVide } from 'text-vide';

const text =
  'Bionic Reading is a new method facilitating the reading process by guiding the eyes through text with artificial fixation points. As a result, the reader is only focusing on the highlighted initial letters and lets the brain center complete the word. In a digital world dominated by shallow forms of reading, Bionic Reading aims to encourage a more in-depth reading and understanding of written content.';

const highlightedText = textVide(text);

console.log(highlightedText); // '<b>Bion</b>ic <b>Readi</b>ng ... <b>writt</b>en <b>conte</b>nt.'

CommonJS

const { textVide } = require('text-vide');

const text =
  'Bionic Reading is a new method facilitating the reading process by guiding the eyes through text with artificial fixation points. As a result, the reader is only focusing on the highlighted initial letters and lets the brain center complete the word. In a digital world dominated by shallow forms of reading, Bionic Reading aims to encourage a more in-depth reading and understanding of written content.';

const highlightedText = textVide(text);

console.log(highlightedText); // '<b>Bion</b>ic <b>Readi</b>ng ... <b>writt</b>en <b>conte</b>nt.'

📚 API

textVide(text: string, options?: Options)

textVide('text-vide');
textVide('text-vide', {
  // ... Options
});

Options

type Options = Partial<{
  sep: string | string[];
  fixationPoint: number;
  ignoreHtmlTag: boolean;
  ignoreHtmlEntity: boolean;
}>;

sep

  • Default: ['<b>', '</b>']

Passing a string allows you to specify the Beginning and End of the highlighted word at once.

textVide('text-vide', { sep: '**' }); // '**tex**t-**vid**e'

It can also set them up by passing a list of length 2.

textVide('text-vide', { sep: ['<strong>', '</strong>'] }); // '<strong>tex</strong>t-<strong>vid</strong>e'

fixationPoint

  • Default: 1
  • Range: [1, 5]
// Default fixation-point: 1
textVide('text-vide'); // '<b>tex</b>t-<b>vid</b>e'

// Changed fixation-point: 5
textVide('text-vide', { fixationPoint: 5 }); // '<b>t</b>ext-<b>v</b>ide'

ignoreHtmlTag

  • Default: true

If this option is true, HTML tags are not highlighted.

textVite('<div>abcd</div>efg'); // '<div><b>abc</b>d</div><b>ef</b>g'
textVite('<div>abcd</div>efg', { ignoreHtmlTag: false }); // '<<b>di</b>v><b>abc</b>d</<b>di</b>v><b>ef</b>g'

ignoreHtmlEntity

  • Default: true

If this option is true, HTML entities are not highlighted.

textVide('&nbsp;abcd&gt;'); // '&nbsp;<b>abc</b>d&gt;'
textVide('&nbsp;abcd&gt;', { ignoreHtmlEntity: false }); // &<b>nbs</b>p;<b>abc</b>d&<b>g</b>t;

License

MIT @Gumball12

It does not require any additional licenses, except for MIT. (#38)

text-vide's People

Contributors

gumball12 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

text-vide's Issues

Doesn't respect punctuation; doesn't match output of bionic website

I wanted to more closely match the formatting of the demo on bionic-typings website, this is what i came up with. it also ignores punctuation. perhaps you can adapt this to your library. cheers

const bionicWordSplit = (word) => {
  const { length } = word;
  let splitPoint;
  switch(true) {
    case length<=4:
      splitPoint = length-1;
    break;
    default:
      splitPoint = length-2; 
    break;
  }
  const first = word.slice(0, splitPoint);
  const second = word.slice(splitPoint);

  return [first, second];
};

function splitParagraphs( str ) {
  return str.split("\n").map(paragraph=>paragraph.replace("\r",""));
}

function unrollToIntermediateStructure( text ) {
  const paragraphs = splitParagraphs(text);
  const exp = /(\w+)/g;
  return paragraphs.map(paragraph=>{
    return paragraph.split(exp).map(item=>{
      if(item.includes('!')||item===' '||item.includes('?')||item.includes('.')||item.includes(',')||item===""){
        return item;
      }
      return bionicWordSplit(item);  
    })
  });
}

function format( intermediateStructure, formatWordFn ) {
  return intermediateStructure.map(paragraphs=>paragraphs.map(item=>Array.isArray(item)?formatWordFn(item):item).join("")).join("\n");
}

function htmlFormatter([start,end]) {
  return `<strong>${start}</strong>${end}`;
}

function markdownFormatter([start,end]) {
  return `**${start}**${end}`;
}

const test = 'Welcome to bionic reading. This will teach you how to read and write in bionic style. I am not sure how this algorithm works. Walking, running, jumping, standing all can be achieved with supreme grace and wonderous accuracy.';

const intermediate = unrollToIntermediateStructure(test);
const htmlResult = format(intermediate,htmlFormatter);
const markdownResult = format(intermediate,markdownFormatter);

console.log(intermediate);
console.log(htmlResult);
console.log(markdownResult);

Handling of hyphenated words and period delineated acronyms, backticks (other punctuations)?

Hi gumball, I'm back home from my surgery and decided to push the bionic api a bit more and see what i could discover about how it handles edge cases. here is a screenshot

image

As you can see the roman numerals and numeric lists will require no special logic to support, and indeed your algorithm already will match the bionic api for this, so thats good.

But i identified two edge cases:

  1. period delineated acronyms - like the S.W.A.T in the above screen. As you can see their api identifies it as an a single word and ignores the periods for purposes of word highlighting, but also periods in the highlighted section are highlighted as well. this might require a bit of tricky logic, i am not sure. maybe you can think of a better solution
  2. hyphenated words - like github-api in above example. as you can see each segment of a hyphenated word grouping is highlighted seperately.

Also, noticed that backtick and possibly other punctuation characters need to be ignored like you've already done with periods and such, so perhaps we need to look deeper into that to add full support for all punctuation characters.

If i can think of any other odd edge cases, i will report back to this thread.

Hello I want to ask a question

Hi. I'm new to coding. Is this possible to implement with a ChakraUI library for converting text to bionic reading?

Also, I'm not sure if this is the right place to ask.

The 'b' tag is not recommended.

The <b> tag is not recommended. However, the <strong> tag affects the screen reader, so it's not a good idea either. I think it can use the same tag as <span>.

Other projects have identified the use of arbitrary tags. It seems to be one of the ways to use it.

support multiple languages

some languages that do not separate words with spaces, such as Japanese or Chinese, are difficult to support.

The documentation for the sep option is incorrect.

Expected behavior
It should be revised as follows:

Passing a string allows you to specify the Beginning and End of the highlighted word at once.

- ```ts
- textVide('text-vide', '**'); // '**tex**t-**vid**e'
- ```
+ ```ts
+ textVide('text-vide', { sep: '**' }); // '**tex**t-**vid**e'
+ ```

It can also set them up by passing a list of length 2.

- ```ts
- textVide('text-vide', ['<strong>', '</strong>']); // '<strong>tex</strong>t-<strong>vid</strong>e'
- ```
+ ```ts
+ textVide('text-vide', { sep: ['<strong>', '</strong>'] }); // '<strong>tex</strong>t-<strong>vid</strong>e'
+ ```

Ignore element tags, i.e. `<a ... >`

Is there any supported way to ignore element tags, like links? For example...

textVide('<a href="https://en.wikipedia.org/wiki/All_models_are_wrong" target="_blank">quote</a>)

outputs...

<a href="https://en.wikipedia.org/wiki/All_models_are_wrong" target="_blank"><b>qu</b>ote</a>

Rendered differently for Numbers

Currently, numbers are treated the same as letters, but they actually have the following rules:

  • 1234567890 -> 1234567890
  • 1234-567890 -> 1234-567890
  • a1234567890 -> <b>a12345678</b>90
  • 1234567890a -> <b>123456789</b>0a
  • 1234a567890 -> <b>1234a5678</b>90
  • 1234!567890 -> <b>1234!5678</b>90
  • !1234567890 -> !1234567890
  • 1234567890! -> 1234567890!

Bionic Reading® Legal Stuff

This isn't a bug, but I just want to inform y'all that the wonderful® folks at Bionic Reading® have decided to crack down on any open source projects that involves Bionic Reading®. It is advised to remove all mentioning of Bionic Reading® for now to avoid legal repercussions.

Context
legal notice

line break doesn't seem to work properly

test:


    a
    b
    c

expected(dom style):

    <b>a</b>
    <b>b</b>
    <b>c</b>

result(dom style):

<b>
</b> <b></b> <b></b> <b></b> <b>a</b>
 <b></b> <b></b> <b></b> <b>b</b>
 <b></b> <b></b> <b></b> <b>c</b>

expected(markdown style):

    **a**
    **b**
    **c**

result(markdown style):

**
** **** **** **** **a**
 **** **** **** **b**
 **** **** **** **c**

Ignore HTML tags in source text

Would be nice if TextVide had an option to ignore HTML tags in the source text.

I have a source text that is an HTML string, previously rendered from markdown. The only way I have been able to use TextVide is by using jquery to render the HTML, looping over each tag, and running TextVide on each individual text node. Very inelegant and probably inefficient.

Also as a bonus feature it would be good to be able to provide a blacklist of specific tags to exclude their content from TextVide, for example existing <b> or <strong> tags.

Add support for emojis

Consider this;

const { bionicReading } = require("bionic-reading");

console.log(bionicReading("👆 hello there, this is some dummy text"));

When I run it, the emoji seems to break:

"<b>�</b>� <b>hel</b>lo <b>the</b>re, <b>thi</b>s <b>i</b>s <b>som</b>e <b>dum</b>my <b>tex</b>t"

bionic-issue

Please fix this ASAP!

Add ignoreHtmlEntities

Is your feature request related to a problem? Please describe.
I noticed that HTML entities such as &nbsp; are not ignored.

Describe the solution you'd like
I would be happy if HTML entities such as &nbsp; were ignored, just as the HTML tags are ignored. It might be possible to filter for strings that start with a & and end with a ; without a space in between.

Describe alternatives you've considered
I can't think of an alternative.

Additional context
Screenshot 2023-11-09 um 17 03 40

At this point, I cannot intervene in the code, as a change would be undone with the next update of the CMS.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.