-
Notifications
You must be signed in to change notification settings - Fork 300
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
e71ae62
65076d5
45c5f64
6799291
d0933eb
c827718
c6291eb
a14650c
e031495
06c663b
f33653b
0bb4f52
666bb98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> |
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 | ||
{ | ||
public string Render(AstNode root) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Render -> Renderer |
||
{ | ||
public string Render(AstNode root); | ||
} | ||
} |
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Сейчас так понимаю схема такая: markdownStr -> Tokens -> Nodes (Tags) -> htmlStr |
||
} | ||
} | ||
} |
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NRE |
||
|
||
Tag = tag; | ||
} | ||
|
||
public void AddChild(AstNode child) | ||
{ | ||
ChildsTokens.Add(child); | ||
} | ||
} | ||
} |
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; | ||
} | ||
} | ||
} |
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); | ||
} | ||
} |
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(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Для чего этот метод нужен будет? Не очень понятно из названия - IsHash |
||
|
||
public static bool IsWhiteSpace(this Token token) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
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) | ||
{ | ||
} | ||
} | ||
} |
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) | ||
{ | ||
} | ||
} | ||
} |
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
SelfCompeted = selfCompleted; | ||
IsCompleted = false; | ||
} | ||
|
||
public Tag CheckCompleted() | ||
{ | ||
if (IsCompleted || SelfCompeted) | ||
return this; | ||
|
||
return new TextTag(this.Content); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Снова не понятно, что за метод 😓. Из названия хочется думать - "Проверить завершенность", т.е. закрылся ли тэг или что-то подобное, на деле возвращаем новый TextTag? |
||
} | ||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Document, Text - это что за теги в HTML? |
||
} | ||
} |
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 | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
} | ||
} | ||
} |
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); | ||
} | ||
} |
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(); | ||
} | ||
} | ||
} |
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 | ||
} |
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; | ||
} | ||
} | ||
} |
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 | ||
} | ||
} |
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.
HtmlRender_er_
HtmlRender наследуется от MarkdownRender звучит не очень логично)