-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
95 additions
and
6 deletions.
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,76 @@ | ||
using System.Text; | ||
|
||
namespace Stratis.DevEx.Drawing | ||
{ | ||
|
||
public abstract class HighlightedCode | ||
{ | ||
#region Constructors | ||
public HighlightedCode(string lang, string code) | ||
{ | ||
Lang = lang; | ||
Code = code; | ||
} | ||
#endregion | ||
|
||
#region Properties | ||
public string Lang { get; set; } | ||
public string Code { get; set; } | ||
#endregion | ||
|
||
#region Methods | ||
public abstract string Draw(string id); | ||
#endregion | ||
|
||
#region Overriden members | ||
public override string ToString() | ||
{ | ||
return Code; | ||
} | ||
#endregion | ||
} | ||
|
||
public class TmHighlightedCode : HighlightedCode | ||
{ | ||
#region Constructors | ||
public TmHighlightedCode(string lang, string code) : base(lang, code) | ||
{ | ||
|
||
|
||
} | ||
#endregion | ||
|
||
#region Methods | ||
public override string Draw(string id) | ||
{ | ||
var html = new StringBuilder(); | ||
html.AppendLine($"<div id=\"{id}\">"); | ||
html.AppendLine("</div>"); | ||
html.AppendLine($"<script>if (highlighter === undefined) {{console.error('Shiki not loaded yet!. Run the notebook init script.')}} else {{$('#{id}').html(highlighter.codeToHtml(\"{(this.Code)}\", \"{this.Lang}\", \"light-plus\"));}}</script>"); | ||
return html.ToString(); | ||
} | ||
#endregion | ||
} | ||
|
||
public class PrismHighlightedCode : HighlightedCode | ||
{ | ||
#region Constructors | ||
public PrismHighlightedCode(string lang, string code) : base(lang, code) | ||
{ | ||
|
||
} | ||
#endregion | ||
|
||
#region Methods | ||
public override string Draw(string id) | ||
{ | ||
var html = new StringBuilder(); | ||
html.AppendLine($"<div id=\"{id}\" class=\"language-{Lang}\">"); | ||
html.AppendLine(Code); | ||
html.Append("</div>"); | ||
return html.ToString(); | ||
} | ||
#endregion | ||
} | ||
} | ||
|
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
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