Skip to content

Commit

Permalink
fix(deps): update dependency rehype to v13 (#1639)
Browse files Browse the repository at this point in the history
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Zbynek Konecny <[email protected]>
  • Loading branch information
renovate[bot] and zbynek authored Oct 12, 2024
1 parent abbfdbe commit fb3ee2a
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 108 deletions.
20 changes: 10 additions & 10 deletions plugins/gatsby-rehype-autolink-headers/__tests__/index.test.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Rehype from 'rehype';
import {rehype} from 'rehype';
import {toHtml} from 'hast-util-to-html';

import pluginFunc from '../index.mjs';

import {describe, expect, it} from '@jest/globals';

describe('handler', () => {
const rehype = new Rehype().data('settings', {
const rehypeParser = new rehype().data('settings', {
fragment: true,
space: 'html',
emitParseErrors: false,
Expand All @@ -15,39 +15,39 @@ describe('handler', () => {

it('bare h1s should get styles and stuff', async () => {
const options = {};
const htmlAst = await rehype.parse('<div><h1>something</h1></div>');
const htmlAst = await rehypeParser.parse('<div><h1>something</h1></div>');
const updatedHtmlAst = pluginFunc({htmlAst}, options);
expect(toHtml(updatedHtmlAst)).toEqual('<div><h1 id="something" style="position: relative"><a href="#something" aria-label="something permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>something</h1></div>');
});
it('existing attributes should be respected', async () => {
const options = {};
const htmlAst = await rehype.parse('<h2 dir="auto">About this plugin</h2>');
const htmlAst = await rehypeParser.parse('<h2 dir="auto">About this plugin</h2>');
const updatedHtmlAst = pluginFunc({htmlAst}, options);
expect(toHtml(updatedHtmlAst)).toEqual('<h2 dir="auto" id="about-this-plugin" style="position: relative"><a href="#about-this-plugin" aria-label="about this plugin permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>About this plugin</h2>');
});
it('existing styles should be respected', async () => {
const options = {};
const htmlAst = await rehype.parse('<h2 dir="auto" style="color: red">About this plugin</h2>');
const htmlAst = await rehypeParser.parse('<h2 dir="auto" style="color: red">About this plugin</h2>');
const updatedHtmlAst = pluginFunc({htmlAst}, options);
expect(toHtml(updatedHtmlAst)).toEqual('<h2 dir="auto" style="color: red; position: relative" id="about-this-plugin"><a href="#about-this-plugin" aria-label="about this plugin permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>About this plugin</h2>');
});
it('after', async () => {
const options = {
isIconAfterHeader: true,
};
const htmlAst = await rehype.parse('<h2 dir="auto" style="color: red">About this plugin</h2>');
const htmlAst = await rehypeParser.parse('<h2 dir="auto" style="color: red">About this plugin</h2>');
const updatedHtmlAst = pluginFunc({htmlAst}, options);
expect(toHtml(updatedHtmlAst)).toEqual('<h2 dir="auto" style="color: red; position: relative" id="about-this-plugin">About this plugin<a href="#about-this-plugin" aria-label="about this plugin permalink" class="anchor after"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a></h2>');
});
it('slugs should be stripped', async () => {
const options = {};
const htmlAst = await rehype.parse('<h1>\n \nsomething\n \n</h1>');
const htmlAst = await rehypeParser.parse('<h1>\n \nsomething\n \n</h1>');
const updatedHtmlAst = pluginFunc({htmlAst}, options);
expect(toHtml(updatedHtmlAst)).toEqual('<h1 id="something" style="position: relative"><a href="#something" aria-label="something permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>\n \nsomething\n \n</h1>');
});
it('prepend id', async () => {
const options = {prependId: 'plugin-content-'};
const htmlAst = await rehype.parse('<h1>something</h1>');
const htmlAst = await rehypeParser.parse('<h1>something</h1>');
const updatedHtmlAst = pluginFunc({htmlAst}, options);
expect(toHtml(updatedHtmlAst)).toEqual('<h1 id="plugin-content-something" style="position: relative"><a href="#plugin-content-something" aria-label="something permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>something</h1>');
});
Expand All @@ -56,15 +56,15 @@ describe('handler', () => {
const options = {
elements: ['h2'],
};
const htmlAst = await rehype.parse('<h2 dir="auto" style="color: red">About this plugin</h2>');
const htmlAst = await rehypeParser.parse('<h2 dir="auto" style="color: red">About this plugin</h2>');
const updatedHtmlAst = pluginFunc({htmlAst}, options);
expect(toHtml(updatedHtmlAst)).toEqual('<h2 dir="auto" style="color: red; position: relative" id="about-this-plugin"><a href="#about-this-plugin" aria-label="about this plugin permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>About this plugin</h2>');
});
it('exclude element', async () => {
const options = {
elements: ['h1'],
};
const htmlAst = await rehype.parse('<h2 dir="auto" style="color: red">About this plugin</h2>');
const htmlAst = await rehypeParser.parse('<h2 dir="auto" style="color: red">About this plugin</h2>');
const updatedHtmlAst = pluginFunc({htmlAst}, options);
expect(toHtml(updatedHtmlAst)).toEqual('<h2 dir="auto" style="color: red">About this plugin</h2>');
});
Expand Down
6 changes: 3 additions & 3 deletions plugins/gatsby-rehype-autolink-headers/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import toString from 'hast-util-to-string';
import visit from 'unist-util-visit';
import slugger from 'github-slugger';
import _ from 'lodash';
import Rehype from 'rehype';
import {rehype} from 'rehype';
import styleToObject from 'style-to-object';

const slugs = slugger();
Expand All @@ -19,7 +19,7 @@ const pluginDefaults = {
elements: null,
};

const rehype = new Rehype().data('settings', {
const rehypeParser = new rehype().data('settings', {
fragment: true,
space: 'html',
emitParseErrors: false,
Expand Down Expand Up @@ -76,7 +76,7 @@ export default ({htmlAst}, pluginOptions) => {
const styles = styleToObject(node.properties.style || '') || {};
styles.position = 'relative';
node.properties.style = Object.entries(styles).map(i => `${i[0]}: ${i[1]}`).join('; ');
node.children[method](rehype.parse(`<a href="#${id}" aria-label="${label} permalink" class="${className} ${isIconAfterHeader ? 'after' : 'before'}">${icon}</a>`));
node.children[method](rehypeParser.parse(`<a href="#${id}" aria-label="${label} permalink" class="${className} ${isIconAfterHeader ? 'after' : 'before'}">${icon}</a>`));
}
};
visit(htmlAst, node => node?.tagName?.match(/^h\d+$/), visitNode);
Expand Down
6 changes: 3 additions & 3 deletions plugins/gatsby-rehype-rewrite-ids/__tests__/index.test.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Rehype from 'rehype';
import {rehype} from 'rehype';
import {toHtml} from 'hast-util-to-html';

import pluginFunc from '../index.mjs';

import {describe, expect, it} from '@jest/globals';

describe('handler', () => {
const rehype = new Rehype().data('settings', {
const rehypeParser = new rehype().data('settings', {
fragment: true,
space: 'html',
emitParseErrors: false,
Expand All @@ -17,7 +17,7 @@ describe('handler', () => {
const options = {
prefix: 'plugin_content_',
};
const htmlAst = await rehype.parse('<div><a href="#place_one">Place One</a><h1 id="place_one">something</h1></div>');
const htmlAst = await rehypeParser.parse('<div><a href="#place_one">Place One</a><h1 id="place_one">something</h1></div>');
const updatedHtmlAst = pluginFunc({htmlAst}, options);
expect(toHtml(updatedHtmlAst)).toEqual('<div><a href="#plugin_content_place_one">Place One</a><h1 id="plugin_content_place_one">something</h1></div>');
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import Rehype from 'rehype';
import {rehype} from 'rehype';
import {toHtml} from 'hast-util-to-html';

import pluginFunc from '../index.mjs';

import {describe, expect, it} from '@jest/globals';

describe('handler', () => {
const rehype = new Rehype().data('settings', {
const rehypeParser = new rehype().data('settings', {
fragment: true,
space: 'html',
emitParseErrors: false,
verbose: false,
}); // Load language extension if defined

it('should rewrite relative urls', async () => {
const htmlAst = await rehype.parse('<img src="foo/bar.jpg" />');
const htmlAst = await rehypeParser.parse('<img src="foo/bar.jpg" />');
const htmlNode = {
context: {
url: 'http://example.com/subdir/readme.md'
Expand All @@ -26,7 +26,7 @@ describe('handler', () => {
});

it('should not touch absolute urls urls', async () => {
const htmlAst = await rehype.parse('<img src="https://google.com/subdir/foo/bar.jpg" />');
const htmlAst = await rehypeParser.parse('<img src="https://google.com/subdir/foo/bar.jpg" />');
const htmlNode = {
context: {
url: 'http://example.com/subdir/readme.md'
Expand Down
2 changes: 1 addition & 1 deletion plugins/gatsby-rehype-rewrite-img-src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"eslint": "9.12.0",
"hast-util-to-html": "9.0.3",
"jest": "29.7.0",
"rehype": "11.0.0"
"rehype": "13.0.2"
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Rehype from 'rehype';
import {rehype} from 'rehype';
import {toHtml} from 'hast-util-to-html';

import pluginFunc from '../index.mjs';

import {describe, expect, it} from '@jest/globals';

describe('handler', () => {
const rehype = new Rehype().data('settings', {
const rehypeParser = new rehype().data('settings', {
fragment: true,
space: 'html',
emitParseErrors: false,
Expand All @@ -17,13 +17,13 @@ describe('handler', () => {
return pluginFunc({
htmlAst,
compiler: {
parseString: rehype.parse.bind(rehype)
parseString: rehypeParser.parse.bind(rehypeParser)
}
});
};

it('basic test', async () => {
const htmlAst = await rehype.parse('<div><table><tr><td>col 1</td></tr></table></div>');
const htmlAst = await rehypeParser.parse('<div><table><tr><td>col 1</td></tr></table></div>');
const updatedHtmlAst = runPluginFunc(htmlAst);

expect(toHtml(updatedHtmlAst)).toBe('<div><div class="table-responsive"><table class="table table-bordered"><tbody><tr><td>col 1</td></tr></tbody></table></div></div>');
Expand Down
2 changes: 1 addition & 1 deletion plugins/gatsby-rehype-wrap-tables-bootstrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"eslint": "9.12.0",
"hast-util-to-html": "9.0.3",
"jest": "29.7.0",
"rehype": "11.0.0"
"rehype": "13.0.2"
}
}
2 changes: 1 addition & 1 deletion plugins/gatsby-transformer-rehype/extend-node-type.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'lodash';
import Rehype from 'rehype';
import {rehype as Rehype} from 'rehype';
import stripPosition from 'unist-util-remove-position';
import hastReparseRaw from 'hast-util-raw';
import visit from 'unist-util-visit';
Expand Down
2 changes: 1 addition & 1 deletion plugins/gatsby-transformer-rehype/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@babel/runtime": "7.25.7",
"hast-util-raw": "^6.0.2",
"lodash": "^4.17.21",
"rehype": "^11.0.0",
"rehype": "^13.0.0",
"unist-util-remove-position": "^3.0.0",
"unist-util-visit": "^2.0.3"
},
Expand Down
Loading

0 comments on commit fb3ee2a

Please sign in to comment.