
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Transform functionality to move between HTML Elements and a text model.
Hello <a href="place" alt="hey">there</a> <u>person</u>!
becomes
{
"text": "Hello there person!",
"blocks": {
"link": [ { "start": 6, "end": 11, "href": "place", "alt": "hey" } ],
"emphasis": [ 12, 18 ]
}
}
npm install --save text-model
Convert from an Element to a text model representation.
var el = document.querySelector('.some-element');
var model = textModel.fromElement(el);
Convert from a text model representation to an Element.
var el = textModel.toElement(model);
paragraphEl.appendChild(el);
Merge text together -- simple styling tags (like <i>, <b>, <em>) will be
merged correctly as well.
var a = textModel.fromElement(document.querySelector('.a'));
var b = textModel.fromElement(document.querySelector('.b'));
var merged = textModel.concat(a, b);
paragraphEl.appendChild(textModel.toElement(merged));
Split text apart -- tags will be split correctly as well.
var model = textModel.fromElement(document.querySelector('.a'));
var splitModels = textModel.split(a, 15);
paragraphEl.appendChild(textModel.toElement(splitModels[0]));
paragraphEl.appendChild(textModel.toElement(splitModels[1]));
textModel.updateSameAs({
'B': 'STRONG',
'U': 'EM',
'I': 'EM',
'H1': 'H2',
'H3': 'H2',
'H4': 'H2',
'H5': 'H2',
'H6': 'H2',
'STRIKE': 'DEL'
});
These tags will be converted if they are seen. The defaults are as above, but you can pass in an object of tag names (uppercase) that will merge and overwrite them. To remove a default conversion, simply pass <tagname>: null in the object:
textModel.updateSameAs({
'B': null, // override default, don't convert <b> to <strong>
'H1': 'STRONG', // convert ALL headers to <strong>
'H2': 'STRONG',
'H3': 'STRONG',
'H4': 'STRONG',
'H5': 'STRONG',
'H6': 'STRONG',
'SPAN': 'EM', // convert all spans to <em>
'STRIKE': null // don't convert <strike>. this will remove the tag as <strike> is deprecated in html (and thus removed by text-model)
});
We use karma and mocha for testing.
npm test
Fork the project and submit a PR on a branch that is not named master. We use linting tools and unit tests, which are built constantly using continuous integration. If you find a bug, it would be appreciated if you could also submit a branch with a failing unit test to show your case.
FAQs
A representational text model
The npm package text-model receives a total of 11 weekly downloads. As such, text-model popularity was classified as not popular.
We found that text-model demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.