Skip to content

Ситдиков Сергей#259

Open
s1lenter wants to merge 2 commits intokontur-courses:masterfrom
s1lenter:master
Open

Ситдиков Сергей#259
s1lenter wants to merge 2 commits intokontur-courses:masterfrom
s1lenter:master

Conversation

@s1lenter
Copy link
Copy Markdown

@s1lenter s1lenter commented Nov 4, 2025

@PeterMotorniy

Идея такая:
Текст разбивается на параграфы
Параграфы на токены(обычный текст, подчеркивание, двойное подчеркивание)
Потом анализ списка токенов и сбор в html строку

@s1lenter s1lenter closed this Nov 4, 2025
@s1lenter s1lenter reopened this Nov 4, 2025
@s1lenter s1lenter changed the title @PeterMotorniy Ситдиков Сергей Nov 4, 2025

public class Md
{
public string Render(string markdownString)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Кажется класс Md знает слишком много о внутренней архитектуре (напрямую вызывает ParagraphCreator, Tokenizer, HtmlCreator). Точно ли так должно быть?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Так быть не должно, поэтому выделю отдельный класс MarkdownProcessor, в котором уже инициализация происходит других нужных классов, и из этого класса в Render будет вызван один метод конвертации в HTML

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

public static class HtmlCreator
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Точно ли оба метода должны относиться к этому классу? Может разбить на 2 класса?

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

public static class ParagraphCreator
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

У тебя все классы содержат сразу реализацию, но что если мне понадобится ее поменять?
Давай для основных классов, например для ParagraphCreator, Tokenizer и других создадим интерфейсы типа IParagraphCreator, чтобы в будущем можно было проще поменять или добавить новую реализацию

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

public class Token
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Почему не используешь свойства?
Может сделать его не класс а record?
Все ли поля должны быть доступны для записи из других классов?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Можно сделать record, потому что не планируется изменение значений уже установленного токена, с параграфом такая же ситуация

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

public static class Tokenizer
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Где будет обрабатываться экранирование символов, правильная вложенность конструкций? Тоже в этом классе или что-то отдельное появится?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Для обработки добавил парсер токенов в дерево, в котором будет удобно работать с вложенностью, и экранирование будет обрабатываться тоже при парсинге, чтобы дерево уже было с верными значениями


public static class ParagraphCreator
{
public static List<Paragraph> CreateParagraphs(string markdownString)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Вопрос по неймингу - точно ли тут слово create подходит?


public static class Tokenizer
{
public static List<Token> CreateTokens(Paragraph paragraph)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Вопрос по неймингу - точно ли тут слово create подходит?

@@ -0,0 +1,10 @@
using System.Security.AccessControl;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Зачем юзинг?


var paragraphs = ParagraphCreator.CreateParagraphs(markdownString);

foreach (var paragraph in paragraphs)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Что если во время работы будет выброшено исключение? Поймет ли пользователь, что пошло не так и как ему исправить проблему?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Пользователь не поймет в чем ошибка. Нужно обработать входные данные и в случае чего выкинуть уже конкретное исключение?

@@ -0,0 +1,6 @@
namespace Markdown.Node;

public class ItalicNode
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Должно наследоваться от INode?

@@ -0,0 +1,6 @@
namespace Markdown;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

неймспейс неправильный

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

public enum TokenType
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Может экранирование как токен вынести?

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

public record Token(int Position, int Length, string Value, TokenType Type); No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Точно ли нужно Value?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно еще в токене хранить парный он или нет, то есть должен закрываться или нет


public MarkdownProcessor()
{
_paragraphCreator = new ParagraphCreator();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

А может все классы передавать в конструкторе?

_htmlCreator = new HtmlCreator();
}

public string ConvertToHtml(string markdownString)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Нужна какая-то проверка markdownString? Что если она будет null или пустой? Или слишком длинной?


namespace Markdown.TokenParser;

public interface IParser
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ITokenParser

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