Skip to content

Conversation

@ShagovVladislav
Copy link

@@ -0,0 +1,16 @@
namespace Markdown;

public static class Markdown
Copy link

Choose a reason for hiding this comment

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

Про именование - "В fork-е этого репозитория создай проект Markdown и реализуй метод Render класса Md." То, что ты решил назвать по-своему не грубая ошибка, но усложняет проверку.

Copy link

Choose a reason for hiding this comment

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

Класс переименовал, а метод нет, хотя я подчеркнул, что это усложняет проверку.

{
public static string ToHtml(string markdownText)
{
var tokenizer = new Tokenizer(markdownText);
Copy link

Choose a reason for hiding this comment

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

tokenizer, text-parser и renderer предлагаю вынести в конструктор - либо принимай их там в качестве аргументов и один раз сохраняй в полях класса, либо создавай прямо в конструкторе; иначе получается, что на каждый вызов метода ты заново создаёшь экземпляры классов и повышаешь трафик памяти; дополнительно в токенайзере написал про это

@@ -0,0 +1,24 @@
using NUnit.Framework;
using System;

This comment was marked as resolved.

using NUnit.Framework;
using System;

namespace Markdown;

This comment was marked as resolved.


namespace Markdown;
[TestFixture]

This comment was marked as resolved.

private char Current => _position < _text.Length ? _text[_position] : '\0';
private char Peek(int offset = 1)
{
int pos = _position + offset;

This comment was marked as resolved.

return tokens;
}

private bool TryReadEscape(List<Token> tokens)

This comment was marked as resolved.

return true;
}

private bool TryReadFormatting(List<Token> tokens)

This comment was marked as resolved.

if (Current == '_' && Peek() == '_')
{
Advance(2);
tokens.Add(new Token(TokenType.BoldStart, "__"));

This comment was marked as resolved.

{
public string Render(List<Node> nodes)
{
var sb = new StringBuilder();

This comment was marked as resolved.

public string HeadingAndParagraphs(string content)
{

content = Markdown.ToHtml(content);

This comment was marked as resolved.

}

[Test]
public void ConvertToHtml_ShouldParseMultipleLists_WhenSeparatedByContent()

This comment was marked as resolved.

content.Should().Be("<ul><li>List A1</li><li>List A2</li></ul>\n<p>Paragraph</p>\n<ul><li>List B1</li><li>List B2</li></ul>");
}
[Test]
public void ConvertToHtml_ShouldParseHeading_WhenStartWithOctothorpe()
Copy link

Choose a reason for hiding this comment

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

Этот тест-кейс есть в следующем тесте.

[TestCase("#Heading", "<h1>Heading</h1>")]
[TestCase("##Heading", "<h2>Heading</h2>")]
[TestCase("###Heading", "<h3>Heading</h3>")]
[TestCase("####Heading", "<h4>Heading</h4>")]
Copy link

Choose a reason for hiding this comment

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

  1. Некорректно работает с кейсом "#################################"
  2. Некорректно работает с кейсом "\##Heading"

Copy link
Author

@ShagovVladislav ShagovVladislav Nov 21, 2025

Choose a reason for hiding this comment

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

1 не соглашусь, если просто "##############" то "", если "##############Heading" то "<h6>Heading</h6>"
установлено ограничение на 6 уровней заголовка, если исправлять, то мне кажется лучше в документации указать просто, что в HTML только 6 уровней заголовков.
2 в данном случае должно вывестись <p>#</p>\n<h1>Heading</h1>? или же <p>##Heading</p>? в спецификации не указан такой случай из-за отсутствия многоуровневых заголовков, смею предположить что первый вариант выглядит логичнее, но при этом ломает представление, тк заголовок и параграф не должны быть в одной строке.

Copy link

Choose a reason for hiding this comment

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

Обсудили в телеге

[Test]
public void ConvertToHtml_ShouldNorParse_WhenOnlyUnderscores()
{
var text = @"___";
Copy link

Choose a reason for hiding this comment

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

  1. Здесь и в других тестах ненужная "@".
  2. В этом тесте много кейсов, подумай, как следует.

Copy link

Choose a reason for hiding this comment

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

  1. Некорректно работает с немного другим кейсом "__ __" (именно двойные подчёркивания).

Copy link
Author

Choose a reason for hiding this comment

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

3 вижу странный результат, как в таком случае должны обрабатываться эти подчёркивания? обрабатываться просто как подчёркивания?
в спецификации два кейса:
1 За подчерками, начинающими выделение, должен следовать непробельный символ. Иначе эти_ подчерки_ не считаются выделением
и остаются просто символами подчерка.
2 Если внутри подчерков пустая строка ____, то они остаются символами подчерка.
но строка вроде и не пустая, но при этом с пробелами частично, что и выдаёт результат "_ __"

Copy link

Choose a reason for hiding this comment

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

Обсудили в телеге

}

[Test]
public void ConvertToHtml_ShouldParse_WhenScreeningOctothorpe()
Copy link

Choose a reason for hiding this comment

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

Объедини с другими кейсами про заголовки или с другими кейсами про экранирование.


content.Should().Be("<p><strong>bold text</strong></p>");
}

Copy link

Choose a reason for hiding this comment

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

Чет много места между тестами




[Test]
Copy link

Choose a reason for hiding this comment

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

Некорректно работает с кейсом _Italic Heading\\\\_ - я здесь экранирую слэш, значит, должно вернуться Italic Heading\, так?


content.Should().Be("<p>#Start</p>");
}

Copy link

Choose a reason for hiding this comment

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

  1. Некорректно работает кейс "\\" - символ экранирования должен исчезать, только если экранирует что-то, не правда ли?
  2. Подумай о случаях, когда вложенность экранирования больше 1-2 символов.

}

[Test]
public void ConvertToHtml_ShouldParse_WhenScreeningSlash()
Copy link

Choose a reason for hiding this comment

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

Отсутствует перфоманс-тест.

content.Should().Be("<p>Start _something _now</p>");
}
[Test]
public void ConvertToHtml_ShouldParse_WhenScreeningUnderscore()
Copy link

Choose a reason for hiding this comment

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

Работает с кейсом "_he_ll_", но почему-то не работает с кейсом "_._._".

public TokenType Type { get; }
public string Value { get; }

public Token(TokenType type, string value = "")
Copy link

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