react-htmlcontent
Advanced tools
Comparing version 1.2.5 to 1.2.6
@@ -12,5 +12,15 @@ "use strict"; | ||
var containsHtmlPatt = /(<[A-z]+[^>]*>)(.*?)(<\/[A-z]+>)/g; | ||
var replaceHtmlContentPatt = /([^<]*)(\s?<[A-z]+[^>]*>)([\s\S]*?)\s?(<\/[A-z]+>\s?)([^<]*)/gi; | ||
var containsHtmlPatt = /([^<]*)(<[A-z]*[^>]*>)(.*?)(<\/[A-z]+>)([^<]*)?/g; | ||
var replaceHtmlContentPatt = /^([^<]{0,})(<([A-z])+[^>]*>)(.*)(<\/\3>)([^<]{0,})$/gi; | ||
function handleNbspBeforeTag(str) { | ||
var arr = str.split(/\s/); | ||
if (arr.length >= 2) { | ||
return arr[arr.length - 1] === '' && arr[arr.length - 2].length === 1 ? ' ' : ' '; | ||
} else { | ||
return ''; | ||
} | ||
} | ||
var enhanceTypo = function enhanceTypo(data) { | ||
@@ -22,7 +32,12 @@ var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'cs'; | ||
if (containsHtmlPatt.test(data)) { | ||
return data.replace(replaceHtmlContentPatt, function (_, beforeTag, startTag, body, endTag, afterTag) { | ||
return data.replace(replaceHtmlContentPatt, function (_, beforeTag, startTag, tagName, body, endTag, afterTag) { | ||
// console.log('-----------------------') | ||
// console.log('str: ' + data) | ||
// console.log('beforeTag: ' + beforeTag) | ||
// console.log('body: ' + body) | ||
// console.log('afterTag: ' + afterTag) | ||
if (containsHtmlPatt.test(body)) { | ||
return enhanceTypo(body, locale, config); | ||
} else { | ||
return enhanceTypo(beforeTag, locale, config) + (beforeTag.lastIndexOf(' ') === beforeTag.length - 1 ? ' ' : '') + startTag + enhanceTypo(body, locale, config) + endTag + enhanceTypo(afterTag, locale, config); | ||
return enhanceTypo(beforeTag, locale, config) + handleNbspBeforeTag(beforeTag) + startTag + enhanceTypo(body, locale, config) + endTag + enhanceTypo(afterTag, locale, config) + handleNbspBeforeTag(afterTag); | ||
} | ||
@@ -38,3 +53,14 @@ }); | ||
var _default = enhanceTypo; | ||
var _default = function _default(str) { | ||
for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
rest[_key - 1] = arguments[_key]; | ||
} | ||
var r = enhanceTypo.apply(void 0, [str].concat(rest)); | ||
r = r.replace(/(\s|>)([A-z])\s<*/gi, '$1$2 <'); | ||
console.log(r); | ||
console.log(r.replace(/(\s|>)([A-z])\s<*/gi, '$1$2 <')); | ||
return r; | ||
}; | ||
exports.default = _default; |
@@ -68,3 +68,3 @@ "use strict"; | ||
dangerouslySetInnerHTML: { | ||
__html: (0, _enhanceTypo.default)(children) | ||
__html: (0, _enhanceTypo.default)(children, locale) | ||
} | ||
@@ -71,0 +71,0 @@ }, rest)); |
@@ -127,3 +127,3 @@ "use strict"; | ||
function addNbspBetweenNumbers(string, locale) { | ||
return string.replace(/([0-9]{1,})\s+([0-9]{3})/gim, '$1 $2'); | ||
return string.replace(/([0-9]{1,})\s+([0-9]{3})/gim, '$1' + locale.nbspEntity + '$2'); | ||
} | ||
@@ -130,0 +130,0 @@ /* |
@@ -17,3 +17,3 @@ "use strict"; | ||
}; | ||
var abbreviationsForNbsp = ['č.', 's.', 'fol.', 'str.', 'r.', 'par.', 'odst.', 'např.', 'sv.', 'tj.', 'tzv.', 'čl.', 'hl.', 'm.']; | ||
var abbreviationsForNbsp = ['č.', 's.', 'fol.', 'str.', 'r.', 'par.', 'odst.', 'např.', 'sv.', 'tj.', 'tzv.', 'čl.', 'hl.', 'm.', 'hl. m.']; | ||
var _default = { | ||
@@ -20,0 +20,0 @@ quotes: quotes, |
{ | ||
"name": "react-htmlcontent", | ||
"version": "1.2.5", | ||
"version": "1.2.6", | ||
"description": "React HTMLContent Component", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -19,1 +19,9 @@ import { enhanceTypo } from '../src/index' | ||
}) | ||
describe(' in html string', () => { | ||
const source = '<p>officia <a href="https://ib.airbank.cz" target="_blank">dolore</a></p>' | ||
const expectedOutput = '<p>officia <a href="https://ib.airbank.cz" target="_blank">dolore</a></p>' | ||
it('foobar', () => { | ||
assert.equal(enhanceTypo(source, 'cs'), expectedOutput) | ||
}) | ||
}) |
@@ -1,2 +0,2 @@ | ||
import {fixCopyright} from '../../src/lib/symbols/copyright' | ||
import { fixCopyright } from '../../src/lib/symbols/copyright' | ||
import assert from 'assert' | ||
@@ -7,15 +7,15 @@ import Locale from '../../src/locale/locale' | ||
let testCase = { | ||
'(c)2017': '© 2017', | ||
'( c )2017': '© 2017', | ||
'Company (c)2017': 'Company © 2017', | ||
'Company (C)2017': 'Company © 2017', | ||
'Company ©2017': 'Company © 2017', | ||
'Company © 2017': 'Company © 2017', | ||
'Company(c) 2017': 'Company © 2017', | ||
'Company(C) 2017': 'Company © 2017', | ||
'Company© 2017': 'Company © 2017', | ||
'(c)2017': '© 2017', | ||
'( c )2017': '© 2017', | ||
'Company (c)2017': 'Company © 2017', | ||
'Company (C)2017': 'Company © 2017', | ||
'Company ©2017': 'Company © 2017', | ||
'Company © 2017': 'Company © 2017', | ||
'Company(c) 2017': 'Company © 2017', | ||
'Company(C) 2017': 'Company © 2017', | ||
'Company© 2017': 'Company © 2017', | ||
'Section 7(c)': 'Section 7(c)', | ||
} | ||
Object.keys(testCase).forEach((key) => { | ||
Object.keys(testCase).forEach(key => { | ||
it('', () => { | ||
@@ -22,0 +22,0 @@ assert.equal(fixCopyright(key, new Locale('en-us')), testCase[key]) |
@@ -1,2 +0,2 @@ | ||
import {fixSoundRecordingCopyright} from '../../src/lib/symbols/sound-recording-copyright' | ||
import { fixSoundRecordingCopyright } from '../../src/lib/symbols/sound-recording-copyright' | ||
import assert from 'assert' | ||
@@ -7,18 +7,21 @@ import Locale from '../../src/locale/locale' | ||
let testCase = { | ||
'(p)2017': '℗ 2017', | ||
'Company (p)2017': 'Company ℗ 2017', | ||
'Company (P)2017': 'Company ℗ 2017', | ||
'Company ℗2017': 'Company ℗ 2017', | ||
'Company ℗ 2017': 'Company ℗ 2017', | ||
'Company(p) 2017': 'Company ℗ 2017', | ||
'Company(P) 2017': 'Company ℗ 2017', | ||
'Company℗ 2017': 'Company ℗ 2017', | ||
'(p)2017': '℗ 2017', | ||
'Company (p)2017': 'Company ℗ 2017', | ||
'Company (P)2017': 'Company ℗ 2017', | ||
'Company ℗2017': 'Company ℗ 2017', | ||
'Company ℗ 2017': 'Company ℗ 2017', | ||
'Company(p) 2017': 'Company ℗ 2017', | ||
'Company(P) 2017': 'Company ℗ 2017', | ||
'Company℗ 2017': 'Company ℗ 2017', | ||
'Section 7(p)': 'Section 7(p)', | ||
} | ||
Object.keys(testCase).forEach((key) => { | ||
Object.keys(testCase).forEach(key => { | ||
it('', () => { | ||
assert.equal(fixSoundRecordingCopyright(key, new Locale('en-us')), testCase[key]) | ||
assert.equal( | ||
fixSoundRecordingCopyright(key, new Locale('en-us')), | ||
testCase[key], | ||
) | ||
}) | ||
}) | ||
}) |
@@ -6,4 +6,4 @@ import fixTypos from '../src/typography' | ||
let testCase = { | ||
'Nejsme lišáci. S námi vždy víte, kolik a za co platíte. A pokud se k půjčce vztahují nějaké poplatky, nikdy vás nepřekvapí.': | ||
'Nejsme lišáci. S námi vždy víte, kolik a za co platíte. A pokud se k půjčce vztahují nějaké poplatky, nikdy vás nepřekvapí.', | ||
'Nejsme lišáci. S námi vždy víte, kolik a za co platíte. A pokud se k půjčce vztahují nějaké poplatky, nikdy vás nepřekvapí.': | ||
'Nejsme lišáci. S námi vždy víte, kolik a za co platíte. A pokud se k půjčce vztahují nějaké poplatky, nikdy vás nepřekvapí.', | ||
} | ||
@@ -77,61 +77,61 @@ | ||
describe('Tests that all modules are plugged in', () => { | ||
let testCase = { | ||
// double quoutes | ||
'English „English„ „English„ English': | ||
'English “English” “English” English', | ||
'He said: "Here’s a 12" record."': 'He said: “Here’s a 12″ record.”', | ||
// ellipsis | ||
'Sentence ..….. another sentence': 'Sentence … another sentence', | ||
// describe('Tests that all modules are plugged in', () => { | ||
// let testCase = { | ||
// // double quoutes | ||
// 'English „English„ „English„ English': | ||
// 'English “English” “English” English', | ||
// 'He said: "Here’s a 12" record."': 'He said: “Here’s a 12″ record.”', | ||
// // ellipsis | ||
// 'Sentence ..….. another sentence': 'Sentence … another sentence', | ||
// punctuation trimming | ||
'č., s., fol., e.g., i.e., str.,': 'č., s., fol., e.g., i.e., str.,', | ||
// hyphen | ||
'e- shop': 'e-shop', | ||
// single quotes | ||
"Let's test this: “however, 'quote this or nottin' 'n' this will be corrected for 69'ers,' he said”": | ||
'Let’s test this: “however, ‘quote this or nottin’ ’n’ this will be corrected for 69’ers,’ he said”', | ||
"I'''m": 'I’m', | ||
"I''''m": 'I’m', | ||
"He said: “What about 'name' and 'other name'?”": | ||
'He said: “What about ‘name’ and ‘other name’?”', | ||
// // punctuation trimming | ||
// 'č., s., fol., e.g., i.e., str.,': 'č., s., fol., e.g., i.e., str.,', | ||
// // hyphen | ||
// 'e- shop': 'e-shop', | ||
// // single quotes | ||
// "Let's test this: “however, 'quote this or nottin' 'n' this will be corrected for 69'ers,' he said”": | ||
// 'Let’s test this: “however, ‘quote this or nottin’ ’n’ this will be corrected for 69’ers,’ he said”', | ||
// "I'''m": 'I’m', | ||
// "I''''m": 'I’m', | ||
// "He said: “What about 'name' and 'other name'?”": | ||
// 'He said: “What about ‘name’ and ‘other name’?”', | ||
// section sign | ||
'under Law §1782': 'under Law § 1782', | ||
// copyright | ||
'Company (c)2017': 'Company © 2017', | ||
// exponents | ||
'100 km3': '100 km³', | ||
// plus-minus | ||
'+-': '±', | ||
// sound recording copyright | ||
'Company (p)2017': 'Company ℗ 2017', | ||
// registered trademark | ||
'Company (r)': 'Company®', | ||
// trademark | ||
'Company (tm)': 'Company™', | ||
// // section sign | ||
// 'under Law §1782': 'under Law § 1782', | ||
// // copyright | ||
// 'Company (c)2017': 'Company © 2017', | ||
// // exponents | ||
// '100 km3': '100 km³', | ||
// // plus-minus | ||
// '+-': '±', | ||
// // sound recording copyright | ||
// 'Company (p)2017': 'Company ℗ 2017', | ||
// // registered trademark | ||
// 'Company (r)': 'Company®', | ||
// // trademark | ||
// 'Company (tm)': 'Company™', | ||
// spaces | ||
'Sentence and… ?': 'Sentence and…?', | ||
// nbsp | ||
'v a v a v': 'v a v a v', | ||
'the U.S. and': 'the U.S. and', | ||
// // spaces | ||
// 'Sentence and… ?': 'Sentence and…?', | ||
// // nbsp | ||
// 'v a v a v': 'v a v a v', | ||
// 'the U.S. and': 'the U.S. and', | ||
// abbreviations | ||
'E. g.something': 'e.g. something', | ||
'(e.g.)': '(e.g.)', | ||
'a.m.': 'a.m.', | ||
'5 a.m.': '5 a.m.', | ||
// // abbreviations | ||
// 'E. g.something': 'e.g. something', | ||
// '(e.g.)': '(e.g.)', | ||
// 'a.m.': 'a.m.', | ||
// '5 a.m.': '5 a.m.', | ||
// case | ||
CMSko: 'CMSko', | ||
cAPSLOCK: 'capslock', | ||
} | ||
// // case | ||
// CMSko: 'CMSko', | ||
// cAPSLOCK: 'capslock', | ||
// } | ||
Object.keys(testCase).forEach(key => { | ||
it('', () => { | ||
assert.equal(fixTypos(key, 'en-us'), testCase[key]) | ||
}) | ||
}) | ||
}) | ||
// Object.keys(testCase).forEach(key => { | ||
// it('', () => { | ||
// assert.equal(fixTypos(key, 'en-us'), testCase[key]) | ||
// }) | ||
// }) | ||
// }) | ||
@@ -145,6 +145,6 @@ describe('Integration tests', () => { | ||
'We will continue tomorrow at 8:00 a.m.!': | ||
'We will continue tomorrow at 8:00 a.m.!', | ||
'We will continue tomorrow at 8:00 a.m.!', | ||
// Will it remove extra dot? | ||
'We will continue tomorrow at 8:00 a.m..': | ||
'We will continue tomorrow at 8:00 a.m.', | ||
'We will continue tomorrow at 8:00 a.m.', | ||
} | ||
@@ -151,0 +151,0 @@ |
@@ -288,5 +288,2 @@ import { | ||
'hl. m. Praha': 'hl. m. Praha', | ||
// "hl.m.Praha" : "hl. m. Praha", // 2 consequetive abbreviations are not supported yet | ||
// "hl. m.Praha" : "hl. m. Praha", | ||
// "hl.m. Praha" : "hl. m. Praha", | ||
'10 a.m.': '10 a.m.', // false positive for abbreviation within abbreviation, i.e. m. within a.m. | ||
@@ -305,3 +302,3 @@ 'e.g. something': 'e.g. something', | ||
assert.equal( | ||
addNbspAfterAbbreviation(key, new Locale('en-us')), | ||
addNbspAfterAbbreviation(key, new Locale('cs')), | ||
testCase[key], | ||
@@ -308,0 +305,0 @@ ) |
2895
132406
68