New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

smark

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smark - npm Package Compare versions

Comparing version 1.2.0 to 2.0.0

src/typeIs.js

7

package.json
{
"name": "smark",
"version": "1.2.0",
"version": "2.0.0",
"description": "Smart parser from strings into HTML",
"main": "smark.js",
"main": "smark.min.js",
"scripts": {

@@ -10,3 +10,4 @@ "test": "mocha -R nyan",

"precompile": "npm run build",
"compile": "uglifyjs smark.js -m --comments 'license' > smark.min.js"
"compile": "uglifyjs smark.js -m --comments 'license' > smark.min.js",
"postcompile": "npm test"
},

@@ -13,0 +14,0 @@ "keywords": [

@@ -67,7 +67,2 @@ # Smark

1. CLI use
1. Documentation
1. Publish to npm
Expected problems:
1. Option passing is too hard. (Might only ever be solved in 2.0)
1. Documentation

@@ -6,22 +6,21 @@ /* @license smark.js written by Kenneth Lim <limzy.kenneth@gmail.com> (http://designerken.be)

// Default options
smark.options = {
"type": "auto",
"typography": true
};
// Type detection
smark.typeIs = require("./typeIs.js");
// Typographic changes will occur here before parsing into html so as not to mess up html quote marks.
smark.typographicChanges = require("./typography.js");
// Parse the string as a paragraph.
// See note.txt for more info.
smark.parseParagraph = require("./paragraph.js");
smark.generate = function(source, options) {
// Catching error in options
// if(typeof options.type !== 'string') console.warn("'type' option only accepts string.");
// if(typeof options.typography !== 'boolean') console.warn("'typopgraphy' option only accepts boolean.");
// Temporary variable to store source string for parsing
var tmp = source;
// The resulting html will be stored in this
var result = "";
// Make a copy of the global options
var opt = this.options;
// Default options
var opt = {
"type": "auto",
"typography": true
};
// Modify the options according to user passed in value

@@ -31,3 +30,3 @@ for (var i in options){

if (i == j){
opt.j = options.i;
opt[j] = options[i];
}

@@ -41,43 +40,25 @@ }

if (this.youtubeRE.test(source)) {
// Source is a Youtube link
tmp = source.replace(this.youtubeRE, "$1");
result = '<iframe class="smark youtube" src="https://www.youtube.com/embed/' + tmp + '" frameborder="0" width="853" height="480" allowfullscreen></iframe>';
if (type == 'auto') type = "youtube";
} else if (this.vimeoRE.test(source)) {
// Source is a Vimeo link
tmp = source.replace(this.vimeoRE, "$1");
result = '<iframe class="smark vimeo" src="https://player.vimeo.com/video/' + tmp + '" frameborder="0" width="853" height="480" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
if (type == 'auto') type = "vimeo";
} else if (this.imageRE.test(source)) {
// Source is an image link
tmp1 = source.replace(this.imageRE, "$1");
tmp2 = source.replace(this.imageRE, "$2");
tmp2 = this.typographicChanges(true, tmp2);
result = '<img class="smark image" title="' + tmp2 + '" src="' + tmp1 + '">';
if (this.imageLinkRE.test(source)) {
// tmp3 = source.replace(this.imageLinkRE, "$1");
tmp3 = this.imageLinkRE.exec(source)[0];
tmp3 = tmp3.substring(1, tmp3.length - 1);
result = '<a href="' + tmp3 + '" target=_blank>' + result + "</a>";
if (type == "auto"){
if (this.typeIs(source) == "youtube") {
// Source is a Youtube link
type = "youtube";
} else if (this.typeIs(source) == "vimeo") {
// Source is a Vimeo link
type = "vimeo";
} else if (this.typeIs(source) == "image") {
// Source is an image link
type = "image";
} else if (this.typeIs(source) == "link") {
// Source is a general link valid for iframe
type = "link";
} else if (this.typeIs(source) == "paragraph") {
// Parse the string as a paragraph.
type = "paragraph";
}
if (type == 'auto') type = "image";
} else if (this.htmlRE.test(source)) {
// Source is a general link valid for iframe
// Note: This is executed after Youtube and Vimeo test
// because this will be a valid match for them as well.
tmp = source.match(this.htmlRE)[0];
result = '<iframe class="smark website" src="' + tmp + '" width="853" height="480" frameborder="0"></iframe>';
if (type == 'auto') type = "link";
} else {
// Parse the string as a paragraph.
// Typographic changes will be made if noTypo is not passed.
// Markdown style syntax will be converted as well.
tmp = this.parseParagraph(typoMark, tmp);
// Treat the source as just a paragraph of text.
result = '<p class="smark paragraph">' + tmp + '</p>';
if (type == 'auto') type = "paragraph";
}else{
type = opt.type;
}
result = parse(source, type);
return {

@@ -87,20 +68,65 @@ html: result,

};
};
// parse() don't care about whether the type for str make sense or not,
// it just parse.
function parse(str, type){
var ret;
var that = smark;
switch(type){
case "youtube":
str = str.replace(that.youtubeRE, "$1");
ret = '<iframe class="smark youtube" src="https://www.youtube.com/embed/' + str + '" frameborder="0" width="853" height="480" allowfullscreen></iframe>';
break;
// Typographic changes will occur here before parsing into html so as not to mess up html quote marks.
smark.typographicChanges = require("./typography.js");
case "vimeo":
str = str.replace(that.vimeoRE, "$1");
ret = '<iframe class="smark vimeo" src="https://player.vimeo.com/video/' + str + '" frameborder="0" width="853" height="480" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
break;
// Parse the string as a paragraph.
// See note.txt for more info.
smark.parseParagraph = require("./paragraph.js");
case "image":
var tmp1 = str.replace(that.imageRE, "$1");
var tmp2 = str.replace(that.imageRE, "$2");
if (typoMark){
tmp2 = that.typographicChanges(tmp2);
}
ret = '<img class="smark image" title="' + tmp2 + '" src="' + tmp1 + '">';
if (that.imageLinkRE.test(str)) {
var tmp3 = that.imageLinkRE.exec(str)[0];
tmp3 = tmp3.substring(1, tmp3.length - 1);
ret = '<a href="' + tmp3 + '" target=_blank>' + ret + "</a>";
}
break;
case "link":
// Note: This is executed after Youtube and Vimeo test
// because this will be a valid match for them as well.
str = str.match(that.htmlRE)[0];
ret = '<iframe class="smark website" src="' + str + '" width="853" height="480" frameborder="0"></iframe>';
break;
case "paragraph":
// Typographic changes will be made if noTypo is not passed.
// Markdown style syntax will be converted as well.
str = that.parseParagraph(typoMark, str);
// Treat the source as just a paragraph of text.
ret = '<p class="smark paragraph">' + str + '</p>';
break;
default:
ret = "";
}
return ret;
}
};
module.exports = smark;
},{"./paragraph.js":2,"./regex.js":3,"./typography.js":4}],2:[function(require,module,exports){
},{"./paragraph.js":2,"./regex.js":3,"./typeIs.js":4,"./typography.js":5}],2:[function(require,module,exports){
var reg = require("./regex.js");
module.exports = function(typoMark, tmp) {
// Typographic changes will occur here before parsing into html so as not to mess up html quote marks.
tmp = this.typographicChanges(typoMark, tmp);
if (typoMark){
tmp = this.typographicChanges(tmp);
}
// Markdown style syntax will be catch and converted.

@@ -199,3 +225,3 @@ // Markdown style links

// Use $1 to return the video id
// Use $1 to return the video id
youtubeRE: /^(?:https?:\/\/)?(?:www\.)?youtu(?:\.be|be\.com)\/(?:watch|embed\/watch|embed)?[\?\/]?(?:v=|feature=player_embedded&v=)?([\w-_]+).*?$/,

@@ -213,3 +239,3 @@ vimeoRE: /^(?:https?:\/\/)?(?:www\.)?vimeo\.com\/(?:channels\/)?(?:\w+\/)?(\d+)$/,

// This will check that given link is not images while having http type protocol or end with html.
// Links that do not start with "http://" or end with ".html"
// Links that do not start with "http://" or end with ".html"
// will not be recognized to prevent some errors with iframe.

@@ -261,3 +287,3 @@ htmlRE: /^((?!.*(jpg|jpeg|gif|png|bmp))(https?:\/\/)[\w\-_]+(\.[\w\-_]+)+[\w\-.,@?^=%&:\/~\\+#]*)|.+\.(?!jpg|jpeg|gif|png|bmp)html?$/,

aposRE: /([A-Za-z]+)'([a-z]+)/g,
endashRE: /(.+)\s-\s(.+)/g,
endashRE: /(.+?)\s-\s(.+?)/g,
elipseRE: /\.{3}/g

@@ -268,3 +294,26 @@ };

},{}],4:[function(require,module,exports){
module.exports = function(enabled, tmp) {
var reg = require("./regex.js");
typeIs = function(str){
if (this.youtubeRE.test(str)) {
// Source is a Youtube link
return "youtube";
} else if (this.vimeoRE.test(str)) {
// Source is a Vimeo link
return "vimeo";
} else if (this.imageRE.test(str)) {
// Source is an image link
return "image";
} else if (this.htmlRE.test(str)) {
// Source is a general link valid for iframe
return "link";
} else {
// Source is a paragraph.
return "paragraph";
}
};
module.exports = typeIs;
},{"./regex.js":3}],5:[function(require,module,exports){
module.exports = function(tmp) {
tmp = tmp.replace(this.dQuotRE, "$1&#8220;$2&#8221;$3");

@@ -271,0 +320,0 @@ tmp = tmp.replace(this.sQuotRE, "$1&#8216;$2&#8217;$3");

/* @license smark.js written by Kenneth Lim <limzy.kenneth@gmail.com> (http://designerken.be)
License under the BSD 2-Clause License */
(function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var r;if(typeof window!=="undefined"){r=window}else if(typeof global!=="undefined"){r=global}else if(typeof self!=="undefined"){r=self}else{r=this}r.smark=e()}})(function(){var e,r,t;return function a(e,r,t){function i(s,o){if(!r[s]){if(!e[s]){var p=typeof require=="function"&&require;if(!o&&p)return p(s,!0);if(l)return l(s,!0);var n=new Error("Cannot find module '"+s+"'");throw n.code="MODULE_NOT_FOUND",n}var h=r[s]={exports:{}};e[s][0].call(h.exports,function(r){var t=e[s][1][r];return i(t?t:r)},h,h.exports,a,e,r,t)}return r[s].exports}var l=typeof require=="function"&&require;for(var s=0;s<t.length;s++)i(t[s]);return i}({1:[function(e,r,t){var a=e("./regex.js");a.options={type:"auto",typography:true};a.generate=function(e,r){var t=e;var a="";var i=this.options;for(var l in r){for(var s in i){if(l==s){i.j=r.i}}}var o=i.type;var p=i.typography;if(this.youtubeRE.test(e)){t=e.replace(this.youtubeRE,"$1");a='<iframe class="smark youtube" src="https://www.youtube.com/embed/'+t+'" frameborder="0" width="853" height="480" allowfullscreen></iframe>';if(o=="auto")o="youtube"}else if(this.vimeoRE.test(e)){t=e.replace(this.vimeoRE,"$1");a='<iframe class="smark vimeo" src="https://player.vimeo.com/video/'+t+'" frameborder="0" width="853" height="480" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';if(o=="auto")o="vimeo"}else if(this.imageRE.test(e)){tmp1=e.replace(this.imageRE,"$1");tmp2=e.replace(this.imageRE,"$2");tmp2=this.typographicChanges(true,tmp2);a='<img class="smark image" title="'+tmp2+'" src="'+tmp1+'">';if(this.imageLinkRE.test(e)){tmp3=this.imageLinkRE.exec(e)[0];tmp3=tmp3.substring(1,tmp3.length-1);a='<a href="'+tmp3+'" target=_blank>'+a+"</a>"}if(o=="auto")o="image"}else if(this.htmlRE.test(e)){t=e.match(this.htmlRE)[0];a='<iframe class="smark website" src="'+t+'" width="853" height="480" frameborder="0"></iframe>';if(o=="auto")o="link"}else{t=this.parseParagraph(p,t);a='<p class="smark paragraph">'+t+"</p>";if(o=="auto")o="paragraph"}return{html:a,type:o}};a.typographicChanges=e("./typography.js");a.parseParagraph=e("./paragraph.js");r.exports=a},{"./paragraph.js":2,"./regex.js":3,"./typography.js":4}],2:[function(e,r,t){var a=e("./regex.js");r.exports=function(e,r){r=this.typographicChanges(e,r);var t="";r=n(r);var i=r.match(a.olRE);if(i!==null){for(var l=0;l<i.length;l++){var s=i[l].match(a.olliRE);t="<ol>";for(var o=0;o<s.length;o++){t+="<li>"+s[o].replace(a.olliRE,"$1")+"</li>"}t+="</ol>";r=r.replace(i[l],t)}}var p=r.match(a.ulRE);if(p!==null){for(var l=0;l<p.length;l++){var s=p[l].match(a.ulliRE);t="<ul>";for(var o=0;o<s.length;o++){t+="<li>"+s[o].replace(a.ulliRE,"$1")+"</li>"}t+="</ul>";r=r.replace(p[l],t)}}if(a.bqRE.test(r)){if(r.replace(a.bqRE,"$2")===""){r=r.replace(a.bqRE,"<blockquote><p>$1</p></blockquote>")}else{r=r.replace(a.bqRE,"<blockquote><p>$1</p><footer>$2</footer></blockquote>")}}r=r.replace(a.h6RE,"<h6>$1</h6>");r=r.replace(a.h5RE,"<h5>$1</h5>");r=r.replace(a.h4RE,"<h4>$1</h4>");r=r.replace(a.h3RE,"<h3>$1</h3>");r=r.replace(a.h2RE,"<h2>$1</h2>");r=r.replace(a.h1RE,"<h1>$1</h1>");r=r.replace(a.hrRE,"<hr />");return r;function n(e){if(e.replace(a.linkRE,"$1")!==""){t='<a href="$2">$1</a>';if(a.linkBlankRE.test(e)){t='<a target=_blank href="$2">$1</a>'}}e=e.replace(a.linkRE,t);if(e.replace(a.linkBareRE,"$1")!==""){t='<a href="$1">$1</a>';if(a.linkBlankRE.test(e)){t='<a target=_blank href="$1">$1</a>'}}e=e.replace(a.linkBareRE,t);return e}}},{"./regex.js":3}],3:[function(e,r,t){var a={youtubeRE:/^(?:https?:\/\/)?(?:www\.)?youtu(?:\.be|be\.com)\/(?:watch|embed\/watch|embed)?[\?\/]?(?:v=|feature=player_embedded&v=)?([\w-_]+).*?$/,vimeoRE:/^(?:https?:\/\/)?(?:www\.)?vimeo\.com\/(?:channels\/)?(?:\w+\/)?(\d+)$/,imageRE:/^(?! )(.+?\.(?:jpg|jpeg|gif|png|bmp))(?: -title="(.+?)")?(?:\(.+?\))?$/,imageLinkRE:/(?:\((.+?)\)){1}/,htmlRE:/^((?!.*(jpg|jpeg|gif|png|bmp))(https?:\/\/)[\w\-_]+(\.[\w\-_]+)+[\w\-.,@?^=%&:\/~\\+#]*)|.+\.(?!jpg|jpeg|gif|png|bmp)html?$/,linkRE:/\[(?!-)(.*?)\](?:|-blank) ?\((.+?)\)/g,linkBlankRE:/\[(?!-)(.*?)\]-blank ?\((.+?)\)/g,linkBareRE:/\[(?!-)(.*?)\](?:-blank)?/g,linkBareBlankRE:/\[(?!-)(.*?)\](?:-blank)/g,olRE:/(?:\d\.\s(.+?) \| ?)+/g,olliRE:/\d\.\s(.+?) \|/g,ulRE:/(?:\*\s(.+?) \| ?)+/g,ulliRE:/\*\s(.+?) \|/g,h6RE:/\s?#{6} (.+?) #{6}\s?/g,h5RE:/\s?#{5} (.+?) #{5}\s?/g,h4RE:/\s?#{4} (.+?) #{4}\s?/g,h3RE:/\s?#{3} (.+?) #{3}\s?/g,h2RE:/\s?#{2} (.+?) #{2}\s?/g,h1RE:/\s?# (.+?) #\s?/g,hrRE:/\s?---\s?/g,bqRE:/```(.+?)(?:\[-source:\s?(.+)\])?```/g,dQuotRE:/(^|\s(?:[ \.,;:\b\[])?)\\?"(.+?)\\?"([ \.,;:\b\]])?/g,sQuotRE:/(^|\s(?:[ \.,;:\b\[])?)\\?'(.+?)\\?'([ \.,;:\b\]])?/g,volRE:/\bvol\.\s\b/gi,pRE:/\bp\.\s\b(?=\d+)/g,cRE:/\bc\.\s\b(?=\d+)/g,flRE:/\bfl\.\s\b(?=\d+)/g,ieRE:/\bi\.e\.\s?\b/g,egRE:/\be\.g\.\s\b/g,aposRE:/([A-Za-z]+)'([a-z]+)/g,endashRE:/(.+)\s-\s(.+)/g,elipseRE:/\.{3}/g};r.exports=a},{}],4:[function(e,r,t){r.exports=function(e,r){r=r.replace(this.dQuotRE,"$1&#8220;$2&#8221;$3");r=r.replace(this.sQuotRE,"$1&#8216;$2&#8217;$3");r=r.replace(this.volRE,"Vol.");r=r.replace(this.pRE,"p.");r=r.replace(this.cRE,"<i>c.</i>");r=r.replace(this.flRE,"<i>fl.</i>");r=r.replace(this.ieRE,"<i>ie</i> ");r=r.replace(this.egRE,"<i>eg</i> ");r=r.replace(this.aposRE,"$1&#8217;$2");r=r.replace(this.endashRE,"$1&#8211;$2");r=r.replace(this.elipseRE,"&#8230;");return r}},{}]},{},[1])(1)});
(function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var r;if(typeof window!=="undefined"){r=window}else if(typeof global!=="undefined"){r=global}else if(typeof self!=="undefined"){r=self}else{r=this}r.smark=e()}})(function(){var e,r,a;return function t(e,r,a){function i(s,p){if(!r[s]){if(!e[s]){var o=typeof require=="function"&&require;if(!p&&o)return o(s,!0);if(l)return l(s,!0);var n=new Error("Cannot find module '"+s+"'");throw n.code="MODULE_NOT_FOUND",n}var h=r[s]={exports:{}};e[s][0].call(h.exports,function(r){var a=e[s][1][r];return i(a?a:r)},h,h.exports,t,e,r,a)}return r[s].exports}var l=typeof require=="function"&&require;for(var s=0;s<a.length;s++)i(a[s]);return i}({1:[function(e,r,a){var t=e("./regex.js");t.typeIs=e("./typeIs.js");t.typographicChanges=e("./typography.js");t.parseParagraph=e("./paragraph.js");t.generate=function(e,r){var a="";var i={type:"auto",typography:true};for(var l in r){for(var s in i){if(l==s){i[s]=r[l]}}}var p=i.type;var o=i.typography;if(p=="auto"){if(this.typeIs(e)=="youtube"){p="youtube"}else if(this.typeIs(e)=="vimeo"){p="vimeo"}else if(this.typeIs(e)=="image"){p="image"}else if(this.typeIs(e)=="link"){p="link"}else if(this.typeIs(e)=="paragraph"){p="paragraph"}}else{p=i.type}a=n(e,p);return{html:a,type:p};function n(e,r){var a;var i=t;switch(r){case"youtube":e=e.replace(i.youtubeRE,"$1");a='<iframe class="smark youtube" src="https://www.youtube.com/embed/'+e+'" frameborder="0" width="853" height="480" allowfullscreen></iframe>';break;case"vimeo":e=e.replace(i.vimeoRE,"$1");a='<iframe class="smark vimeo" src="https://player.vimeo.com/video/'+e+'" frameborder="0" width="853" height="480" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';break;case"image":var l=e.replace(i.imageRE,"$1");var s=e.replace(i.imageRE,"$2");if(o){s=i.typographicChanges(s)}a='<img class="smark image" title="'+s+'" src="'+l+'">';if(i.imageLinkRE.test(e)){var p=i.imageLinkRE.exec(e)[0];p=p.substring(1,p.length-1);a='<a href="'+p+'" target=_blank>'+a+"</a>"}break;case"link":e=e.match(i.htmlRE)[0];a='<iframe class="smark website" src="'+e+'" width="853" height="480" frameborder="0"></iframe>';break;case"paragraph":e=i.parseParagraph(o,e);a='<p class="smark paragraph">'+e+"</p>";break;default:a=""}return a}};r.exports=t},{"./paragraph.js":2,"./regex.js":3,"./typeIs.js":4,"./typography.js":5}],2:[function(e,r,a){var t=e("./regex.js");r.exports=function(e,r){if(e){r=this.typographicChanges(r)}var a="";r=n(r);var i=r.match(t.olRE);if(i!==null){for(var l=0;l<i.length;l++){var s=i[l].match(t.olliRE);a="<ol>";for(var p=0;p<s.length;p++){a+="<li>"+s[p].replace(t.olliRE,"$1")+"</li>"}a+="</ol>";r=r.replace(i[l],a)}}var o=r.match(t.ulRE);if(o!==null){for(var l=0;l<o.length;l++){var s=o[l].match(t.ulliRE);a="<ul>";for(var p=0;p<s.length;p++){a+="<li>"+s[p].replace(t.ulliRE,"$1")+"</li>"}a+="</ul>";r=r.replace(o[l],a)}}if(t.bqRE.test(r)){if(r.replace(t.bqRE,"$2")===""){r=r.replace(t.bqRE,"<blockquote><p>$1</p></blockquote>")}else{r=r.replace(t.bqRE,"<blockquote><p>$1</p><footer>$2</footer></blockquote>")}}r=r.replace(t.h6RE,"<h6>$1</h6>");r=r.replace(t.h5RE,"<h5>$1</h5>");r=r.replace(t.h4RE,"<h4>$1</h4>");r=r.replace(t.h3RE,"<h3>$1</h3>");r=r.replace(t.h2RE,"<h2>$1</h2>");r=r.replace(t.h1RE,"<h1>$1</h1>");r=r.replace(t.hrRE,"<hr />");return r;function n(e){if(e.replace(t.linkRE,"$1")!==""){a='<a href="$2">$1</a>';if(t.linkBlankRE.test(e)){a='<a target=_blank href="$2">$1</a>'}}e=e.replace(t.linkRE,a);if(e.replace(t.linkBareRE,"$1")!==""){a='<a href="$1">$1</a>';if(t.linkBlankRE.test(e)){a='<a target=_blank href="$1">$1</a>'}}e=e.replace(t.linkBareRE,a);return e}}},{"./regex.js":3}],3:[function(e,r,a){var t={youtubeRE:/^(?:https?:\/\/)?(?:www\.)?youtu(?:\.be|be\.com)\/(?:watch|embed\/watch|embed)?[\?\/]?(?:v=|feature=player_embedded&v=)?([\w-_]+).*?$/,vimeoRE:/^(?:https?:\/\/)?(?:www\.)?vimeo\.com\/(?:channels\/)?(?:\w+\/)?(\d+)$/,imageRE:/^(?! )(.+?\.(?:jpg|jpeg|gif|png|bmp))(?: -title="(.+?)")?(?:\(.+?\))?$/,imageLinkRE:/(?:\((.+?)\)){1}/,htmlRE:/^((?!.*(jpg|jpeg|gif|png|bmp))(https?:\/\/)[\w\-_]+(\.[\w\-_]+)+[\w\-.,@?^=%&:\/~\\+#]*)|.+\.(?!jpg|jpeg|gif|png|bmp)html?$/,linkRE:/\[(?!-)(.*?)\](?:|-blank) ?\((.+?)\)/g,linkBlankRE:/\[(?!-)(.*?)\]-blank ?\((.+?)\)/g,linkBareRE:/\[(?!-)(.*?)\](?:-blank)?/g,linkBareBlankRE:/\[(?!-)(.*?)\](?:-blank)/g,olRE:/(?:\d\.\s(.+?) \| ?)+/g,olliRE:/\d\.\s(.+?) \|/g,ulRE:/(?:\*\s(.+?) \| ?)+/g,ulliRE:/\*\s(.+?) \|/g,h6RE:/\s?#{6} (.+?) #{6}\s?/g,h5RE:/\s?#{5} (.+?) #{5}\s?/g,h4RE:/\s?#{4} (.+?) #{4}\s?/g,h3RE:/\s?#{3} (.+?) #{3}\s?/g,h2RE:/\s?#{2} (.+?) #{2}\s?/g,h1RE:/\s?# (.+?) #\s?/g,hrRE:/\s?---\s?/g,bqRE:/```(.+?)(?:\[-source:\s?(.+)\])?```/g,dQuotRE:/(^|\s(?:[ \.,;:\b\[])?)\\?"(.+?)\\?"([ \.,;:\b\]])?/g,sQuotRE:/(^|\s(?:[ \.,;:\b\[])?)\\?'(.+?)\\?'([ \.,;:\b\]])?/g,volRE:/\bvol\.\s\b/gi,pRE:/\bp\.\s\b(?=\d+)/g,cRE:/\bc\.\s\b(?=\d+)/g,flRE:/\bfl\.\s\b(?=\d+)/g,ieRE:/\bi\.e\.\s?\b/g,egRE:/\be\.g\.\s\b/g,aposRE:/([A-Za-z]+)'([a-z]+)/g,endashRE:/(.+?)\s-\s(.+?)/g,elipseRE:/\.{3}/g};r.exports=t},{}],4:[function(e,r,a){var t=e("./regex.js");typeIs=function(e){if(this.youtubeRE.test(e)){return"youtube"}else if(this.vimeoRE.test(e)){return"vimeo"}else if(this.imageRE.test(e)){return"image"}else if(this.htmlRE.test(e)){return"link"}else{return"paragraph"}};r.exports=typeIs},{"./regex.js":3}],5:[function(e,r,a){r.exports=function(e){e=e.replace(this.dQuotRE,"$1&#8220;$2&#8221;$3");e=e.replace(this.sQuotRE,"$1&#8216;$2&#8217;$3");e=e.replace(this.volRE,"Vol.");e=e.replace(this.pRE,"p.");e=e.replace(this.cRE,"<i>c.</i>");e=e.replace(this.flRE,"<i>fl.</i>");e=e.replace(this.ieRE,"<i>ie</i> ");e=e.replace(this.egRE,"<i>eg</i> ");e=e.replace(this.aposRE,"$1&#8217;$2");e=e.replace(this.endashRE,"$1&#8211;$2");e=e.replace(this.elipseRE,"&#8230;");return e}},{}]},{},[1])(1)});
var smark = require("./regex.js");
// Default options
smark.options = {
"type": "auto",
"typography": true
};
// Type detection
smark.typeIs = require("./typeIs.js");
// Typographic changes will occur here before parsing into html so as not to mess up html quote marks.
smark.typographicChanges = require("./typography.js");
// Parse the string as a paragraph.
// See note.txt for more info.
smark.parseParagraph = require("./paragraph.js");
smark.generate = function(source, options) {
// Catching error in options
// if(typeof options.type !== 'string') console.warn("'type' option only accepts string.");
// if(typeof options.typography !== 'boolean') console.warn("'typopgraphy' option only accepts boolean.");
// Temporary variable to store source string for parsing
var tmp = source;
// The resulting html will be stored in this
var result = "";
// Make a copy of the global options
var opt = this.options;
// Default options
var opt = {
"type": "auto",
"typography": true
};
// Modify the options according to user passed in value

@@ -27,3 +26,3 @@ for (var i in options){

if (i == j){
opt.j = options.i;
opt[j] = options[i];
}

@@ -37,43 +36,25 @@ }

if (this.youtubeRE.test(source)) {
// Source is a Youtube link
tmp = source.replace(this.youtubeRE, "$1");
result = '<iframe class="smark youtube" src="https://www.youtube.com/embed/' + tmp + '" frameborder="0" width="853" height="480" allowfullscreen></iframe>';
if (type == 'auto') type = "youtube";
} else if (this.vimeoRE.test(source)) {
// Source is a Vimeo link
tmp = source.replace(this.vimeoRE, "$1");
result = '<iframe class="smark vimeo" src="https://player.vimeo.com/video/' + tmp + '" frameborder="0" width="853" height="480" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
if (type == 'auto') type = "vimeo";
} else if (this.imageRE.test(source)) {
// Source is an image link
tmp1 = source.replace(this.imageRE, "$1");
tmp2 = source.replace(this.imageRE, "$2");
tmp2 = this.typographicChanges(true, tmp2);
result = '<img class="smark image" title="' + tmp2 + '" src="' + tmp1 + '">';
if (this.imageLinkRE.test(source)) {
// tmp3 = source.replace(this.imageLinkRE, "$1");
tmp3 = this.imageLinkRE.exec(source)[0];
tmp3 = tmp3.substring(1, tmp3.length - 1);
result = '<a href="' + tmp3 + '" target=_blank>' + result + "</a>";
if (type == "auto"){
if (this.typeIs(source) == "youtube") {
// Source is a Youtube link
type = "youtube";
} else if (this.typeIs(source) == "vimeo") {
// Source is a Vimeo link
type = "vimeo";
} else if (this.typeIs(source) == "image") {
// Source is an image link
type = "image";
} else if (this.typeIs(source) == "link") {
// Source is a general link valid for iframe
type = "link";
} else if (this.typeIs(source) == "paragraph") {
// Parse the string as a paragraph.
type = "paragraph";
}
if (type == 'auto') type = "image";
} else if (this.htmlRE.test(source)) {
// Source is a general link valid for iframe
// Note: This is executed after Youtube and Vimeo test
// because this will be a valid match for them as well.
tmp = source.match(this.htmlRE)[0];
result = '<iframe class="smark website" src="' + tmp + '" width="853" height="480" frameborder="0"></iframe>';
if (type == 'auto') type = "link";
} else {
// Parse the string as a paragraph.
// Typographic changes will be made if noTypo is not passed.
// Markdown style syntax will be converted as well.
tmp = this.parseParagraph(typoMark, tmp);
// Treat the source as just a paragraph of text.
result = '<p class="smark paragraph">' + tmp + '</p>';
if (type == 'auto') type = "paragraph";
}else{
type = opt.type;
}
result = parse(source, type);
return {

@@ -83,12 +64,55 @@ html: result,

};
};
// parse() don't care about whether the type for str make sense or not,
// it just parse.
function parse(str, type){
var ret;
var that = smark;
switch(type){
case "youtube":
str = str.replace(that.youtubeRE, "$1");
ret = '<iframe class="smark youtube" src="https://www.youtube.com/embed/' + str + '" frameborder="0" width="853" height="480" allowfullscreen></iframe>';
break;
// Typographic changes will occur here before parsing into html so as not to mess up html quote marks.
smark.typographicChanges = require("./typography.js");
case "vimeo":
str = str.replace(that.vimeoRE, "$1");
ret = '<iframe class="smark vimeo" src="https://player.vimeo.com/video/' + str + '" frameborder="0" width="853" height="480" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
break;
// Parse the string as a paragraph.
// See note.txt for more info.
smark.parseParagraph = require("./paragraph.js");
case "image":
var tmp1 = str.replace(that.imageRE, "$1");
var tmp2 = str.replace(that.imageRE, "$2");
if (typoMark){
tmp2 = that.typographicChanges(tmp2);
}
ret = '<img class="smark image" title="' + tmp2 + '" src="' + tmp1 + '">';
if (that.imageLinkRE.test(str)) {
var tmp3 = that.imageLinkRE.exec(str)[0];
tmp3 = tmp3.substring(1, tmp3.length - 1);
ret = '<a href="' + tmp3 + '" target=_blank>' + ret + "</a>";
}
break;
case "link":
// Note: This is executed after Youtube and Vimeo test
// because this will be a valid match for them as well.
str = str.match(that.htmlRE)[0];
ret = '<iframe class="smark website" src="' + str + '" width="853" height="480" frameborder="0"></iframe>';
break;
case "paragraph":
// Typographic changes will be made if noTypo is not passed.
// Markdown style syntax will be converted as well.
str = that.parseParagraph(typoMark, str);
// Treat the source as just a paragraph of text.
ret = '<p class="smark paragraph">' + str + '</p>';
break;
default:
ret = "";
}
return ret;
}
};
module.exports = smark;
var reg = require("./regex.js");
module.exports = function(typoMark, tmp) {
// Typographic changes will occur here before parsing into html so as not to mess up html quote marks.
tmp = this.typographicChanges(typoMark, tmp);
if (typoMark){
tmp = this.typographicChanges(tmp);
}
// Markdown style syntax will be catch and converted.

@@ -8,0 +10,0 @@ // Markdown style links

@@ -5,3 +5,3 @@ var reg = {

// Use $1 to return the video id
// Use $1 to return the video id
youtubeRE: /^(?:https?:\/\/)?(?:www\.)?youtu(?:\.be|be\.com)\/(?:watch|embed\/watch|embed)?[\?\/]?(?:v=|feature=player_embedded&v=)?([\w-_]+).*?$/,

@@ -19,3 +19,3 @@ vimeoRE: /^(?:https?:\/\/)?(?:www\.)?vimeo\.com\/(?:channels\/)?(?:\w+\/)?(\d+)$/,

// This will check that given link is not images while having http type protocol or end with html.
// Links that do not start with "http://" or end with ".html"
// Links that do not start with "http://" or end with ".html"
// will not be recognized to prevent some errors with iframe.

@@ -67,3 +67,3 @@ htmlRE: /^((?!.*(jpg|jpeg|gif|png|bmp))(https?:\/\/)[\w\-_]+(\.[\w\-_]+)+[\w\-.,@?^=%&:\/~\\+#]*)|.+\.(?!jpg|jpeg|gif|png|bmp)html?$/,

aposRE: /([A-Za-z]+)'([a-z]+)/g,
endashRE: /(.+)\s-\s(.+)/g,
endashRE: /(.+?)\s-\s(.+?)/g,
elipseRE: /\.{3}/g

@@ -70,0 +70,0 @@ };

@@ -1,2 +0,2 @@

module.exports = function(enabled, tmp) {
module.exports = function(tmp) {
tmp = tmp.replace(this.dQuotRE, "$1&#8220;$2&#8221;$3");

@@ -3,0 +3,0 @@ tmp = tmp.replace(this.sQuotRE, "$1&#8216;$2&#8217;$3");

@@ -80,3 +80,3 @@ var assert = require("chai").assert;

},
{

@@ -142,3 +142,3 @@ original: "## heading 2 ##",

},
{

@@ -175,3 +175,3 @@ original: "Don't litter, you'll regret it.",

},
{

@@ -277,3 +277,3 @@ original: "Floruit, abbreviated fl. 1999, in Latin meaning 'he/she flourished'.",

for (var i=0; i<paragraphTestCases[category].length; i++){
paragraphTestCases[category][i].expected = '<p class="smark paragraph">' + paragraphTestCases[category][i].expected + "</p>";
paragraphTestCases[category][i].expectedWithP = '<p class="smark paragraph">' + paragraphTestCases[category][i].expected + "</p>";
}

@@ -285,3 +285,3 @@ }

for (var i=0; i<paragraphTestCases.links.length; i++){
assert.equal(smark.generate(paragraphTestCases.links[i].original).html, paragraphTestCases.links[i].expected);
assert.equal(smark.generate(paragraphTestCases.links[i].original).html, paragraphTestCases.links[i].expectedWithP);
}

@@ -294,3 +294,3 @@ });

for (var i=0; i<paragraphTestCases.blockquotes.length; i++){
assert.equal(smark.generate(paragraphTestCases.blockquotes[i].original).html, paragraphTestCases.blockquotes[i].expected);
assert.equal(smark.generate(paragraphTestCases.blockquotes[i].original).html, paragraphTestCases.blockquotes[i].expectedWithP);
}

@@ -303,3 +303,3 @@ });

for (var i=0; i<paragraphTestCases.lists.length; i++){
assert.equal(smark.generate(paragraphTestCases.lists[i].original).html, paragraphTestCases.lists[i].expected);
assert.equal(smark.generate(paragraphTestCases.lists[i].original).html, paragraphTestCases.lists[i].expectedWithP);
}

@@ -312,3 +312,3 @@ });

for (var i=0; i<paragraphTestCases.headings.length; i++){
assert.equal(smark.generate(paragraphTestCases.headings[i].original).html, paragraphTestCases.headings[i].expected);
assert.equal(smark.generate(paragraphTestCases.headings[i].original).html, paragraphTestCases.headings[i].expectedWithP);
}

@@ -321,3 +321,3 @@ });

for (var i=0; i<paragraphTestCases.horizontalRules.length; i++){
assert.equal(smark.generate(paragraphTestCases.horizontalRules[i].original).html, paragraphTestCases.horizontalRules[i].expected);
assert.equal(smark.generate(paragraphTestCases.horizontalRules[i].original).html, paragraphTestCases.horizontalRules[i].expectedWithP);
}

@@ -331,6 +331,8 @@ });

it("should be coverted if it means between two things", function(){
assert.equal(smark.generate(paragraphTestCases.ndash[0].original).html, paragraphTestCases.ndash[0].expected);
assert.equal(smark.generate(paragraphTestCases.ndash[0].original).html, paragraphTestCases.ndash[0].expectedWithP);
assert.equal(smark.typographicChanges(paragraphTestCases.ndash[0].original), paragraphTestCases.ndash[0].expected);
});
it("should not be coverted if it link words together", function(){
assert.equal(smark.generate(paragraphTestCases.ndash[1].original).html, paragraphTestCases.ndash[1].expected);
assert.equal(smark.generate(paragraphTestCases.ndash[1].original).html, paragraphTestCases.ndash[1].expectedWithP);
assert.equal(smark.typographicChanges(paragraphTestCases.ndash[1].original), paragraphTestCases.ndash[1].expected);
});

@@ -342,3 +344,4 @@ });

for (var i=0; i<paragraphTestCases.quotemarks.length; i++){
assert.equal(smark.generate(paragraphTestCases.quotemarks[i].original).html, paragraphTestCases.quotemarks[i].expected);
assert.equal(smark.generate(paragraphTestCases.quotemarks[i].original).html, paragraphTestCases.quotemarks[i].expectedWithP);
assert.equal(smark.typographicChanges(paragraphTestCases.quotemarks[i].original), paragraphTestCases.quotemarks[i].expected);
}

@@ -351,3 +354,4 @@ });

for (var i=0; i<paragraphTestCases.apostrophes.length; i++){
assert.equal(smark.generate(paragraphTestCases.apostrophes[i].original).html, paragraphTestCases.apostrophes[i].expected);
assert.equal(smark.generate(paragraphTestCases.apostrophes[i].original).html, paragraphTestCases.apostrophes[i].expectedWithP);
assert.equal(smark.typographicChanges(paragraphTestCases.apostrophes[i].original), paragraphTestCases.apostrophes[i].expected);
}

@@ -360,3 +364,4 @@ });

for (var i=0; i<paragraphTestCases.ellipses.length; i++){
assert.equal(smark.generate(paragraphTestCases.ellipses[i].original).html, paragraphTestCases.ellipses[i].expected);
assert.equal(smark.generate(paragraphTestCases.ellipses[i].original).html, paragraphTestCases.ellipses[i].expectedWithP);
assert.equal(smark.typographicChanges(paragraphTestCases.ellipses[i].original), paragraphTestCases.ellipses[i].expected);
}

@@ -369,3 +374,4 @@ });

for (var i=0; i<paragraphTestCases.concatenations.length; i++){
assert.equal(smark.generate(paragraphTestCases.concatenations[i].original).html, paragraphTestCases.concatenations[i].expected);
assert.equal(smark.generate(paragraphTestCases.concatenations[i].original).html, paragraphTestCases.concatenations[i].expectedWithP);
assert.equal(smark.typographicChanges(paragraphTestCases.concatenations[i].original), paragraphTestCases.concatenations[i].expected);
}

@@ -372,0 +378,0 @@ });

@@ -80,3 +80,3 @@ var assert = require("chai").assert;

},
{

@@ -124,2 +124,7 @@ original: "## heading 2 ##",

expected: "Jean-Charles, chevalier de Borda"
},
{
original: "Melancholy graphic design student expired in 2016 who makes love and art to postpone her suicide. Taipei - Kaohsiung - London, \"the eternal flight of myself from myself\".",
expected: "Melancholy graphic design student expired in 2016 who makes love and art to postpone her suicide. Taipei&#8211;Kaohsiung&#8211;London, &#8220;the eternal flight of myself from myself&#8221;."
}

@@ -143,3 +148,3 @@ ],

},
{

@@ -176,3 +181,3 @@ original: "Don't litter, you'll regret it.",

},
{

@@ -278,3 +283,3 @@ original: "Floruit, abbreviated fl. 1999, in Latin meaning 'he/she flourished'.",

for (var i=0; i<paragraphTestCases[category].length; i++){
paragraphTestCases[category][i].expected = '<p class="smark paragraph">' + paragraphTestCases[category][i].expected + "</p>";
paragraphTestCases[category][i].expectedWithP = '<p class="smark paragraph">' + paragraphTestCases[category][i].expected + "</p>";
}

@@ -286,3 +291,3 @@ }

for (var i=0; i<paragraphTestCases.links.length; i++){
assert.equal(smark.generate(paragraphTestCases.links[i].original).html, paragraphTestCases.links[i].expected);
assert.equal(smark.generate(paragraphTestCases.links[i].original).html, paragraphTestCases.links[i].expectedWithP);
}

@@ -295,3 +300,3 @@ });

for (var i=0; i<paragraphTestCases.blockquotes.length; i++){
assert.equal(smark.generate(paragraphTestCases.blockquotes[i].original).html, paragraphTestCases.blockquotes[i].expected);
assert.equal(smark.generate(paragraphTestCases.blockquotes[i].original).html, paragraphTestCases.blockquotes[i].expectedWithP);
}

@@ -304,3 +309,3 @@ });

for (var i=0; i<paragraphTestCases.lists.length; i++){
assert.equal(smark.generate(paragraphTestCases.lists[i].original).html, paragraphTestCases.lists[i].expected);
assert.equal(smark.generate(paragraphTestCases.lists[i].original).html, paragraphTestCases.lists[i].expectedWithP);
}

@@ -313,3 +318,3 @@ });

for (var i=0; i<paragraphTestCases.headings.length; i++){
assert.equal(smark.generate(paragraphTestCases.headings[i].original).html, paragraphTestCases.headings[i].expected);
assert.equal(smark.generate(paragraphTestCases.headings[i].original).html, paragraphTestCases.headings[i].expectedWithP);
}

@@ -322,3 +327,3 @@ });

for (var i=0; i<paragraphTestCases.horizontalRules.length; i++){
assert.equal(smark.generate(paragraphTestCases.horizontalRules[i].original).html, paragraphTestCases.horizontalRules[i].expected);
assert.equal(smark.generate(paragraphTestCases.horizontalRules[i].original).html, paragraphTestCases.horizontalRules[i].expectedWithP);
}

@@ -332,6 +337,8 @@ });

it("should be coverted if it means between two things", function(){
assert.equal(smark.generate(paragraphTestCases.ndash[0].original).html, paragraphTestCases.ndash[0].expected);
assert.equal(smark.generate(paragraphTestCases.ndash[0].original).html, paragraphTestCases.ndash[0].expectedWithP);
assert.equal(smark.typographicChanges(paragraphTestCases.ndash[0].original), paragraphTestCases.ndash[0].expected);
});
it("should not be coverted if it link words together", function(){
assert.equal(smark.generate(paragraphTestCases.ndash[1].original).html, paragraphTestCases.ndash[1].expected);
assert.equal(smark.generate(paragraphTestCases.ndash[1].original).html, paragraphTestCases.ndash[1].expectedWithP);
assert.equal(smark.typographicChanges(paragraphTestCases.ndash[1].original), paragraphTestCases.ndash[1].expected);
});

@@ -343,3 +350,4 @@ });

for (var i=0; i<paragraphTestCases.quotemarks.length; i++){
assert.equal(smark.generate(paragraphTestCases.quotemarks[i].original).html, paragraphTestCases.quotemarks[i].expected);
assert.equal(smark.generate(paragraphTestCases.quotemarks[i].original).html, paragraphTestCases.quotemarks[i].expectedWithP);
assert.equal(smark.typographicChanges(paragraphTestCases.quotemarks[i].original), paragraphTestCases.quotemarks[i].expected);
}

@@ -352,3 +360,4 @@ });

for (var i=0; i<paragraphTestCases.apostrophes.length; i++){
assert.equal(smark.generate(paragraphTestCases.apostrophes[i].original).html, paragraphTestCases.apostrophes[i].expected);
assert.equal(smark.generate(paragraphTestCases.apostrophes[i].original).html, paragraphTestCases.apostrophes[i].expectedWithP);
assert.equal(smark.typographicChanges(paragraphTestCases.apostrophes[i].original), paragraphTestCases.apostrophes[i].expected);
}

@@ -361,3 +370,4 @@ });

for (var i=0; i<paragraphTestCases.ellipses.length; i++){
assert.equal(smark.generate(paragraphTestCases.ellipses[i].original).html, paragraphTestCases.ellipses[i].expected);
assert.equal(smark.generate(paragraphTestCases.ellipses[i].original).html, paragraphTestCases.ellipses[i].expectedWithP);
assert.equal(smark.typographicChanges(paragraphTestCases.ellipses[i].original), paragraphTestCases.ellipses[i].expected);
}

@@ -370,3 +380,4 @@ });

for (var i=0; i<paragraphTestCases.concatenations.length; i++){
assert.equal(smark.generate(paragraphTestCases.concatenations[i].original).html, paragraphTestCases.concatenations[i].expected);
assert.equal(smark.generate(paragraphTestCases.concatenations[i].original).html, paragraphTestCases.concatenations[i].expectedWithP);
assert.equal(smark.typographicChanges(paragraphTestCases.concatenations[i].original), paragraphTestCases.concatenations[i].expected);
}

@@ -454,3 +465,3 @@ });

for (var i=0; i<embededTestCases.link.length; i++){
assert.equal(smark.generate(embededTestCases.link[i].original, {type: "link"}).type, "link");
assert.equal(smark.generate(embededTestCases.youtube[i].original, {type: "link"}).type, "link");
}

@@ -457,0 +468,0 @@ });

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