-
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
Брозовский Максим #234
base: master
Are you sure you want to change the base?
Брозовский Максим #234
Changes from 3 commits
882da40
f5c3f1d
18b7b96
898ec46
a05ef8a
23b8f6a
e91b0e2
89b922f
711d9f0
0bb79b7
e764bda
f9c3b56
4b9415b
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,8 @@ | ||
using Markdown.Tokens; | ||
|
||
namespace Markdown; | ||
|
||
public class HtmlConverter : IConverter | ||
{ | ||
public string Convert(List<IToken> tokens) => throw new NotImplementedException(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Markdown.Tokens; | ||
|
||
namespace Markdown; | ||
|
||
public interface IConverter | ||
{ | ||
string Convert(List<IToken> tokens); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<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,13 @@ | ||
using Markdown.Tags; | ||
|
||
namespace Markdown; | ||
|
||
public static class Md | ||
{ | ||
private static readonly IEnumerable<ITag> Tags = [new BoldTag(), new HeaderTag(), new ItalicTag()]; | ||
public static string Render(string markdownText) | ||
{ | ||
var tokens = new Tokenizer(Tags).Tokenize(markdownText); | ||
return new HtmlConverter().Convert(tokens); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Markdown; | ||
|
||
class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Hello, World!"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Markdown.Tags; | ||
|
||
public class BoldTag : PairTag, ITag | ||
{ | ||
public override string MdTag => "__"; | ||
public override string HtmlTag => "<strong>"; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Markdown.Tags; | ||
|
||
public class HeaderTag : SingleTag, ITag | ||
{ | ||
public override string MdTag => "#"; | ||
public override string HtmlTag => "<h1>"; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Markdown.Tags; | ||
|
||
public interface ITag | ||
{ | ||
string MdTag { get; } | ||
string HtmlTag { get; } | ||
|
||
bool IsOpenedCorrectly((char left, char right) contextChars); | ||
bool IsClosedCorrectly((char left, char right) contextChars); | ||
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. Выдели мб отдельную модельку под это? Таплы передавать публично плохая практика. У тебя уже два места, где одна и та же модель используется. При изменении одно из этих мест надо отдельно помнить и о другом |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Markdown.Tags; | ||
|
||
public class ItalicTag : PairTag, ITag | ||
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. А зачем интерфейс еще раз указывать? |
||
{ | ||
public override string MdTag => "_"; | ||
public override string HtmlTag => "<em>"; | ||
|
||
protected override IEnumerable<ITag> ForbiddenInside => [new BoldTag()]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Markdown.Tags; | ||
|
||
public abstract class PairTag : ITag | ||
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. И как определяем закрываюищий тег? 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. для MdTag добавил, а HtmlTag там симметричный, т.е. <HtmlTag></HtmlTag> 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.
Главное отличие в том, что у одинарного не будет закрвающего MdTag и он действует на всю строчку, а для HtmlTag мы делаем как в коментарии выше - симметрично 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. Но там тоже могут быть особые случаи типа <img> тега.... 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. но мне кажется это уже отвественность IMdConverter, как он будет эти токены укладывать в строку |
||
{ | ||
public abstract string MdTag { get; } | ||
public abstract string HtmlTag { get; } | ||
|
||
public virtual bool IsOpenedCorrectly((char left, char right) contextChars) => contextChars.left != ' '; | ||
public virtual bool IsClosedCorrectly((char left, char right) contextChars) => contextChars.right != ' '; | ||
|
||
protected virtual IEnumerable<ITag> ForbiddenInside => []; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Markdown.Tags; | ||
|
||
public abstract class SingleTag : ITag | ||
{ | ||
public abstract string MdTag { get; } | ||
public abstract string HtmlTag { get; } | ||
|
||
public virtual bool IsOpenedCorrectly((char left, char right) contextChars) => contextChars.left == '\n'; | ||
public bool IsClosedCorrectly((char left, char right) contextChars) => true; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Markdown.Tags; | ||
|
||
public enum TagStatus | ||
{ | ||
Opened, | ||
Closed | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Markdown.Tags; | ||
using Markdown.Tokens; | ||
|
||
namespace Markdown; | ||
|
||
public class Tokenizer(IEnumerable<ITag> tags) | ||
{ | ||
public List<IToken> Tokenize(string markdownText) => throw new NotImplementedException(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Markdown.Tokens; | ||
|
||
public class EscapeToken : IToken | ||
{ | ||
public string Value => "\\"; | ||
public int Length => 1; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Markdown.Tokens; | ||
|
||
public interface IToken | ||
{ | ||
string Value { get; } | ||
int Length { get; } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Markdown.Tokens; | ||
|
||
public class NewLineToken : IToken | ||
{ | ||
public string Value => "\n"; | ||
public int Length => 1; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Markdown.Tags; | ||
|
||
namespace Markdown.Tokens; | ||
|
||
public class TagToken(ITag tag, char left, char right) : IToken | ||
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. А почему char? Например, __ - это два подчеркивания. |
||
{ | ||
public ITag Tag => tag; | ||
public TagStatus Status { get; set; } | ||
// TODO: we should get value of tag by his status? | ||
public string Value => throw new NotImplementedException(); | ||
public int Length => Tag.MdTag.Length; | ||
public (char left, char right) ContextChars => (left, right); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Markdown.Tokens; | ||
|
||
public class TextToken(string value) : IToken | ||
{ | ||
public string Value => value; | ||
public int Length => Value.Length; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"/> | ||
<PackageReference Include="FluentAssertions" Version="6.12.2" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/> | ||
<PackageReference Include="NUnit" Version="3.14.0"/> | ||
<PackageReference Include="NUnit.Analyzers" Version="3.9.0"/> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="NUnit.Framework"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Markdown\Markdown.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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.
Конвертер чего?