-
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
Шевырин Никита #229
Open
alexadralt
wants to merge
27
commits into
kontur-courses:master
Choose a base branch
from
alexadralt:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Шевырин Никита #229
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
883f607
created project Markdown
alexadralt c1f6b4d
initial design
alexadralt 09601ae
initial design
alexadralt f27204e
added ArgumentExceptionHelpers
alexadralt bc62038
implemented abstract syntax tree
alexadralt f0d106e
did some syntax tree testing
alexadralt 106f113
tokenizer WIP
alexadralt 8de5081
addded tests for Md
alexadralt 6e53af2
deleted tree tests
alexadralt b67b916
added usage example
alexadralt ae81615
implementation WIP 1
alexadralt 9005981
renamed IMdTest to IMdTests
alexadralt 1ef1aa0
renamed files for refactoring
alexadralt 887266f
refactored the whole thing
alexadralt 5be7d46
added nesting syntax rule
alexadralt 90e83aa
refactored nesting rule
alexadralt f106f80
added new syntax rules and fixed potential bugs
alexadralt 8b6a4d8
added descriptions to tests
alexadralt 8efaaf3
deleted files with old version of existing code
alexadralt 8549226
removed old files
alexadralt b5df139
merged version 1.0
alexadralt f298b01
deleted old files
alexadralt 9f42573
added factory method for Md
alexadralt 75251ad
refactored MdTokenizer
alexadralt 262d9a2
refactored syntax rules
alexadralt f7be964
moved private fields declarations
alexadralt 96b2796
moved performance tests to a different project and added more test cases
alexadralt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
| ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Markdown", "Markdown\Markdown.csproj", "{B8FD8A48-C2C3-434B-953F-B9AF324E3E95}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{B8FD8A48-C2C3-434B-953F-B9AF324E3E95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{B8FD8A48-C2C3-434B-953F-B9AF324E3E95}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{B8FD8A48-C2C3-434B-953F-B9AF324E3E95}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{B8FD8A48-C2C3-434B-953F-B9AF324E3E95}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Markdown; | ||
|
||
public interface IMd | ||
{ | ||
public string Render(string markdown); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Text; | ||
using Markdown.TokenConverters; | ||
using Markdown.Tokenizers; | ||
using Markdown.Tokens; | ||
|
||
namespace Markdown; | ||
|
||
public class Md : IMd | ||
{ | ||
private readonly ITokenizer[] _tokenizers = | ||
{ | ||
new BoldTokenizer(), | ||
new ItalicTokenizer(), | ||
new HeadingTokenizer() | ||
}; | ||
private readonly ITokenConverter[] _converters = | ||
{ | ||
new BoldHtmlConverter(), | ||
new ItalicHtmlConverter(), | ||
new HeadingHtmlConverter() | ||
}; | ||
|
||
private readonly int _sliceSize = 1024; | ||
|
||
public string Render(string markdown) | ||
{ | ||
var markdownSpan = markdown.AsSpan(); | ||
var context = new StringBuilder(); | ||
var stepCount = markdownSpan.Length / _sliceSize; | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
stepCount = markdownSpan.Length % _sliceSize == 0 ? stepCount : stepCount + 1; | ||
var tokenList = new List<Token>(); | ||
for (var step = 0; step < stepCount; step++) | ||
{ | ||
var sliceStart = step * _sliceSize; | ||
var sliceSize = Math.Min(_sliceSize, markdownSpan.Length - sliceStart); | ||
var stepSpan = markdownSpan.Slice(sliceStart, sliceSize); | ||
foreach (var tokenizer in _tokenizers) | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
tokenList.AddRange(tokenizer.Tokenize(stepSpan)); | ||
foreach (var converter in _converters) | ||
converter.ProcessTokens(tokenList, context); | ||
tokenList.Clear(); | ||
} | ||
|
||
return context.ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Text; | ||
using Markdown.Tokens; | ||
|
||
namespace Markdown.TokenConverters; | ||
|
||
public class BoldHtmlConverter : HtmlTokenConverter | ||
{ | ||
protected override MarkdownTokenType MarkdownTokenType { get; } = MarkdownTokenType.ToBold; | ||
public override void ProcessTokens(IEnumerable<Token> tokens, StringBuilder context) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Text; | ||
using Markdown.Tokens; | ||
|
||
namespace Markdown.TokenConverters; | ||
|
||
public class HeadingHtmlConverter : HtmlTokenConverter | ||
{ | ||
protected override MarkdownTokenType MarkdownTokenType { get; } = MarkdownTokenType.ToHeading; | ||
public override void ProcessTokens(IEnumerable<Token> tokens, StringBuilder context) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Text; | ||
using Markdown.Tokens; | ||
|
||
namespace Markdown.TokenConverters; | ||
|
||
public abstract class HtmlTokenConverter : ITokenConverter | ||
{ | ||
protected IEnumerable<Token>? TokensOnPreviousSlice { get; set; } | ||
protected abstract MarkdownTokenType MarkdownTokenType { get; } | ||
public abstract void ProcessTokens(IEnumerable<Token> tokens, StringBuilder context); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Text; | ||
using Markdown.Tokens; | ||
|
||
namespace Markdown.TokenConverters; | ||
|
||
public interface ITokenConverter | ||
{ | ||
public void ProcessTokens(IEnumerable<Token> tokens, StringBuilder context); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Text; | ||
using Markdown.Tokens; | ||
|
||
namespace Markdown.TokenConverters; | ||
|
||
public class ItalicHtmlConverter : HtmlTokenConverter | ||
{ | ||
protected override MarkdownTokenType MarkdownTokenType { get; } = MarkdownTokenType.ToItalic; | ||
public override void ProcessTokens(IEnumerable<Token> tokens, StringBuilder context) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Markdown.Tokens; | ||
|
||
namespace Markdown.Tokenizers; | ||
|
||
public class BoldTokenizer : MarkdownTokenizer | ||
{ | ||
protected override MarkdownTokenType MarkdownTokenType { get; } = MarkdownTokenType.ToBold; | ||
|
||
public override IEnumerable<Token> Tokenize(ReadOnlySpan<char> input) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Markdown.Tokens; | ||
|
||
namespace Markdown.Tokenizers; | ||
|
||
public class HeadingTokenizer : MarkdownTokenizer | ||
{ | ||
protected override MarkdownTokenType MarkdownTokenType { get; } = MarkdownTokenType.ToHeading; | ||
|
||
public override IEnumerable<Token> Tokenize(ReadOnlySpan<char> input) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Markdown.Tokens; | ||
|
||
namespace Markdown.Tokenizers; | ||
|
||
public interface ITokenizer | ||
{ | ||
public IEnumerable<Token> Tokenize(ReadOnlySpan<char> input); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Text; | ||
using Markdown.Tokens; | ||
|
||
namespace Markdown.Tokenizers; | ||
|
||
public class ItalicTokenizer : MarkdownTokenizer | ||
{ | ||
protected override MarkdownTokenType MarkdownTokenType { get; } = MarkdownTokenType.ToItalic; | ||
|
||
public override IEnumerable<Token> Tokenize(ReadOnlySpan<char> input) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Text; | ||
using Markdown.Tokens; | ||
|
||
namespace Markdown.Tokenizers; | ||
|
||
public abstract class MarkdownTokenizer : ITokenizer | ||
{ | ||
protected abstract MarkdownTokenType MarkdownTokenType { get; } | ||
public abstract IEnumerable<Token> Tokenize(ReadOnlySpan<char> input); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Markdown.Tokens; | ||
|
||
public enum MarkdownTokenType | ||
{ | ||
NoConversion, | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
ToItalic, | ||
ToBold, | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
ToHeading | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Markdown.Tokens; | ||
|
||
public readonly struct Token( | ||
ReadOnlyMemory<char> content, | ||
MarkdownTokenType markdownTokenType, | ||
int startIndex, | ||
int endIndex) | ||
{ | ||
public ReadOnlyMemory<char> Content { get; } = content; | ||
public MarkdownTokenType MarkdownTokenType { get; } = markdownTokenType; | ||
public int StartIndex { get; } = startIndex; | ||
public int EndIndex { get; } = endIndex; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as resolved.
Sorry, something went wrong.