Skip to content
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

Брайденбихер Виктор Николаевич #240

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cs/Markdown/Markdown.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
17 changes: 17 additions & 0 deletions cs/Markdown/MarkdownRenders/ConcreteMarkdownRenders/HtmlRender.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Markdown.Parsers;

namespace Markdown.MarkdownRenders.ConcreteMarkdownRenders
{
public class HtmlRender : IMarkdownRender

Choose a reason for hiding this comment

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

HtmlRender_er_

HtmlRender наследуется от MarkdownRender звучит не очень логично)

{
public string Render(AstNode root)
{
throw new NotImplementedException();
}
}
}
14 changes: 14 additions & 0 deletions cs/Markdown/MarkdownRenders/IMarkdownRender.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Markdown.Parsers;

namespace Markdown.MarkdownRenders
{
public interface IMarkdownRender

Choose a reason for hiding this comment

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

Render -> Renderer

{
public string Render(AstNode root);
}
}
36 changes: 36 additions & 0 deletions cs/Markdown/Md.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Markdown.MarkdownRenders;
using Markdown.Parsers;
using Markdown.TokenizerClasses;
using Markdown.TokenizerClasses.ConcreteTokenizers;

namespace Markdown
{
public class Md
{
private readonly IMarkdownParser markdownParser;

private readonly ITokenizer markdownTokenizer;

private readonly IMarkdownRender render;

public Md(IMarkdownParser parser, ITokenizer tokenizer, IMarkdownRender render)
{
markdownParser = parser;
markdownTokenizer = tokenizer;
this.render = render;
}

public string Render(string text)
{
var tokens = markdownTokenizer.Tokenize(text);
var rootNode = markdownParser.Parse(tokens);

return render.Render(rootNode);

Choose a reason for hiding this comment

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

Возможно немного перемудрил с проектированием. Нам недостаточно следовать такого плана?

  1. markdown строку разбиваем на токены
  2. из токенов собираем html строку

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

Choose a reason for hiding this comment

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

Сейчас так понимаю схема такая: markdownStr -> Tokens -> Nodes (Tags) -> htmlStr

}
}
}
32 changes: 32 additions & 0 deletions cs/Markdown/Parsers/AstNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Markdown.Tags;
using Markdown.Tokens;

namespace Markdown.Parsers
{
public class AstNode
{
public readonly AstNode ParentToken;

public readonly List<AstNode> ChildsTokens;

public Tag Tag;

public AstNode(AstNode parent, Tag tag)
{
ParentToken = parent;
ParentToken.ChildsTokens.Add(this);

Choose a reason for hiding this comment

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

NRE


Tag = tag;
}

public void AddChild(AstNode child)
{
ChildsTokens.Add(child);
}
}
}
26 changes: 26 additions & 0 deletions cs/Markdown/Parsers/ConcreteMarkdownParsers/MarkdownParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Markdown.Tags;
using Markdown.Tags.ConcreteTags;
using Markdown.Tokens;

namespace Markdown.Parsers.ConcreteMarkdownParsers
{
public class MarkdownParser : IMarkdownParser
{

public AstNode Parse(List<Token> tokens)
{
var root = new AstNode(null, new DocumentTag());

//Некая логика

return root;
}
}
}
14 changes: 14 additions & 0 deletions cs/Markdown/Parsers/IMarkdownParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Markdown.Tokens;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Markdown.Parsers
{
public interface IMarkdownParser
{
public AstNode Parse(List<Token> tokens);
}
}
22 changes: 22 additions & 0 deletions cs/Markdown/Parsers/TokenExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Markdown.Tokens;

namespace Markdown.Parsers
{
public static class TokenExtensions
{
public static bool IsHash(this Token token)
{
throw new NotImplementedException();
}

Choose a reason for hiding this comment

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

Для чего этот метод нужен будет? Не очень понятно из названия - IsHash


public static bool IsWhiteSpace(this Token token)
{
throw new NotImplementedException();
}
}
}
15 changes: 15 additions & 0 deletions cs/Markdown/Tags/ConcreteTags/DocumentTag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Markdown.Tags.ConcreteTags
{
public class DocumentTag : Tag
{
public DocumentTag() : base(TagType.Document, String.Empty, true, 0)
{
}
}
}
15 changes: 15 additions & 0 deletions cs/Markdown/Tags/ConcreteTags/TextTag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Markdown.Tags.ConcreteTags
{
public class TextTag : Tag
{
public TextTag(string content) : base(TagType.Text, content, true, 0)
{
}
}
}
41 changes: 41 additions & 0 deletions cs/Markdown/Tags/Tag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Markdown.Tags.ConcreteTags;

namespace Markdown.Tags
{
public abstract class Tag
{
public bool IsCompleted { get; set; }

public bool SelfCompeted { get; protected set; }

public TagType TagType { get; protected set; }

public readonly string Content;

public readonly int level;

public Tag(TagType tagType, string content, bool selfCompleted, int level = 0)
{
TagType = tagType;
Content = content;
this.level = level;
Content = string.Empty;

Choose a reason for hiding this comment

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

Content = content;
...
Content = string.Empty;


SelfCompeted = selfCompleted;
IsCompleted = false;
}

public Tag CheckCompleted()
{
if (IsCompleted || SelfCompeted)
return this;

return new TextTag(this.Content);
}

Choose a reason for hiding this comment

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

Снова не понятно, что за метод 😓. Из названия хочется думать - "Проверить завершенность", т.е. закрылся ли тэг или что-то подобное, на деле возвращаем новый TextTag?

}
}
19 changes: 19 additions & 0 deletions cs/Markdown/Tags/TagType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Markdown.Tags
{
public enum TagType
{
Document,
Header,
Italic,
Bold,
Paragraph,
BulletedList,
Text

Choose a reason for hiding this comment

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

Document, Text - это что за теги в HTML?

}
}
20 changes: 20 additions & 0 deletions cs/Markdown/TokenizerClasses/ConcreteTokenizers/Tokenizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using Markdown.Tags;
using Markdown.Tokens;

namespace Markdown.TokenizerClasses.ConcreteTokenizers
{

Choose a reason for hiding this comment

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

Придерживайся везде единого стиля. Рядом лежат две папки: Parsers, Renderers внутри которых папка с конкретными реализациями, рядом лежат интерфейсы и вспомогательные классы. А тут в названии откуда-то "Classes"

public class Tokenizer : ITokenizer
{
public List<Token> Tokenize(string text)
{
throw new NotImplementedException();
}
}
}
14 changes: 14 additions & 0 deletions cs/Markdown/TokenizerClasses/ITokenizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Markdown.Tokens;

namespace Markdown.TokenizerClasses
{
public interface ITokenizer
{
public List<Token> Tokenize(string text);
}
}
17 changes: 17 additions & 0 deletions cs/Markdown/TokenizerClasses/TokenFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Markdown.Tokens;

namespace Markdown.TokenizerClasses
{
public class TokenFactory
{
public static Token CreateSingleCharacterToken(string ch)
{
throw new NotImplementedException();
}
}
}
10 changes: 10 additions & 0 deletions cs/Markdown/Tokens/ConcreteTokens/ConcreteTokens.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Markdown.Tokens.ConcreteTokens
{
// Сюда думаю можно прописать конкретные классы токенов, наследников Token
}
23 changes: 23 additions & 0 deletions cs/Markdown/Tokens/Token.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Markdown.Tags;

namespace Markdown.Tokens
{
public class Token
{
public readonly TokenType TokenType;

public readonly string Content;

public Token(TokenType tokenType, string content)
{
TokenType = tokenType;

Content = content;
}
}
}
22 changes: 22 additions & 0 deletions cs/Markdown/Tokens/TokenType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Markdown.Tokens
{
public enum TokenType
{
WhiteSpace,
BreakLine,
Escape,
Em_start,
Em_end,
Bold_start,
Bold_end,
Hash,
Text,
Number
}
}
Loading