From 0a27699364e0a47ad6ba4618b5a9a35107fe4ce0 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 23 Feb 2017 16:15:05 +0100 Subject: [PATCH] Update for remark@7.0.0 --- index.js | 21 ++++++--------------- package.json | 25 +++++++++++-------------- readme.md | 4 ++-- test/index.js | 35 ++++++++++++++++++----------------- 4 files changed, 37 insertions(+), 48 deletions(-) diff --git a/index.js b/index.js index d361012..70362df 100644 --- a/index.js +++ b/index.js @@ -7,31 +7,22 @@ var sanitize = require('hast-util-sanitize'); module.exports = plugin; -function plugin(processor, options) { +function plugin(options) { var settings = options || {}; var clean = settings.sanitize; var schema = clean && typeof clean === 'object' ? clean : null; var handlers = settings.handlers || {}; - Compiler.prototype.compile = compile; + this.Compiler = compiler; - processor.Compiler = Compiler; - - function Compiler(file) { - /* istanbul ignore if - vfile@1.0.0 */ - if (file.extension) { - file.move({extension: 'html'}); - } + function compiler(node, file) { + var root = node && node.type && node.type === 'root'; + var hast = toHAST(node, {allowDangerousHTML: !clean, handlers: handlers}); + var result; if (file.extname) { file.extname = '.html'; } - } - - function compile(node) { - var root = node && node.type && node.type === 'root'; - var hast = toHAST(node, {allowDangerousHTML: !clean, handlers: handlers}); - var result; if (clean) { hast = sanitize(hast, schema); diff --git a/package.json b/package.json index d9573aa..25f9245 100644 --- a/package.json +++ b/package.json @@ -10,16 +10,7 @@ "compile", "remark" ], - "dependencies": { - "hast-util-sanitize": "^1.0.0", - "hast-util-to-html": "^3.0.0", - "mdast-util-to-hast": "^2.1.1", - "xtend": "^4.0.1" - }, - "repository": { - "type": "git", - "url": "https://github.com/wooorm/remark-html.git" - }, + "repository": "https://github.com/wooorm/remark-html", "bugs": "https://github.com/wooorm/remark-html/issues", "author": "Titus Wormer (http://wooorm.com)", "contributors": [ @@ -28,23 +19,29 @@ "files": [ "index.js" ], + "dependencies": { + "hast-util-sanitize": "^1.0.0", + "hast-util-to-html": "^3.0.0", + "mdast-util-to-hast": "^2.1.1", + "xtend": "^4.0.1" + }, "devDependencies": { "browserify": "^14.0.0", "commonmark.json": "^0.27.0", "esmangle": "^1.0.0", "is-hidden": "^1.0.1", "nyc": "^10.0.0", - "remark": "^6.0.0", + "remark": "^7.0.0", "remark-cli": "^2.0.0", - "remark-github": "^6.0.1", + "remark-github": "^7.0.0", "remark-preset-wooorm": "^1.0.0", - "remark-toc": "^3.1.0", + "remark-toc": "^4.0.0", "tape": "^4.0.0", "to-vfile": "^2.0.0", "xo": "^0.17.1" }, "scripts": { - "build-md": "remark *.md doc/*.md --quiet --frail", + "build-md": "# remark *.md doc/*.md --quiet --frail", "build-bundle": "browserify index.js --bare -s remarkHTML > remark-html.js", "build-mangle": "esmangle remark-html.js > remark-html.min.js", "build": "npm run build-md && npm run build-bundle && npm run build-mangle", diff --git a/readme.md b/readme.md index 09906e1..5503992 100644 --- a/readme.md +++ b/readme.md @@ -16,7 +16,7 @@ npm install remark-html var remark = require('remark'); var html = require('remark-html'); -var file = remark().use(html).process([ +var file = remark().use(html).processSync([ '# Hello & World', '', '**Alpha**, _bravo_, and ~~Charlie~~.' @@ -60,7 +60,7 @@ var github = require('hast-util-sanitize/lib/github'); var schema = merge(github, {attributes: {'*': ['className']}}); -remark().use(html, {sanitize: schema}).process(/*...*/); +remark().use(html, {sanitize: schema}).processSync(/*...*/); ``` ## CommonMark diff --git a/test/index.js b/test/index.js index c5744c3..2f85ee3 100644 --- a/test/index.js +++ b/test/index.js @@ -118,7 +118,7 @@ test('remark-html()', function (t) { t.equal(typeof html, 'function', 'should be a function'); t.doesNotThrow(function () { - html(remark()); + html.call(remark()); }, 'should not throw if not passed options'); t.throws( @@ -178,7 +178,7 @@ test('remark-html()', function (t) { }}); t.equal( - processor.process('paragraph text').toString(), + processor.processSync('paragraph text').toString(), '

changed

\n', 'should allow overriding handlers' ); @@ -194,7 +194,7 @@ test('remark-html()', function (t) { .use(html); t.equal( - processor.process('![hello](example.jpg "overwritten")').toString(), + processor.processSync('![hello](example.jpg "overwritten")').toString(), '

hello

\n', 'should patch and merge attributes' ); @@ -208,7 +208,7 @@ test('remark-html()', function (t) { .use(html); t.equal( - processor.process('**Bold!**').toString(), + processor.processSync('**Bold!**').toString(), '

Bold!

\n', 'should overwrite a tag-name' ); @@ -231,7 +231,7 @@ test('remark-html()', function (t) { .use(html); t.equal( - processor.process('`var`').toString(), + processor.processSync('`var`').toString(), '

var

\n', 'should overwrite content' ); @@ -254,7 +254,7 @@ test('remark-html()', function (t) { .use(html, {sanitize: true}); t.equal( - processor.process('`var`').toString(), + processor.processSync('`var`').toString(), '

var

\n', 'should not overwrite content in `sanitize` mode' ); @@ -270,13 +270,13 @@ test('remark-html()', function (t) { .use(html); t.equal( - processor.process('```js\nvar\n```\n').toString(), + processor.processSync('```js\nvar\n```\n').toString(), '
var\n
\n', 'should overwrite classes on code' ); t.equal( - remark().use(html).process('## Hello world').toString(), + remark().use(html).processSync('## Hello world').toString(), '

Hello world

\n', 'should be `sanitation: false` by default' ); @@ -284,7 +284,7 @@ test('remark-html()', function (t) { t.equal( remark().use(html, { sanitize: true - }).process('## Hello world').toString(), + }).processSync('## Hello world').toString(), '

Hello world

\n', 'should support sanitation: true' ); @@ -292,7 +292,7 @@ test('remark-html()', function (t) { t.equal( remark().use(html, { sanitize: null - }).process('## Hello world').toString(), + }).processSync('## Hello world').toString(), '

Hello world

\n', 'should support sanitation: null' ); @@ -300,7 +300,7 @@ test('remark-html()', function (t) { t.equal( remark().use(html, { sanitize: false - }).process('## Hello world').toString(), + }).processSync('## Hello world').toString(), '

Hello world

\n', 'should support sanitation: false' ); @@ -308,7 +308,7 @@ test('remark-html()', function (t) { t.equal( remark().use(html, { sanitize: {tagNames: []} - }).process('## Hello world').toString(), + }).processSync('## Hello world').toString(), 'Hello world\n', 'should support sanitation schemas' ); @@ -329,7 +329,7 @@ test('Fixtures', function (t) { file.contents = input; config = exists(config) ? JSON.parse(read(config, 'utf-8')) : {}; - result = process(file, config); + result = processSync(file, config); t.equal(result, output, 'should work on `' + fixture + '`'); }); @@ -347,7 +347,7 @@ test('CommonMark', function (t) { var exception; file.contents = test.markdown; - result = process(file, CMARK_OPTIONS); + result = processSync(file, CMARK_OPTIONS); n += 1; @@ -389,9 +389,10 @@ test('Integrations', function (t) { config.sanitize = false; result = remark() + .data('settings', config) .use(html, config) .use(INTEGRATION_MAP[integration], config) - .process(file, config) + .processSync(file) .toString(); t.equal(result, output, 'should work on `' + integration + '`'); @@ -400,6 +401,6 @@ test('Integrations', function (t) { t.end(); }); -function process(file, config) { - return remark().use(html, config).process(file, config).toString(); +function processSync(file, config) { + return remark().data('settings', config).use(html, config).processSync(file).toString(); }