-
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
Рыбин Леонид #236
base: master
Are you sure you want to change the base?
Рыбин Леонид #236
Changes from 3 commits
dd6c865
f58bebf
2953301
3098027
0e78fce
d954e38
ec240a3
7d337ad
db4069a
8dc7f24
71a7e22
7b4d9db
e92b5fc
d5ed0a0
ea13850
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,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Token\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Text; | ||
using Markdown.Tags; | ||
using Markdown.Token; | ||
|
||
namespace Markdown; | ||
|
||
public class Md | ||
{ | ||
private readonly List<ITag> availableTags = | ||
[ | ||
new BoldTag(), | ||
new H1Tag(), | ||
new ItalicTextTag(), | ||
new EscapeTag() | ||
]; | ||
|
||
public string Render(string text) | ||
{ | ||
var parser = new TagParser(availableTags); | ||
return GenerateHtml(text, parser.GetTokens(text)); | ||
This comment was marked as resolved.
Sorry, something went wrong. 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. Ну если про GetTokens говорить, то он возращает, что-то такое: |
||
} | ||
|
||
private string GenerateHtml(string text, List<IToken> tokens) | ||
{ | ||
// TODO some logic | ||
throw new NotImplementedException(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
using Markdown; | ||
|
||
Md md = new Md(); | ||
md.Render("text \n\n\n text123"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Collections; | ||
using Markdown.Tags; | ||
using Markdown.Token; | ||
|
||
namespace Markdown; | ||
|
||
public class TagParser | ||
{ | ||
private readonly List<(Stack<ITag>, TagType)> TagsOrder; | ||
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 TagParser(List<ITag> tags) | ||
{ | ||
foreach (var tag in tags) | ||
{ | ||
TagsOrder.Add((new Stack<ITag> {}, tag.Type)); | ||
} | ||
} | ||
|
||
public List<IToken> GetTokens(string text) | ||
{ | ||
// TODO some logic | ||
throw new NotImplementedException(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Markdown.Tags; | ||
|
||
namespace Markdown.Tags; | ||
|
||
public class BoldTag : ITag | ||
{ | ||
public string Head => "<strong>"; | ||
public string Tail => "</strong>"; | ||
public string MdView => "__"; | ||
public TagType Type => TagType.BoldText; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Markdown.Tags; | ||
|
||
public class EscapeTag : ITag | ||
{ | ||
public string Head => ""; | ||
public string Tail => ""; | ||
public string MdView => """\"""; | ||
public TagType Type => TagType.Escape; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Markdown.Tags; | ||
|
||
namespace Markdown.Tags; | ||
|
||
public class H1Tag : ITag | ||
{ | ||
public string Head => "<h1>"; | ||
public string Tail => "</h1>"; | ||
public string MdView => "# "; | ||
public TagType Type => TagType.Header; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Markdown.Tags; | ||
|
||
public interface ITag | ||
{ | ||
public string MdView { get; } | ||
public string Head { get;} | ||
public string Tail { get;} | ||
public TagType Type { get; } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Markdown.Tags; | ||
|
||
namespace Markdown.Tags; | ||
|
||
public class ItalicTextTag : ITag | ||
{ | ||
public string Head => "<em>"; | ||
public string Tail => "</em>"; | ||
public string MdView => "_"; | ||
public TagType Type => TagType.ItalicText; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Markdown.Tags; | ||
|
||
public enum TagType | ||
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. Кажется этот enum-чик лишним, т.к. у тебя уже есть разные реализации |
||
{ | ||
Header, | ||
ItalicText, | ||
BoldText, | ||
Escape | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Markdown.Tags; | ||
|
||
namespace Markdown.Token; | ||
|
||
public interface 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. Почему интерфейс? Какие реализации будут? |
||
{ | ||
public string SourceText { get; } | ||
public string ConvertedText { get; } | ||
public int Position { get; set; } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace MarkdownTests | ||
{ | ||
public class Tests | ||
{ | ||
[SetUp] | ||
public void Setup() | ||
{ | ||
} | ||
|
||
[Test] | ||
public void Test1() | ||
{ | ||
Assert.Pass(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<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="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> | ||
<ProjectReference Include="..\Markdown\Markdown.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="NUnit.Framework" /> | ||
</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.
Можно всё это статическим сделать - и класс, и этот список.