Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

markedパッケージのバージョンを1.0.0から最新の4.0.10へ更新 #1380

Merged
merged 3 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions source/use-case/nodecli/md-to-html/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ JavaScriptでMarkdownをHTMLへ変換するために、今回は[marked][]とい
markedのパッケージはnpmで配布されているので、commanderと同様に`npm install`コマンドでパッケージをインストールしましょう。

```shell
$ npm install marked@1.0.0
$ npm install marked@4.0.10
```

インストールが完了したら、Node.jsのスクリプトから読み込みます。
前のセクションの最後で書いたスクリプトに、markedパッケージの読み込み処理を追加しましょう。
次のように`main.js`を変更し、読み込んだMarkdownファイルをmarkedを使ってHTMLに変換します。
markedパッケージをインポートした`marked`関数は、Markdown文字列を引数にとり、HTML文字列に変換して返します。
markedパッケージをインポートした`marked.parse`関数は、Markdown文字列を引数にとり、HTML文字列に変換して返します。

[import title:"main.js"](src/main-1.js)

Expand Down Expand Up @@ -114,7 +114,7 @@ const cliOptions = {
};
```

こうして作成した`cliOptions`オブジェクトから、markedにオプションを渡しましょう
こうして作成したcliOptionsオブジェクトを、markedの`parse`関数へオプションとして渡しましょう。 main.jsの全体は次のようになります
`main.js`の全体は次のようになります。

[import title:"main.js"](src/main-3.js)
Expand Down
2 changes: 1 addition & 1 deletion source/use-case/nodecli/md-to-html/src/main-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ fs.readFile(filePath, { encoding: "utf8" }, (err, file) => {
return;
}
// MarkdownファイルをHTML文字列に変換する
const html = marked(file);
const html = marked.parse(file);
console.log(html);
});
2 changes: 1 addition & 1 deletion source/use-case/nodecli/md-to-html/src/main-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fs.readFile(filePath, { encoding: "utf8" }, (err, file) => {
return;
}
// gfmオプションを無効にする
const html = marked(file, {
const html = marked.parse(file, {
gfm: false
});
console.log(html);
Expand Down
2 changes: 1 addition & 1 deletion source/use-case/nodecli/md-to-html/src/main-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fs.readFile(filePath, { encoding: "utf8" }, (err, file) => {
process.exit(1);
return;
}
const html = marked(file, {
const html = marked.parse(file, {
// オプションの値を使用する
gfm: cliOptions.gfm,
});
Expand Down
2 changes: 1 addition & 1 deletion source/use-case/nodecli/md-to-html/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fs.readFile(filePath, { encoding: "utf8" }, (err, file) => {
process.exit(1);
return;
}
const html = marked(file, {
const html = marked.parse(file, {
// オプションの値を使用する
gfm: cliOptions.gfm,
});
Expand Down
6 changes: 3 additions & 3 deletions source/use-case/nodecli/md-to-html/src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion source/use-case/nodecli/md-to-html/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"license": "ISC",
"dependencies": {
"commander": "^5.0.0",
"marked": "^1.0.0"
"marked": "^4.0.10"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fs.readFile(filePath, { encoding: "utf8" }, (err, file) => {
process.exit(1);
return;
}
const html = marked(file, {
const html = marked.parse(file, {
// オプションの値を使用する
gfm: cliOptions.gfm,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const marked = require("marked");

module.exports = (markdown, cliOptions) => {
return marked(markdown, {
return marked.parse(markdown, {
gfm: cliOptions.gfm,
});
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"license": "ISC",
"dependencies": {
"commander": "^5.0.0",
"marked": "1.0.0"
"marked": "^4.0.10"
},
"devDependencies": {
"mocha": "^7.0.0"
Expand Down