Skip to content

Commit 2ad4510

Browse files
committed
Merge remote-tracking branch 'upstream/master' into dependabot/npm_and_yarn/chai-5.1.2
2 parents 5d8d250 + 9d42f9e commit 2ad4510

File tree

6 files changed

+39
-37
lines changed

6 files changed

+39
-37
lines changed

.github/workflows/linter.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ jobs:
66
linter:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v2
10-
- name: Use Node.js 14.x
9+
- uses: actions/checkout@v4
10+
- name: Use Node.js 22
1111
uses: actions/setup-node@v4
1212
with:
13-
node-version: "14.x"
13+
node-version: "22"
1414
- name: Cache NPM dependencies
1515
uses: actions/cache@v4
1616
with:

.github/workflows/tester.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ jobs:
88
strategy:
99
matrix:
1010
os: [ubuntu-latest, windows-latest, macos-latest]
11-
node-version: ["14.x", "16.x", "18.x"]
12-
exclude:
13-
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/running-variations-of-jobs-in-a-workflow#excluding-matrix-configurations
14-
- os: macos-latest
15-
node-version: 14.x
11+
node-version: ["18", "20", "22"]
1612
fail-fast: false
1713
steps:
18-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v4
1915
- name: Use Node.js ${{ matrix.node-version }}
2016
uses: actions/setup-node@v4
2117
with:
@@ -38,9 +34,9 @@ jobs:
3834
strategy:
3935
matrix:
4036
os: [ubuntu-latest]
41-
node-version: ["14.x"]
37+
node-version: ["22"]
4238
steps:
43-
- uses: actions/checkout@v2
39+
- uses: actions/checkout@v4
4440
- name: Use Node.js ${{ matrix.node-version }}
4541
uses: actions/setup-node@v4
4642
with:

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# hexo-renderer-marked
22

3-
[![Build Status](https://github.com/hexojs/hexo-renderer-marked/workflows/Tester/badge.svg?branch=master)](https://github.com/hexojs/hexo-renderer-marked/actions?query=workflow%3ATester)
3+
[![Tester](https://github.com/hexojs/hexo-renderer-marked/actions/workflows/tester.yml/badge.svg?branch=master)](https://github.com/hexojs/hexo-renderer-marked/actions/workflows/tester.yml)
44
[![NPM version](https://badge.fury.io/js/hexo-renderer-marked.svg)](https://www.npmjs.com/package/hexo-renderer-marked)
55
[![Coverage Status](https://img.shields.io/coveralls/hexojs/hexo-renderer-marked.svg)](https://coveralls.io/r/hexojs/hexo-renderer-marked?branch=master)
66
[![NPM Dependencies](https://img.shields.io/librariesio/release/npm/hexo-renderer-marked.svg)](https://libraries.io/npm/hexo-renderer-marked)
@@ -20,7 +20,7 @@ There are two solutions to avoid those issues:
2020

2121
## Installation
2222

23-
``` bash
23+
```bash
2424
$ npm install hexo-renderer-marked --save
2525
```
2626

@@ -32,7 +32,7 @@ $ npm install hexo-renderer-marked --save
3232

3333
You can configure this plugin in `_config.yml`.
3434

35-
``` yaml
35+
```yml
3636
marked:
3737
gfm: true
3838
pedantic: false
@@ -83,7 +83,7 @@ marked:
8383
- **figcaption** - Append `figcaption` element after each image.
8484
- **prependRoot** - Prepend root value to (internal) image path.
8585
* Example `_config.yml`:
86-
``` yml
86+
```yml
8787
root: /blog/
8888
```
8989
* `![text](/path/to/image.jpg)` becomes `<img src="/blog/path/to/image.jpg" alt="text">`
@@ -112,7 +112,7 @@ For more options, see [Marked](https://marked.js.org/using_advanced#options). Du
112112

113113
To enable it, pass an object containing the DOMPurify options:
114114

115-
```json
115+
```yml
116116
dompurify: true
117117
```
118118

@@ -173,10 +173,11 @@ This plugin overrides some default behaviours of how [marked] plugin renders the
173173

174174
For example, to override how heading like `# heading text` is rendered:
175175

176-
``` js
176+
```js
177177
hexo.extend.filter.register('marked:renderer', function(renderer) {
178178
const { config } = this; // Skip this line if you don't need user config from _config.yml
179-
renderer.heading = function(text, level) {
179+
renderer.heading = function({ tokens, depth: level }) {
180+
const text = this.parser.parseInline(tokens);
180181
// Default behaviour
181182
// return `<h${level}>${text}</h${level}>`;
182183
// outputs <h1>heading text</h1>
@@ -196,7 +197,7 @@ Notice `renderer.heading = function (text, level) {` corresponds to [this line](
196197

197198
It is also possible to customize the [tokenizer](https://marked.js.org/using_pro#tokenizer).
198199

199-
``` js
200+
```js
200201
const { escapeHTML: escape } = require('hexo-util');
201202

202203
// https://github.com/markedjs/marked/blob/b6773fca412c339e0cedd56b63f9fa1583cfd372/src/Lexer.js#L8-L24

lib/renderer.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ function mangleEmail(text) {
3333

3434
const renderer = {
3535
// Add id attribute to headings
36-
heading(text, level) {
36+
heading({ tokens, depth: level }) {
37+
let text = this.parser.parseInline(tokens);
3738
const { anchorAlias, headerIds, modifyAnchors, _headingId } = this.options;
3839

3940
if (!headerIds) {
@@ -67,7 +68,8 @@ const renderer = {
6768
return `<h${level} id="${id}"><a href="#${id}" class="headerlink" title="${stripHTML(text)}"></a>${text}</h${level}>`;
6869
},
6970

70-
link(href, title, text) {
71+
link({ tokens, href, title }) {
72+
const text = this.parser.parseInline(tokens);
7173
const { external_link, sanitizeUrl, hexo, mangle } = this.options;
7274
const { url: urlCfg } = hexo.config;
7375

@@ -96,7 +98,7 @@ const renderer = {
9698
out += '"';
9799

98100
if (title) {
99-
out += ` title="${title}"`;
101+
out += ` title="${escape(title)}"`;
100102
}
101103
if (external_link) {
102104
const target = ' target="_blank"';
@@ -118,7 +120,8 @@ const renderer = {
118120
},
119121

120122
// Support Basic Description Lists
121-
paragraph(text) {
123+
paragraph({ tokens }) {
124+
const text = this.parser.parseInline(tokens);
122125
const { descriptionLists = true } = this.options;
123126

124127
if (descriptionLists) {
@@ -131,7 +134,7 @@ const renderer = {
131134
},
132135

133136
// Prepend root to image path
134-
image(href, title, text) {
137+
image({ href, title, text }) {
135138
const { options } = this;
136139
const { hexo } = options;
137140
const { relative_link } = hexo.config;
@@ -149,8 +152,8 @@ const renderer = {
149152
}
150153

151154
let out = `<img src="${encodeURL(href)}"`;
152-
if (text) out += ` alt="${text}"`;
153-
if (title) out += ` title="${title}"`;
155+
if (text) out += ` alt="${escape(text)}"`;
156+
if (title) out += ` title="${escape(title)}"`;
154157
if (lazyload) out += ' loading="lazy"';
155158

156159
out += '>';
@@ -185,7 +188,7 @@ const smartypants = (str, quotes) => {
185188
};
186189

187190
const tokenizer = {
188-
// Support AutoLink option
191+
// Support autolink option
189192
url(src) {
190193
const { autolink } = this.options;
191194

@@ -225,7 +228,7 @@ module.exports = function(data, options) {
225228
// exec filter to extend marked
226229
this.execFilterSync('marked:use', marked.use, { context: this });
227230

228-
// exec filter to extend renderer.
231+
// exec filter to extend renderer
229232
this.execFilterSync('marked:renderer', renderer, { context: this });
230233

231234
// exec filter to extend tokenizer

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hexo-renderer-marked",
3-
"version": "6.3.0",
3+
"version": "7.0.0",
44
"description": "Markdown renderer plugin for Hexo",
55
"main": "index",
66
"scripts": {
@@ -33,18 +33,18 @@
3333
"dependencies": {
3434
"dompurify": "^3.0.3",
3535
"hexo-util": "^3.1.0",
36-
"jsdom": "^20.0.1",
37-
"marked": "^12.0.1"
36+
"jsdom": "^25.0.1",
37+
"marked": "^15.0.4"
3838
},
3939
"devDependencies": {
40-
"c8": "^8.0.0",
40+
"c8": "^10.1.2",
4141
"chai": "^5.1.2",
4242
"eslint": "^8.57.0",
4343
"eslint-config-hexo": "^5.0.0",
4444
"hexo": "^7.1.1",
45-
"mocha": "^10.4.0"
45+
"mocha": "^11.0.1"
4646
},
4747
"engines": {
48-
"node": ">=14"
48+
"node": ">=18"
4949
}
5050
}

test/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -901,12 +901,15 @@ describe('Marked renderer', () => {
901901
});
902902

903903
describe('exec filter to extend', () => {
904+
// Clear the cache, as the filter might permanently modify the tokenizer
905+
// thereby affecting other test cases
906+
delete require.cache[require.resolve('../lib/renderer')];
904907
const hexo = new Hexo(__dirname, {silent: true});
905908
hexo.config.marked = {};
906909

907910
it('should execute filter registered to marked:renderer', () => {
908911
hexo.extend.filter.register('marked:renderer', renderer => {
909-
renderer.image = function(href, title, text) {
912+
renderer.image = function({ href }) {
910913
return `<img data-src="${encodeURL(href)}">`;
911914
};
912915
});
@@ -949,7 +952,7 @@ describe('Marked renderer', () => {
949952
const r = require('../lib/renderer').bind(hexo);
950953

951954
const result = r({text: body});
952-
result.should.eql(`<p>${smartypants(body)}</p>\n`);
955+
result.should.eql(`<p>${escapeHTML(smartypants(body))}</p>\n`);
953956
});
954957

955958
it('should execute filter registered to marked:extensions', () => {
@@ -1042,6 +1045,5 @@ describe('Marked renderer', () => {
10421045
'<p><a href="http://hexo.io/">Hexo</a></p>\n'
10431046
].join(''));
10441047
});
1045-
10461048
});
10471049
});

0 commit comments

Comments
 (0)