https://github.com/joscha/html-context
Gives (textual) context for a given DOM node
https://github.com/joscha/html-context
Last synced: 5 days ago
JSON representation
Gives (textual) context for a given DOM node
- Host: GitHub
- URL: https://github.com/joscha/html-context
- Owner: joscha
- License: mit
- Created: 2015-11-30T07:26:52.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-02-18T13:07:15.000Z (almost 9 years ago)
- Last Synced: 2025-03-08T09:35:39.501Z (10 months ago)
- Language: JavaScript
- Size: 47.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 39
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HTML Context
[](https://travis-ci.org/joscha/html-context)
[](https://www.npmjs.com/package/html-context)
[](https://opensource.org/licenses/MIT)
[](https://david-dm.org/joscha/html-context)

[](https://coveralls.io/github/joscha/html-context)
This package allows you to generate some HTML context for a given DOM node. E.g.
Some markup looking like this:
```html
Hello world
```
with
```javascript
const div = window.document.getElementById('x');
htmlContext(div, {
maxLength: 19,
});
```
would result in
```
…
```
The context can either be `document` or an `HTMLElement`.
## Install
```console
npm install html-context --save
```
or in the browser (UMD):
```html
```
## Options
`options.maxLength`: the maximum length of the returned context. The package will try and fit the outermost tag in if it can. Defaults to no maximum length.
`options.beautify`: Beautifies the returned context snippet. Defaults to `false`.
`options.placeholder`: The placeholder to use for capped markup. Defaults to `…`.