Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

brightml

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

brightml - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

33

index.js

@@ -5,2 +5,3 @@ var fs = require('fs');

var cheerio = require('cheerio');
var normall = require('normall');

@@ -148,2 +149,32 @@ var rules = require('./rules');

// Normalize titles id based on title text
function normalizeTitlesId() {
var titles = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
var ids = [];
var counter;
titles.forEach(function(title) {
$(title).each(function() {
// Compute new id
var oldId = $(this).attr('id');
var textId = normall.filename($(this).text());
var newId = textId;
counter = 0;
while (_.includes(ids, newId)) {
newId = textId+'-'+counter;
}
// Prevent obtaining the same id twice
ids.push(newId);
// Replace id in href links
$('*[href="#'+oldId+'"]').each(function() {
$(this).attr('href', '#'+newId);
});
// Replace title id
$(this).attr('id', newId);
});
});
};
// For empty <a> tags with an id attribute, set id on parent

@@ -273,2 +304,3 @@ function setAnchorsId() {

cleanElements();
normalizeTitlesId();
// Cleanup tables

@@ -289,2 +321,3 @@ removeNestedTables();

retrieveFootnotes: retrieveFootnotes,
normalizeTitlesId: normalizeTitlesId,
removeNestedTables: removeNestedTables,

@@ -291,0 +324,0 @@ formatTables: formatTables,

5

package.json
{
"name": "brightml",
"version": "3.0.0",
"version": "3.0.1",
"description": "Smart utility rendering markdown-ready HTML",

@@ -23,3 +23,4 @@ "main": "index.js",

"cheerio": "git://github.com/cheeriojs/cheerio.git#70c5608113d3efaf584efd29edafe173b74e106f",
"lodash": "^3.10.1"
"lodash": "^3.10.1",
"normall": "^0.2.2"
},

@@ -26,0 +27,0 @@ "scripts": {

@@ -106,2 +106,18 @@ # Brightml

#### brightml.normalizeTitlesId()
Set an `id` attribute on each `<h>` tag. The `id` is based on the title tag content.
Each reference to this `id` will be modified in consequence.
```HTML
<h1 id="some-id">A great title</h1>
<a href="#some-id">Back to a great title</a>
```
will become:
```HTML
<h1 id="a_great_title">A great title</h1>
<a href="#a_great_title">Back to a great title</a>
```
#### brightml.removeNestedTables()

@@ -108,0 +124,0 @@

46

test/test.js

@@ -217,2 +217,42 @@ var should = require('should');

describe('brightml.normalizeTitlesId()', function() {
it('should change the title id', function() {
var input = '<h1 id="345-is-a-weird-id">'+
'Sample title'+
'</h1>';
var correctOutput = '<h1 id="sample_title">'+
'Sample title'+
'</h1>';
brightml.parse(input);
brightml.normalizeTitlesId();
var output = brightml.render();
output.should.be.equal(correctOutput);
});
it('should replace references to title id', function() {
var input = '<h2 id="another-strange-id">'+
'A great title'+
'</h2>'+
'<a href="#another-strange-id">'+
'Go back'+
'</a>';
var correctOutput = '<h2 id="a_great_title">'+
'A great title'+
'</h2>'+
'<a href="#a_great_title">'+
'Go back'+
'</a>';
brightml.parse(input);
brightml.normalizeTitlesId();
var output = brightml.render();
output.should.be.equal(correctOutput);
});
});
describe('brightml.retrieveFootnotes()', function() {

@@ -414,3 +454,3 @@ it('should move the referenced <p> tag before the next <h1> tag', function() {

var correctOutput = '<h1 id="first-title">Part 1</h1>'+
var correctOutput = '<h1 id="part_1">Part 1</h1>'+
'<p>'+

@@ -442,5 +482,5 @@ 'Sample footnote'+

'</p>'+
'<h1>Part 2</h1>'+
'<h1 id="part_2">Part 2</h1>'+
'<p>Some content</p>'+
'<h1>Part 3</h1>'+
'<h1 id="part_3">Part 3</h1>'+
'<caption>Data table</caption>'+

@@ -447,0 +487,0 @@ '<table>'+

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc