markup-builder
Advanced tools
Comparing version 2.0.0 to 3.1.0
@@ -29,3 +29,2 @@ module.exports = { | ||
globals: { | ||
requirejs: false, | ||
}, | ||
@@ -32,0 +31,0 @@ parserOptions: { |
'use strict'; | ||
const sanitizeHtml = require('sanitize-html'); | ||
const DomParser = require('dom-parser'); | ||
const Remarkable = require('remarkable'); | ||
var xss = require('xss'); | ||
var DomParser = require('dom-parser'); | ||
var Remarkable = require('remarkable'); | ||
var mtools = require('markup-tools'); | ||
module.exports = { | ||
//export dependencies | ||
sanitizeHtml: sanitizeHtml, | ||
xss: xss, | ||
DomParser: DomParser, | ||
Remarkable: Remarkable | ||
Remarkable: Remarkable, | ||
mtools: mtools | ||
}; |
'use strict'; | ||
const img = require('./parsers/img.js'); | ||
const txt = require('./parsers/txt.js'); | ||
const build = require('./builders/build.js'); | ||
const dep = require('./dependencies.js'); | ||
module.exports = {img, txt, dep}; | ||
module.exports = {build, dep}; |
{ | ||
"name": "markup-builder", | ||
"version": "2.0.0", | ||
"version": "3.1.0", | ||
"description": "Markup and HTML builder tools", | ||
@@ -12,4 +12,4 @@ "main": "./lib/index.js", | ||
"lintstaged": "./node_modules/.bin/lint-staged", | ||
"test": "npm run lintfix", | ||
"build": "npm run lintfix && webpack" | ||
"test": "npm run lintfix && node ./node_modules/mocha/bin/mocha --exit", | ||
"build": "npm run test && webpack" | ||
}, | ||
@@ -33,6 +33,6 @@ "repository": { | ||
"dependencies": { | ||
"@babel/runtime": "^7.1.2", | ||
"dom-parser": "^0.1.5", | ||
"markup-tools": "^2.7.0", | ||
"remarkable": "^1.7.1", | ||
"sanitize-html": "^1.19.1" | ||
"xss": "^1.0.3" | ||
}, | ||
@@ -46,6 +46,3 @@ "lint-staged": { | ||
"devDependencies": { | ||
"@babel/core": "^7.1.2", | ||
"@babel/plugin-transform-runtime": "^7.1.0", | ||
"@babel/preset-env": "^7.1.0", | ||
"babel-loader": "^8.0.4", | ||
"chai": "^4.2.0", | ||
"eslint": "^5.6.1", | ||
@@ -55,5 +52,5 @@ "eslint-plugin-react": "^7.11.1", | ||
"lint-staged": "^7.3.0", | ||
"mocha": "^5.2.0", | ||
"prettier": "^1.14.3", | ||
"pretty-quick": "^1.7.0", | ||
"uglifyjs-webpack-plugin": "^2.0.1", | ||
"webpack": "^4.12.0", | ||
@@ -60,0 +57,0 @@ "webpack-cli": "^3.0.3" |
139
README.md
@@ -7,3 +7,3 @@ [![Pull requests](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg)](https://github.com/peerquery/markup-builder/pulls) | ||
# Markup Builder | ||
Markdown and HTML markup building tools. | ||
Markdown and HTML markup building tools. Built on [XSS](https://www.npmjs.com/package/xss), [Remarkable](https://www.npmjs.com/package/remarkable), [DOMParser](https://www.npmjs.com/package/dom-parser) and [Markup tools](https://www.npmjs.com/package/markup-tools). | ||
@@ -33,3 +33,3 @@ ## Installation | ||
### Text tools | ||
`markup.txt` comes with 5 functions: | ||
`markup.build` comes with 5 functions: | ||
@@ -41,56 +41,49 @@ ```javascript | ||
```javascript | ||
//options object the configurations for the 'sanitize-html' module | ||
//Find out more: https://github.com/punkave/sanitize-html#what-are-the-default-options | ||
const options = { | ||
allowedTags: [ 'h3', 'h4', 'h5', 'h6', 'blockquote', 'p', 'a', 'ul', 'ol', | ||
'nl', 'li', 'b', 'i', 'strong', 'em', 'strike', 'code', 'hr', 'br', 'div', | ||
'table', 'thead', 'caption', 'tbody', 'tr', 'th', 'td', 'pre', 'iframe' ], | ||
allowedAttributes: { | ||
a: [ 'href', 'name', 'target' ], | ||
// We don't currently allow img itself by default, but this | ||
// would make sense if we did | ||
img: [ 'src' ] | ||
}, | ||
// Lots of these won't come up by default because we don't allow them | ||
selfClosing: [ 'img', 'br', 'hr', 'area', 'base', 'basefont', 'input', 'link', 'meta' ], | ||
// URL schemes we permit | ||
allowedSchemes: [ 'http', 'https', 'ftp', 'mailto' ], | ||
allowedSchemesByTag: {}, | ||
allowedSchemesAppliedToAttributes: [ 'href', 'src', 'cite' ], | ||
allowProtocolRelative: true, | ||
allowedIframeHostnames: ['www.youtube.com', 'player.vimeo.com'] | ||
//options object the configurations for the 'xss' module | ||
//Find out more: https://www.npmjs.com/package/xss#custom-filter-rules | ||
const | ||
// only tag a and its attributes href, title, target are allowed | ||
var options = { | ||
whiteList: { | ||
a: ["href", "title", "target"] | ||
} | ||
}; | ||
// With the configuration specified above, the following HTML: | ||
// <a href="#" onclick="hello()"><i>Hello</i></a> | ||
// would become: | ||
// <a href="#">Hello</a> | ||
``` | ||
#### `markup.txt.text(text, options);` | ||
#### `markup.build.text(text, options);` | ||
Returns the text version of a `markdown` or `HTML` string input; | ||
`options` is optional configurations object for `sanitize-html`. | ||
`options` is optional configurations object for `xss`. | ||
```javascript | ||
var text = markup.txt.text(t, options); | ||
var text = markup.build.text(t, options); | ||
console.log(text); | ||
// " Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum @sociis natoque #penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, https://www.youtube.com/watch?v=sO_YEdTcVXc https://travis-ci.org/peerquery/markup-builder" | ||
// " Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum @sociis natoque #penatibus et magnis dis parturient montes,<script>alert(\'Quisque rutrum.\')</script> nascetur ridiculus mus. Donec quam felis, https://www.youtube.com/watch?v=sO_YEdTcVXc https://travis-ci.org/peerquery/markup-builder\n " | ||
``` | ||
#### `markup.txt.html(text, options);` | ||
#### `markup.build.html(text, options);` | ||
Returns the html version of a `markdown` or `HTML` string input; | ||
`options` is optional configurations object for `sanitize-html`. | ||
`options` is optional configurations object for `xss`. | ||
```javascript | ||
//inside async function | ||
var html = await markup.txt.html(t, options); | ||
var html = await markup.build.html(t, options); | ||
console.log(html); | ||
//With promise API | ||
markup.txt.html(t).then(function(html, options){ | ||
markup.build.html(t).then(function(html, options){ | ||
console.log(html); | ||
}); | ||
// "<p><strong>Lorem ipsum dolor sit amet</strong>, consectetuer adipiscing elit. Aenean <i>commodo ligula eget</i> dolor. Aenean massa. Cum @sociis natoque #penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, https://www.youtube.com/watch?v=sO_YEdTcVXc https://travis-ci.org/peerquery/markup-builder</p>" | ||
// "<p><strong>Lorem ipsum dolor sit amet</strong>, consectetuer adipiscing elit. Aenean <i>commodo ligula eget</i> dolor. Aenean massa. Cum @sociis natoque #penatibus et magnis dis parturient montes,<script>alert(\'Quisque rutrum.\')</script> nascetur ridiculus mus. Donec quam felis, https://www.youtube.com/watch?v=sO_YEdTcVXc https://travis-ci.org/peerquery/markup-builder</p>\n" | ||
``` | ||
#### `markup.txt.summary(text, count, options);` | ||
#### `markup.build.summary(text, count, options);` | ||
Returns the text version of a `markdown` or `HTML` string input, trimmed to `count` or a default of 160 characters; | ||
@@ -100,7 +93,7 @@ | ||
//inside async function | ||
var summary = await markup.txt.summary(t/* , options */); | ||
var summary = await markup.build.summary(t/* , options */); | ||
console.log(summary); | ||
//With promise API | ||
markup.txt.summary(t).then(function(summary/* , options */){ | ||
markup.build.summary(t).then(function(summary/* , options */){ | ||
console.log(summary); | ||
@@ -112,12 +105,12 @@ }); | ||
#### `markup.txt.content(text, options, sane);` | ||
#### `markup.build.content(text, config, options);` | ||
Returns the full html version of a `markdown` or `HTML` string input; parsing hashtag, mentions, naked image links and naked youtube link. | ||
```javascript | ||
var options = {}; | ||
options.video = true; //default: true | ||
options.account_scheme = '/@'; //default is: '/user' | ||
options.hashtag_scheme = '/trends'; //default: '/trending' | ||
var config = {}; | ||
config.video = true; //default: true | ||
config.account_scheme = '/@'; //default is: '/user' | ||
config.hashtag_scheme = '/trends'; //default: '/trending' | ||
//'sane' object is sanitize-html configurations | ||
//'options' object is xss configurations | ||
``` | ||
@@ -127,72 +120,32 @@ Example: | ||
//inside async function | ||
var content = await markup.txt.content(t, options ); //with about options object | ||
var content = await markup.build.content(t /*,config, options*/ ); //with about options object | ||
console.log(content); | ||
// "<p><strong>Lorem ipsum dolor sit amet</strong>, consectetuer adipiscing elit. Aenean <i>commodo ligula eget</i> dolor. Aenean massa. Cum <a target="_blank" href="/@/sociis">@sociis</a> natoque <a target="_blank" href="/trends/penatibus "> #penatibus </a> et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis,<iframe width="640" height="360" src="https://www.youtube.com/embed/sO_YEdTcVXc" frameborder="0" allowfullscreen></iframe> <a href="https://travis-ci.org/peerquery/markup-builder">https://travis-ci.org/peerquery/markup-builder</p></a>↵" | ||
//With promise API | ||
markup.txt.content(t/*, options */).then(function(content){ //options is optional, using defaults | ||
markup.build.content(t /*,config, options*/).then(function(content){ //options is optional, using defaults | ||
console.log(content); | ||
}); | ||
// "<p><strong>Lorem ipsum dolor sit amet</strong>, consectetuer adipiscing elit. Aenean <i>commodo ligula eget</i> dolor. Aenean massa. Cum <a target="_blank" href="/user/sociis">@sociis</a> natoque <a target="_blank" href="/trending/penatibus "> #penatibus </a> et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis,<iframe width="640" height="360" src="https://www.youtube.com/embed/sO_YEdTcVXc" frameborder="0" allowfullscreen></iframe> <a href="https://travis-ci.org/peerquery/markup-builder">https://travis-ci.org/peerquery/markup-builder</p></a>↵" | ||
// "<p><strong>Lorem ipsum dolor sit amet</strong>, consectetuer adipiscing elit. Aenean <i>commodo ligula eget</i> dolor. Aenean massa. Cum <a target="_blank" href="/user/sociis">@sociis</a> natoque <a target="_blank" href="/trending/penatibus "> #penatibus </a> et magnis dis parturient montes,<script>alert(\'Quisque rutrum.\')</script> nascetur ridiculus mus. Donec quam felis, <a href="https://www.youtube.com/watch?v=sO_YEdTcVXc">https://www.youtube.com/watch?v=sO_YEdTcVXc</a> <a href="https://travis-ci.org/peerquery/markup-builder">https://travis-ci.org/peerquery/markup-builder</p></a>\n" | ||
``` | ||
#### `markup.txt.sanitize(text, options);` | ||
#### `markup.build.sanitize(text, options);` | ||
Returns the sanitized version of the input string; | ||
`options` is optional configurations object for `sanitize-html` and can be either `true` || `false`. Default is `true` | ||
`options` is optional configurations object for `xss` and can be either `true` || `false`. Default is `true` | ||
```javascript | ||
//inside async function | ||
var clean = await markup.txt.sanitize(t/* , options */); | ||
var clean = await markup.build.sanitize(t/* , options */); | ||
console.log(clean); | ||
//With promise API | ||
markup.txt.sanitize(t/* , options */).then(function(clean){ | ||
markup.build.sanitize(t/* , options */).then(function(clean){ | ||
console.log(clean); | ||
}); | ||
// "**Lorem ipsum dolor sit amet**, consectetuer adipiscing elit. Aenean <i>commodo ligula eget</i> dolor. Aenean massa. Cum @sociis natoque #penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, https://www.youtube.com/watch?v=sO_YEdTcVXc https://travis-ci.org/peerquery/markup-builder" | ||
// "**Lorem ipsum dolor sit amet**, consectetuer adipiscing elit. Aenean <i>commodo ligula eget</i> dolor. Aenean massa. Cum @sociis natoque #penatibus et magnis dis parturient montes,<script>alert(\'Quisque rutrum.\')</script> nascetur ridiculus mus. Donec quam felis, https://www.youtube.com/watch?v=sO_YEdTcVXc https://travis-ci.org/peerquery/markup-builder" | ||
``` | ||
### Image tools | ||
`markup.img.get(text, number, ext)` | ||
**With argument** | ||
```javascript | ||
const markup = require('markup-builder'); | ||
var post = ' www.image1.png http://www.image2.jpg www.image3.svg www.image4.png http://www.image5.jpg www.image6.svg'; | ||
//Image type supports a trailing '.' to the extension | ||
markup.img.get(post, 2, '.png'); | ||
//is the same as | ||
markup.img.get(post, 2, 'png'); | ||
//Examples | ||
console.log(markup.img.get(post, null, 'jpg')); | ||
//'http://www.image2.jpg' | ||
console.log(markup.img.get(post, 1, '.png')); | ||
//'www.image4.png' | ||
console.log(markup.img.get(post, 0, 'svg')); | ||
//'www.image3.svg' | ||
console.log(markup.img.get(post, 1, '.svg')); | ||
//'www.image6.svg' | ||
``` | ||
**Without argument** | ||
`var thumbnail = markup.img.get(post);` | ||
Th will return the first image `jpe?g|bmp|svg|png|gif|tif|tiff` from the `post` string. | ||
### Dependencies | ||
@@ -204,11 +157,9 @@ | ||
const remarkable = markup.dep.Remarkable; | ||
const sanitize = markup.dep.sanitizeHtml; | ||
const xss = markup.dep.xss; | ||
const domparser = markup.dep.DomParser; | ||
const mtools = markup.dep.mtools | ||
``` | ||
## Known issues | ||
Bundling with webpack may cause some non-breaking warning notifications on `different casting types`. This is caused by the `sanitize-html` module, but does not have invalidate or break the build. | ||
## Contributions | ||
Are welcome, particularly for enabling support for parsing content from *IPFS, DTube and other video sites*. | ||
Are welcome. |
const path = require('path'); | ||
const webpack = require('webpack'); | ||
const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); | ||
@@ -17,14 +16,3 @@ module.exports = { | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(js)$/, | ||
use: 'babel-loader', | ||
}, | ||
], | ||
}, | ||
optimization: { | ||
minimizer: [new UglifyJsPlugin()] | ||
}, | ||
mode: 'production', | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
10
142089
16
439
159
+ Addedmarkup-tools@^2.7.0
+ Addedxss@^1.0.3
+ Addedcommander@2.20.3(transitive)
+ Addedcssfilter@0.0.10(transitive)
+ Addedmarkup-tools@2.10.0(transitive)
+ Addedxss@1.0.15(transitive)
- Removed@babel/runtime@^7.1.2
- Removedsanitize-html@^1.19.1
- Removed@babel/runtime@7.26.7(transitive)
- Removeddom-serializer@1.4.1(transitive)
- Removeddomelementtype@2.3.0(transitive)
- Removeddomhandler@3.3.04.3.1(transitive)
- Removeddomutils@2.8.0(transitive)
- Removedentities@2.2.0(transitive)
- Removedhtmlparser2@4.1.0(transitive)
- Removedlodash@4.17.21(transitive)
- Removedparse-srcset@1.0.2(transitive)
- Removedpicocolors@0.2.1(transitive)
- Removedpostcss@7.0.39(transitive)
- Removedregenerator-runtime@0.14.1(transitive)
- Removedsanitize-html@1.27.5(transitive)