GithubHelp home page GithubHelp logo

fex80 / html-highlight Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 1.49 MB

A npm package to add <span> tags to html content at specified positions – useful to highlight search results.

JavaScript 57.59% TypeScript 42.41%

html-highlight's Introduction

HTML HIGHLIGHT

Adds <mark> tags to html content at specified positions – useful to highlight search results.

Usage

Position parameters are gives as [index, length] arrays, so to highlight the first letter in a text, we use position [0, 1].

Add a highlight on the first letter of the text with CSS class c1:

htmlHighlight('I say Hello World.', [{ position: [0, 1], className: 'c1' }])
 --> '<mark class="c1">I</mark> say Hello World.'

We can also add multiple highlights with different classes:

htmlHighlight('I say Hello World.', [
  { position: [0, 1], className: 'c1' }, 
  { position: [2, 3], className: 'c2' }
])

--> '<mark class="c1">I</mark> <mark class="c2">say</mark> Hello World.')

That's it :)

Currently, we do not support nested or overlapping highlights.

RELEASE NOTES

2.0.0

  • now using <mark> tags as opposed to <span>

1.0.2

  • made an IE11-friendy move by replacing template strings with regular string concatenation

1.0.1

  • including HighlightSpecs in error message

1.0.0

  • Initial Release

Developer's notes

Internal: How to release a new version

  • Make sure lint and tests pass
  • Add release notes to README.md
  • Commit everything
  • Run publish command
    • PATCH: npm run preversion && npm version patch && npm publish
    • MINOR npm run preversion && npm version minor && npm publish

html-highlight's People

Contributors

fex80 avatar

Watchers

 avatar

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.