Skip to content

Commit

Permalink
Update for [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Feb 23, 2017
1 parent 86d4e75 commit aa0d3ee
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 82 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var toString = require('hast-util-to-string');

module.exports = attacher;

function attacher(origin, options) {
function attacher(options) {
var settings = options || {};
var detect = settings.subset !== false;
var prefix = settings.prefix;
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
"browserify": "^14.1.0",
"esmangle": "^1.0.1",
"nyc": "^10.0.0",
"rehype": "^3.0.0",
"remark-cli": "^2.1.0",
"remark-preset-wooorm": "^1.0.0",
"rehype": "^4.0.0",
"remark-cli": "^3.0.0",
"remark-preset-wooorm": "^2.0.0",
"tape": "^4.0.0",
"unist-util-inspect": "^4.0.0",
"xo": "^0.17.1"
Expand Down Expand Up @@ -58,6 +58,6 @@
]
},
"remarkConfig": {
"presets": "wooorm"
"plugins": ["preset-wooorm"]
}
}
15 changes: 9 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ npm install rehype-highlight
var rehype = require('rehype');
var highlight = require('rehype-highlight');

var file = rehype().use(highlight).process([
'<h1>Hello World!</h1>',
'',
'<pre><code class="language-js">var name = "World";',
'console.warn("Hello, " + name + "!")</code></pre>'
].join('\n'), {fragment: true});
var file = rehype()
.data('settings', {fragment: true})
.use(highlight)
.processSync([
'<h1>Hello World!</h1>',
'',
'<pre><code class="language-js">var name = "World";',
'console.warn("Hello, " + name + "!")</code></pre>'
].join('\n'));

console.log(String(file));
```
Expand Down
194 changes: 123 additions & 71 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ var highlight = require('./index.js');

test('highlight()', function (t) {
t.equal(
rehype().use(highlight).process([
'<h1>Hello World!</h1>',
'',
'<pre><code></code></pre>'
].join('\n'), {fragment: true}).toString(),
rehype()
.data('settings', {fragment: true})
.use(highlight)
.processSync([
'<h1>Hello World!</h1>',
'',
'<pre><code></code></pre>'
].join('\n'))
.toString(),
[
'<h1>Hello World!</h1>',
'',
Expand All @@ -20,11 +24,15 @@ test('highlight()', function (t) {
);

t.equal(
rehype().use(highlight).process([
'<h1>Hello World!</h1>',
'',
'<pre><code>"use strict";</code></pre>'
].join('\n'), {fragment: true}).toString(),
rehype()
.data('settings', {fragment: true})
.use(highlight)
.processSync([
'<h1>Hello World!</h1>',
'',
'<pre><code>"use strict";</code></pre>'
].join('\n'))
.toString(),
[
'<h1>Hello World!</h1>',
'',
Expand All @@ -34,11 +42,15 @@ test('highlight()', function (t) {
);

t.equal(
rehype().use(highlight, {subset: ['applescript']}).process([
'<h1>Hello World!</h1>',
'',
'<pre><code>"use strict";</code></pre>'
].join('\n'), {fragment: true}).toString(),
rehype()
.data('settings', {fragment: true})
.use(highlight, {subset: ['applescript']})
.processSync([
'<h1>Hello World!</h1>',
'',
'<pre><code>"use strict";</code></pre>'
].join('\n'))
.toString(),
[
'<h1>Hello World!</h1>',
'',
Expand All @@ -48,11 +60,15 @@ test('highlight()', function (t) {
);

t.equal(
rehype().use(highlight, {subset: false}).process([
'<h1>Hello World!</h1>',
'',
'<pre><code>"use strict";</code></pre>'
].join('\n'), {fragment: true}).toString(),
rehype()
.data('settings', {fragment: true})
.use(highlight, {subset: false})
.processSync([
'<h1>Hello World!</h1>',
'',
'<pre><code>"use strict";</code></pre>'
].join('\n'))
.toString(),
[
'<h1>Hello World!</h1>',
'',
Expand All @@ -62,11 +78,15 @@ test('highlight()', function (t) {
);

t.equal(
rehype().use(highlight, {prefix: 'foo'}).process([
'<h1>Hello World!</h1>',
'',
'<pre><code>"use strict";</code></pre>'
].join('\n'), {fragment: true}).toString(),
rehype()
.data('settings', {fragment: true})
.use(highlight, {prefix: 'foo'})
.processSync([
'<h1>Hello World!</h1>',
'',
'<pre><code>"use strict";</code></pre>'
].join('\n'))
.toString(),
[
'<h1>Hello World!</h1>',
'',
Expand All @@ -76,11 +96,15 @@ test('highlight()', function (t) {
);

t.equal(
rehype().use(highlight, {prefix: 'foo-'}).process([
'<h1>Hello World!</h1>',
'',
'<pre><code>"use strict";</code></pre>'
].join('\n'), {fragment: true}).toString(),
rehype()
.data('settings', {fragment: true})
.use(highlight, {prefix: 'foo-'})
.processSync([
'<h1>Hello World!</h1>',
'',
'<pre><code>"use strict";</code></pre>'
].join('\n'))
.toString(),
[
'<h1>Hello World!</h1>',
'',
Expand All @@ -90,12 +114,16 @@ test('highlight()', function (t) {
);

t.equal(
rehype().use(highlight).process([
'<h1>Hello World!</h1>',
'',
'<pre><code class="lang-js">var name = "World";',
'console.log("Hello, " + name + "!")</code></pre>'
].join('\n'), {fragment: true}).toString(),
rehype()
.data('settings', {fragment: true})
.use(highlight)
.processSync([
'<h1>Hello World!</h1>',
'',
'<pre><code class="lang-js">var name = "World";',
'console.log("Hello, " + name + "!")</code></pre>'
].join('\n'))
.toString(),
[
'<h1>Hello World!</h1>',
'',
Expand All @@ -106,12 +134,16 @@ test('highlight()', function (t) {
);

t.equal(
rehype().use(highlight).process([
'<h1>Hello World!</h1>',
'',
'<pre><code class="language-js">var name = "World";',
'console.log("Hello, " + name + "!")</code></pre>'
].join('\n'), {fragment: true}).toString(),
rehype()
.data('settings', {fragment: true})
.use(highlight)
.processSync([
'<h1>Hello World!</h1>',
'',
'<pre><code class="language-js">var name = "World";',
'console.log("Hello, " + name + "!")</code></pre>'
].join('\n'))
.toString(),
[
'<h1>Hello World!</h1>',
'',
Expand All @@ -122,12 +154,16 @@ test('highlight()', function (t) {
);

t.equal(
rehype().use(highlight).process([
'<h1>Hello World!</h1>',
'',
'<pre><code class="language-javascript">var name = "World";',
'console.log("Hello, " + name + "!")</code></pre>'
].join('\n'), {fragment: true}).toString(),
rehype()
.data('settings', {fragment: true})
.use(highlight)
.processSync([
'<h1>Hello World!</h1>',
'',
'<pre><code class="language-javascript">var name = "World";',
'console.log("Hello, " + name + "!")</code></pre>'
].join('\n'))
.toString(),
[
'<h1>Hello World!</h1>',
'',
Expand All @@ -138,12 +174,16 @@ test('highlight()', function (t) {
);

t.equal(
rehype().use(highlight).process([
'<h1>Hello World!</h1>',
'',
'<pre><code class="no-highlight">var name = "World";',
'console.log("Hello, " + name + "!")</code></pre>'
].join('\n'), {fragment: true}).toString(),
rehype()
.data('settings', {fragment: true})
.use(highlight)
.processSync([
'<h1>Hello World!</h1>',
'',
'<pre><code class="no-highlight">var name = "World";',
'console.log("Hello, " + name + "!")</code></pre>'
].join('\n'))
.toString(),
[
'<h1>Hello World!</h1>',
'',
Expand All @@ -154,12 +194,16 @@ test('highlight()', function (t) {
);

t.equal(
rehype().use(highlight).process([
'<h1>Hello World!</h1>',
'',
'<pre><code class="nohighlight">var name = "World";',
'console.log("Hello, " + name + "!")</code></pre>'
].join('\n'), {fragment: true}).toString(),
rehype()
.data('settings', {fragment: true})
.use(highlight)
.processSync([
'<h1>Hello World!</h1>',
'',
'<pre><code class="nohighlight">var name = "World";',
'console.log("Hello, " + name + "!")</code></pre>'
].join('\n'))
.toString(),
[
'<h1>Hello World!</h1>',
'',
Expand All @@ -170,12 +214,16 @@ test('highlight()', function (t) {
);

t.equal(
rehype().use(highlight).process([
'<h1>Hello World!</h1>',
'',
'<pre><code class="hljs lang-js"><span class="hljs-keyword">var</span> name = <span class="hljs-string">"World"</span>;',
'<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Hello, "</span> + name + <span class="hljs-string">"!"</span>)</code></pre>'
].join('\n'), {fragment: true}).toString(),
rehype()
.data('settings', {fragment: true})
.use(highlight)
.processSync([
'<h1>Hello World!</h1>',
'',
'<pre><code class="hljs lang-js"><span class="hljs-keyword">var</span> name = <span class="hljs-string">"World"</span>;',
'<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Hello, "</span> + name + <span class="hljs-string">"!"</span>)</code></pre>'
].join('\n'))
.toString(),
[
'<h1>Hello World!</h1>',
'',
Expand All @@ -186,11 +234,15 @@ test('highlight()', function (t) {
);

t.equal(
rehype().use(highlight).process([
'<h1>Hello World!</h1>',
'',
'<pre><code><!--TODO-->"use strict";</code></pre>'
].join('\n'), {fragment: true}).toString(),
rehype()
.data('settings', {fragment: true})
.use(highlight)
.processSync([
'<h1>Hello World!</h1>',
'',
'<pre><code><!--TODO-->"use strict";</code></pre>'
].join('\n'))
.toString(),
[
'<h1>Hello World!</h1>',
'',
Expand Down

0 comments on commit aa0d3ee

Please sign in to comment.