Comparing version 2.0.0 to 2.0.1
23
index.js
@@ -106,3 +106,3 @@ var fs = require('fs'); | ||
// Remove empty tags | ||
if (!$(this).text().trim()) { | ||
if (!$(this).html().trim()) { | ||
if (!_.includes(rules.allowedEmpty, tagName)) { | ||
@@ -115,4 +115,14 @@ return $(this).remove(); | ||
if (!rules.allowed[tagName]) { | ||
// Set content in a paragraph | ||
$(this).replaceWith('<p><b>Illegal HTML tag removed : </b>'+$(this).html()+'</p>'); | ||
// Set content in a <p> tag or in a <span> if parent is a <p> | ||
var warning = '<b>Illegal HTML tag removed : </b>'+$(this).html(); | ||
var $container = $('<p></p>'); | ||
var $parent = $(this).parent(); | ||
var parentTag; | ||
if (!!$parent.length) parentTag = getTagName($parent); | ||
if (parentTag === 'p') $container = $('<span></span>'); | ||
$container.html(warning); | ||
$(this).replaceWith($container); | ||
return; | ||
@@ -154,2 +164,3 @@ } | ||
// Move local referenced tags before next <h1> | ||
// Prevent moving title tags | ||
function moveLocalReferences() { | ||
@@ -164,3 +175,7 @@ $('a').each(function() { | ||
var $referencedTag = $(href); | ||
if (!$referencedTag.length) return; | ||
var tagName = getTagName($referencedTag); | ||
if (_.startsWith(tagName, 'h')) return; | ||
// Check existence | ||
@@ -235,4 +250,4 @@ if (!_.isUndefined($referencedTag.get(0))) { | ||
setAnchorsId(); | ||
cleanElements(); | ||
moveLocalReferences(); | ||
cleanElements(); | ||
// Cleanup tables | ||
@@ -239,0 +254,0 @@ removeNestedTables(); |
{ | ||
"name": "brightml", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Smart utility rendering markdown-ready HTML", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -280,9 +280,11 @@ var should = require('should'); | ||
'Sample text'+ | ||
'<memo>This is a fictious tag</memo>'+ | ||
'</p>'; | ||
'<memo>This should become a span</memo>'+ | ||
'</p>'+ | ||
'<memo>This should turn into a p</memo>'; | ||
var correctOutput = '<p>'+ | ||
'Sample text'+ | ||
'<p><b>Illegal HTML tag removed : </b>This is a fictious tag</p>'+ | ||
'</p>'; | ||
'<span><b>Illegal HTML tag removed : </b>This should become a span</span>'+ | ||
'</p>'+ | ||
'<p><b>Illegal HTML tag removed : </b>This should turn into a p</p>'; | ||
@@ -354,3 +356,3 @@ brightml.parse(input); | ||
'This too'+ | ||
'<memo>This is a fictious tag</memo>'+ | ||
'<memo>This should become a span</memo>'+ | ||
'</p>'+ | ||
@@ -378,3 +380,3 @@ '<table>'+ | ||
'This too'+ | ||
'<p><b>Illegal HTML tag removed : </b>This is a fictious tag</p>'+ | ||
'<span><b>Illegal HTML tag removed : </b>This should become a span</span>'+ | ||
'</p>'+ | ||
@@ -381,0 +383,0 @@ '<h1>Part 2</h1>'+ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27407
652