-
Notifications
You must be signed in to change notification settings - Fork 319
Савицких Антон #270
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
base: master
Are you sure you want to change the base?
Савицких Антон #270
Conversation
| if (Builder != null && Tokenizer != null) | ||
| { | ||
| var tokens = Tokenizer.Tokenize(text); | ||
| var ast = new SyntaxTree(tokens); | ||
| var convertedText = Builder.Build(ast); | ||
| return convertedText; | ||
| } | ||
| throw new NullReferenceException(); |
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.
ok
| public IBuilder Builder { get; } | ||
| public ITokenizer Tokenizer { get; } |
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.
Можно сделать приватными readonly полями, думаю конвертер не подразумевает отдельное их использование в обход своей логики
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.
ok
| List<string> TextToLines(string text); | ||
|
|
||
| List<Token> TokenizeLines(IEnumerable<string> lines); | ||
|
|
||
| List<Token> TokenizeLine(string line); |
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.
++
| _tagMapping = new Dictionary<NodeType, string> | ||
| { | ||
| { NodeType.Document, "" }, | ||
| { NodeType.Paragraph, "p" }, | ||
| { NodeType.Header, "h1" }, | ||
| { NodeType.Bold, "strong" }, | ||
| { NodeType.Italic, "em" }, | ||
| { NodeType.Text, "" } | ||
| }; |
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.
ok
| return; | ||
| } | ||
|
|
||
| if (currentChar == '_') |
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.
Давай '_' в какие-нибудь константы markdown и в похожих местах
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.
ok
|
|
||
| if (IsValidClosingMarker(line, currentPosition, true)) | ||
| { | ||
| var isEmptyWord = IsEmptyMarkedWord(currentPosition, startPosition, 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.
Лишний пробел 👉👈
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.
oki
| if (innerTokens.Count > 0) | ||
| { | ||
| FlushTextBufferIfNotEmpty(originalTextBuffer, tokens); | ||
| AddNestedItalicsTokens(textBuffer, tokens, innerTokens); | ||
| SkipBoldMarker(ref currentPosition); | ||
| return; | ||
| } | ||
|
|
||
| FlushTextBufferIfNotEmpty(originalTextBuffer, tokens); | ||
| AddTokensFromBufferWithSpecifiedTags(textBuffer, tokens, TokenType.BoldStart, TokenType.BoldEnd); | ||
| SkipBoldMarker(ref currentPosition); |
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.
Можно тернарник, а то повторки
| private void PrependMarkerToBuffer(StringBuilder textBuffer, bool isBold) | ||
| { | ||
| if (isBold) | ||
| { | ||
| textBuffer.Insert(0, "__"); | ||
| } | ||
| else | ||
| { | ||
| textBuffer.Insert(0, '_'); | ||
| } | ||
| } | ||
|
|
||
| private void AppendMarkerToBuffer(StringBuilder textBuffer, bool isBold) | ||
| { | ||
| if (isBold) | ||
| { | ||
| textBuffer.Append("__"); | ||
| } | ||
| else | ||
| { | ||
| textBuffer.Append('_'); | ||
| } | ||
| } |
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.
Какие-то одинаковые методы
| private bool CanContinueParsingHeaderContent() | ||
| { | ||
| return currentIndex < tokens.Count && tokens[currentIndex].Type != TokenType.Newline; | ||
| } | ||
|
|
||
| private bool HasNewlineTokenAtCurrentPosition() | ||
| { | ||
| return currentIndex < tokens.Count && tokens[currentIndex].Type == TokenType.Newline; | ||
| } | ||
|
|
||
| private bool CanContinueParsingParagraphContent() | ||
| { | ||
| return currentIndex < tokens.Count && tokens[currentIndex].Type != TokenType.Newline; | ||
| } | ||
|
|
||
| private bool CanContinueParsingBoldContent() | ||
| { | ||
| return currentIndex < tokens.Count && tokens[currentIndex].Type != TokenType.BoldEnd; | ||
| } | ||
|
|
||
| private bool HasBoldEndTokenAtCurrentPosition() | ||
| { | ||
| return currentIndex < tokens.Count && tokens[currentIndex].Type == TokenType.BoldEnd; | ||
| } | ||
|
|
||
| private bool CanContinueParsingItalicContent() | ||
| { | ||
| return currentIndex < tokens.Count && tokens[currentIndex].Type != TokenType.ItalicsEnd; | ||
| } | ||
|
|
||
| private bool HasItalicsEndTokenAtCurrentPosition() | ||
| { | ||
| return currentIndex < tokens.Count && tokens[currentIndex].Type == TokenType.ItalicsEnd; | ||
| } |
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.
Кажется можно один или два метода сделать и переиспользовать
@ksamnole