Skip to content

Conversation

@Xineev
Copy link

@Xineev Xineev commented Nov 14, 2025

Comment on lines 36 to 43
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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно более явную ошибку об отсутствии билдера или токенайзера

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment on lines 25 to 26
public IBuilder Builder { get; }
public ITokenizer Tokenizer { get; }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно сделать приватными readonly полями, думаю конвертер не подразумевает отдельное их использование в обход своей логики

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment on lines +13 to +17
List<string> TextToLines(string text);

List<Token> TokenizeLines(IEnumerable<string> lines);

List<Token> TokenizeLine(string line);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Методы нигде не используются, думаю они не должны торчать наружу

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Comment on lines 29 to 37
_tagMapping = new Dictionary<NodeType, string>
{
{ NodeType.Document, "" },
{ NodeType.Paragraph, "p" },
{ NodeType.Header, "h1" },
{ NodeType.Bold, "strong" },
{ NodeType.Italic, "em" },
{ NodeType.Text, "" }
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Может вынести куда-нибудь в отдельный файл или в поля класса, всё равно он не изменяется

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

return;
}

if (currentChar == '_')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давай '_' в какие-нибудь константы markdown и в похожих местах

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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лишний пробел 👉👈

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oki

Comment on lines 208 to 218
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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно тернарник, а то повторки

Comment on lines 284 to 306
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('_');
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Какие-то одинаковые методы

Comment on lines 186 to 219
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;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кажется можно один или два метода сделать и переиспользовать

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants