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

Рыбин Леонид #236

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
14 changes: 14 additions & 0 deletions cs/Markdown/Markdown.csproj
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>
28 changes: 28 additions & 0 deletions cs/Markdown/Md.cs
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 =

Choose a reason for hiding this comment

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

Можно всё это статическим сделать - и класс, и этот список.

[
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.

Copy link
Author

Choose a reason for hiding this comment

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

Ну если про GetTokens говорить, то он возращает, что-то такое:
"# ", <h1>, position = 0
"_", <em>, position = 8
А GenerateHtml пробегает по тексту и меняет в нужной позиции символы на HTML тэги, при этом у него может быть глобальный сдвиг, чтобы позиции символов оставались актуальными

}

private string GenerateHtml(string text, List<IToken> tokens)
{
// TODO some logic
throw new NotImplementedException();
}
}
4 changes: 4 additions & 0 deletions cs/Markdown/Program.cs
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");
24 changes: 24 additions & 0 deletions cs/Markdown/TagParser.cs
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;

Choose a reason for hiding this comment

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

Чёт пока сложно как-то тут и непонятно, как это использовать: вроде это должен быть список List<ITag> tags, который наш парсер будет уметь распознавать и уметь конвертировать.

Т.е. чтобы тебе до конца понять, как это ты будешь использовать - необходим какой-то псевдокод, набросочек public List<IToken> GetTokens(string text).


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();
}
}
11 changes: 11 additions & 0 deletions cs/Markdown/Tags/BoldTag.cs
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;
}
9 changes: 9 additions & 0 deletions cs/Markdown/Tags/EscapeTag.cs
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;
}
11 changes: 11 additions & 0 deletions cs/Markdown/Tags/H1Tag.cs
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;
}
9 changes: 9 additions & 0 deletions cs/Markdown/Tags/ITag.cs
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; }
}
11 changes: 11 additions & 0 deletions cs/Markdown/Tags/ItalicTextTag.cs
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;
}
9 changes: 9 additions & 0 deletions cs/Markdown/Tags/TagType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Markdown.Tags;

public enum TagType

Choose a reason for hiding this comment

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

Кажется этот enum-чик лишним, т.к. у тебя уже есть разные реализации ITag - они и отражают тип тэга.

{
Header,
ItalicText,
BoldText,
Escape
}
10 changes: 10 additions & 0 deletions cs/Markdown/Token/IToken.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Markdown.Tags;

namespace Markdown.Token;

public interface IToken

Choose a reason for hiding this comment

The 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; }
}
16 changes: 16 additions & 0 deletions cs/MarkdownTests/MarkdownTest.cs
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();
}
}
}
28 changes: 28 additions & 0 deletions cs/MarkdownTests/MarkdownTests.csproj
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>
19 changes: 17 additions & 2 deletions cs/clean-code.sln
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio Version 17
VisualStudioVersion = 17.12.35514.174 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chess", "Chess\Chess.csproj", "{DBFBE40E-EE0C-48F4-8763-EBD11C960081}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ControlDigit", "ControlDigit\ControlDigit.csproj", "{B06A4B35-9D61-4A63-9167-0673F20CA989}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples", "Samples\Samples.csproj", "{C3EF41D7-50EF-4CE1-B30A-D1D81C93D7FA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Markdown", "Markdown\Markdown.csproj", "{2A88730A-1C3F-42B6-AD70-FF890AEAC047}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MarkdownTests", "MarkdownTests\MarkdownTests.csproj", "{5928AADB-6ACE-429E-B801-BE58A76299AC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,5 +31,16 @@ Global
{C3EF41D7-50EF-4CE1-B30A-D1D81C93D7FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C3EF41D7-50EF-4CE1-B30A-D1D81C93D7FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C3EF41D7-50EF-4CE1-B30A-D1D81C93D7FA}.Release|Any CPU.Build.0 = Release|Any CPU
{2A88730A-1C3F-42B6-AD70-FF890AEAC047}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A88730A-1C3F-42B6-AD70-FF890AEAC047}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A88730A-1C3F-42B6-AD70-FF890AEAC047}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A88730A-1C3F-42B6-AD70-FF890AEAC047}.Release|Any CPU.Build.0 = Release|Any CPU
{5928AADB-6ACE-429E-B801-BE58A76299AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5928AADB-6ACE-429E-B801-BE58A76299AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5928AADB-6ACE-429E-B801-BE58A76299AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5928AADB-6ACE-429E-B801-BE58A76299AC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
3 changes: 3 additions & 0 deletions cs/clean-code.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=4a98fdf6_002D7d98_002D4f5a_002Dafeb_002Dea44ad98c70c/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Instance" AccessRightKinds="Private" Description="Instance fields (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="FIELD" /&gt;&lt;Kind Name="READONLY_FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=a0b4bc4d_002Dd13b_002D4a37_002Db37e_002Dc9c6864e4302/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Any" AccessRightKinds="Any" Description="Types and namespaces"&gt;&lt;ElementKinds&gt;&lt;Kind Name="NAMESPACE" /&gt;&lt;Kind Name="CLASS" /&gt;&lt;Kind Name="STRUCT" /&gt;&lt;Kind Name="ENUM" /&gt;&lt;Kind Name="DELEGATE" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EPredefinedNamingRulesToUserRulesUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=13FAEF5AD10371439A650EAFEB60E612/@KeyIndexDefined">True</s:Boolean>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=13FAEF5AD10371439A650EAFEB60E612/Applicability/=Live/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=13FAEF5AD10371439A650EAFEB60E612/Categories/=Imported_002010_002E10_002E2016/@EntryIndexedValue">Imported 10.10.2016</s:String>
Expand Down