Skip to content

Commit 154f841

Browse files
authored
Merge pull request #57 from pxgrid/upgrade-marked-v17
marked を v7.0.5 から v17.0.5 に更新
2 parents 1191154 + 7d3a400 commit 154f841

6 files changed

Lines changed: 26 additions & 40 deletions

File tree

index.d.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,11 @@ export default class CodeGridMarkdown {
77
* Options for CodeGridMarkdown.
88
*
99
* Basically the same as MarkedOptions.
10-
* `renderer` and `headerIds` are used internally and cannot be overridden.
10+
* `renderer` is used internally and cannot be overridden.
1111
*
1212
* See also https://marked.js.org/using_advanced#options
1313
*/
1414
export interface CodeGridMarkdownOptions {
15-
/**
16-
* A prefix URL for any relative link.
17-
*/
18-
baseUrl?: string;
19-
2015
/**
2116
* Enable GFM line breaks. This option requires the gfm option to be true.
2217
*/
@@ -27,11 +22,6 @@ export interface CodeGridMarkdownOptions {
2722
*/
2823
gfm?: boolean;
2924

30-
/**
31-
* Set the prefix for header tag ids.
32-
*/
33-
headerPrefix?: string;
34-
3525
/**
3626
* Conform to obscure parts of markdown.pl as much as possible. Don't fix any of the original markdown bugs or poor behavior.
3727
*/
@@ -41,14 +31,4 @@ export interface CodeGridMarkdownOptions {
4131
* Shows an HTML error message when rendering fails.
4232
*/
4333
silent?: boolean;
44-
45-
/**
46-
* Use "smart" typographic punctuation for things like quotes and dashes.
47-
*/
48-
smartypants?: boolean;
49-
50-
/**
51-
* Generate closing slash for self-closing tags (<br/> instead of <br>)
52-
*/
53-
xhtml?: boolean;
5434
}

lib/renderer/md.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ class MDRenderer {
2020
this.options = options;
2121

2222
this.options.renderer = new marked.Renderer();
23-
// markedのアップデートで初期値が変わったもの
24-
this.options.headerIds = '';
2523

2624
Object.keys(renderFunc).forEach((key) => {
2725
this.options.renderer[key] = renderFunc[key];

lib/renderer/md/code.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,29 @@ const renderLivecodeSection = (title, codeHtml) => `
2323
* ```html#たいとる 言語指定とタイトル指定 ```
2424
* みたいにすると、拡張したやつでレンダリングして返す
2525
*
26-
* @param {string} code
27-
* @param {string} lang
28-
* @param {string} escaped
26+
* @param {object} token
27+
* marked v17 のコードトークン ({type, raw, lang, text})
2928
* @return {string}
3029
* HTML文字列
3130
*
3231
*/
33-
export default function(code, lang, escaped) {
32+
export default function(token) {
33+
const { lang } = token;
34+
3435
// そもそも言語指定ないやつ
3536
if (!lang) {
36-
return origCodeRender.apply(this, [code, lang, escaped]);
37+
return origCodeRender.call(this, token);
3738
}
3839

3940
const langArr = lang.split('#').map((t) => t.trim());
4041
// 言語の指定はあったが、タイトルがない = 今まで通り
4142
if (langArr.length === 1 || langArr[1].length === 0) {
42-
return origCodeRender.apply(this, [code, langArr[0], escaped]);
43+
return origCodeRender.call(this, { ...token, lang: langArr[0] });
4344
}
4445

4546
// 言語の指定もタイトル指定もちゃんとあるやつ
4647
return renderLivecodeSection(
4748
langArr[1], // タイトル
48-
origCodeRender.apply(this, [code, langArr[0], escaped]) // コード本体
49+
origCodeRender.call(this, { ...token, lang: langArr[0] }) // コード本体
4950
);
5051
}

package-lock.json

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"dependencies": {
2020
"cheerio": "^1.2.0",
21-
"marked": "7.0.5"
21+
"marked": "^17.0.5"
2222
},
2323
"devDependencies": {
2424
"@power-assert/node": "^0.6.0"

test/cgmd/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ describe('CodeGridMarkdown', function() {
77

88
describe('#constructor', function() {
99
it('markedにオプションが渡せる', function() {
10-
const original = '<img>';
11-
const expect = '<p>&lt;img&gt;</p>\n';
10+
const original = 'line1\nline2';
11+
const withBreaks = '<p>line1<br>line2</p>\n';
12+
const withoutBreaks = '<p>line1\nline2</p>\n';
1213

13-
const cgmd = new CodeGridMarkdown({ sanitize: true });
14-
assert(cgmd.render(original) === expect);
14+
const cgmd = new CodeGridMarkdown({ breaks: true });
15+
assert(cgmd.render(original) === withBreaks);
16+
17+
const cgmdDefault = new CodeGridMarkdown();
18+
assert(cgmdDefault.render(original) === withoutBreaks);
1519
});
1620
});
1721

0 commit comments

Comments
 (0)