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
Support figure environment #3
Conversation
@@ -44,11 +44,12 @@ export const BeginEnvironment = ( | |||
|
|||
export const EndEnvironment = (context: Context): Parsimmon.Parser<null> => | |||
Parsimmon((input, i) => { | |||
const m = input.slice(i).match(new RegExp(`^\\\\end\\{${context.name}\\}`)); | |||
const pattern = context.name.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&'); |
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.
現在は.*?
が代入されるので問題無いのですが、BeginEnvironmentにも今後同様の可能性があるので、BeginEnvironmentの際にも同様のエスケープをしていただけますか?
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.
また、好みの問題ですが変数の寿命が短いので変数名はpattern
ではなくp
にしてもらえると嬉しいです。
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.
ありがとうございます。対応致します。
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.
- 変数名については修正しました。
- BeginEnvironmentのエスケープについて確認させてください。
以下の部分でBeginEnvironment(".*?", context)
という形で使用されているので、同様のエスケープをすると"\\.\\*\\?"
となってしまいませんか?
また、今回実装したfigureでも?
はメタ文字として使用しているため、エスケープは使用する側に任せた方が良いのではないかと思います(引数名もpatternなので、正規表現のパターンが期待されていることは読み取れます)。
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.
全くもってその通りですね。ご指摘ありがとうございます。見た限りテストも追加されており問題無く完璧なようですので、マージさせてもらいます。
Thank you for your contribution! cheers. |
#1 のうち、まずはfigure環境の部分を追加しました。
普通の
figure
環境と、2段組に1段組の図を挿入する時使用するfigure*
環境に対応しています。figure*
は以下の部分でそのままRegExpにするとアスタリスクがメタ文字になってしまうので、先にエスケープするようにしました。https://github.com/ta2gch/textlint-plugin-latex2e/blob/571e268eaef651dee094920409219156f1d6bf93/src/latex-to-ast/environment/common.ts#L45-L47