-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
feat: Change automatic line breaks to optional #64
Conversation
今回の PR から API やプロパティーなどにコード ドキュメントを付けるようにしました。コードが自己言及的に書かれていればコメントは不要という思想もありますが、最もコードに近い場所へ意図などを記述する場としてコメントはあったほうがよいと考えているため、今後はなるべく書く予定です。 IDE や VS Code など入力補完の効く環境下で API リファレンスとして機能することも狙っています。 |
すみません。CLI 対応が抜けてたので改めてコミットしました。もし CLI を試される場合は
VFM を
と
を比較してください。既定値 |
↑のコメントを書いて思ったのですが remark-breaks の処理は「変換」ではなく、改行位置へ コード ドキュメントや CLI ヘルプでは "Convert" としましたが、なにかよい代替表現があればご指摘ください。またオプションもよりよい名前がありそうですね。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PRありがとうございました。JSDocによるコメントなどありがたいです!
レビューコメント以外に一点、autoLineBreaks
の有無による出力結果の変化についてテストがない状態なので、tests/block/
以下に追加していただけるとありがたいです。
例えばGFMでは、改行1つによるautoLineBreaksはoffですが、行末に
や \
があると改行される仕様があります (https://gist.github.com/shaunlebron/746476e6e7a4d698b373 )。その点なども、testで確認できると良いかと思いました。
src/revive-parse.ts
Outdated
|
||
if (options.autoLineBreaks) { | ||
// Line breaks are processed immediately after ruby | ||
results.splice(3, 0, breaks); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indexをマジックナンバーで指定して挿入する実装は results
の変更への追従を忘れてしまう恐れがあるためおすすめできません。同等の実装は以下のコードでも可能です。
const results = [
(snip)
...(options.autoLineBreaks ? [breaks] : []),
(snip)
];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spread operator で条件分岐いけるのですね。マジックナンバーよりも好ましいのでこの方法に変更します。
src/revive-parse.ts
Outdated
* @param options Options. | ||
* @returns Parsers. | ||
*/ | ||
export const reviveParse = (options: MarkdownOptions) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
返値の型として unified.PluggableList<unified.Settings>
を明示していただけますか? その結果、results
にある as unified.PluggableList<unified.Settings>
を省略することが可能です。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
元コードで直に配列を返す際の as
を踏襲していましたが、関数化したなら確かに返り値の型で明示するほうが好ましいですね。そのように変更します。
で対応します。 |
… option If it is not expanded and is a normal argument, the caller must resolve the dependency between the properties. The VFM function avoids this by expansion, so referred to it.
1. Avoid `as` by explicitly specifying the return type of reviveParse 2. Independent test of line break handle
指摘のあった箇所を修正しました。 |
現時点の対応でよろしければ merge しますので、お手すきの時に再レビューをお願いします。 |
--auto-line-breaks という名前ですが、長い行を自動で改行を入れるという意味かと誤解されるかもしれません。 Pandocはオプションで改行の扱いを変えることができるので、それに倣うのがよいと思います。 https://pandoc.org/MANUAL.html#extension-hard_line_breaks
テスト:
The quick brown fox
jumps over the lazy dog. ↓ <p>The quick brown fox<br />
jumps over the lazy dog.</p> ということで、 |
いい案ですね。対応します。 |
村上さんのオプション名案を反映しました |
@spring-raining @MurakamiShinyu |
README.md
Outdated
@@ -24,6 +24,7 @@ Vivliostyle Flavored Markdown (VFM), a Markdown syntax optimized for book author | |||
- [`partial` (default: `false`)](#partial-default-false) | |||
- [`title` (default: `undefined`)](#title-default-undefined) | |||
- [`language` (default: `undefined`)](#language-default-undefined) | |||
- [`autoLineBreaks` (default: `false`)](#autoLineBreaks-default-false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- [`autoLineBreaks` (default: `false`)](#autoLineBreaks-default-false) | |
- [`hardLineBreaks` (default: `false`)](#hardLineBreaks-default-false) |
README.md
Outdated
@@ -210,6 +211,38 @@ will generates: | |||
</html> | |||
``` | |||
|
|||
#### `autoLineBreaks` (default: `false`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#### `autoLineBreaks` (default: `false`) | |
#### `hardLineBreaks` (default: `false`) |
README.md
Outdated
new | ||
line | ||
`, | ||
{ autoLineBreaks: true }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ autoLineBreaks: true }, | |
{ hardLineBreaks: true }, |
@spring-raining ありがとうございます。指摘のあった README の変更漏れを修正しました。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
良さそうです!
@spring-raining @MurakamiShinyu レビューありがとうございました! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
#50 対応。