Skip to content

Commit

Permalink
Update feature language
Browse files Browse the repository at this point in the history
  • Loading branch information
“hphan9” committed Sep 30, 2021
1 parent 9cd048c commit f9943a5
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 45 deletions.
Binary file modified .vs/shinny-ssg/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file modified .vs/shinny-ssg/v16/.suo
Binary file not shown.
87 changes: 45 additions & 42 deletions Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,54 @@
namespace shinny_ssg
{

class Page
{
private string _head;
private string _title;
private string _body;
private string _cssString;
public Page() { }
public Page(string text)
class Page
{
var paraps = Regex.Split(text, "\r?\n\r?\n");
//first line is _title
_title = paraps[0];
_cssString = String.IsNullOrEmpty(Globals.cssUrl)
? "<style type ='text/css'> body { display: block;max-width: 800px; margin: 20px auto; padding: 0 10px; word-wrap: break-word }</style >"
: $"<link rel =\"stylesheet\"href =\"{Globals.cssUrl}\" >";
private string _head;
private string _title;
private string _body;
private string _cssString;
private string _lang;
public Page() { }
public Page(string text)
{
var paraps = Regex.Split(text, "\r?\n\r?\n");
//first line is _title
_title = paraps[0];
_cssString = String.IsNullOrEmpty(Globals.cssUrl)
? "<style type ='text/css'> body { display: block;max-width: 800px; margin: 20px auto; padding: 0 10px; word-wrap: break-word }</style >"
: $"<link rel =\"stylesheet\"href =\"{Globals.cssUrl}\" >";
_lang = String.IsNullOrEmpty(Globals.langAtr)
? "lang= \"en-CA\""
: $"lang= \"{Globals.langAtr}\"";
_head = $"<meta charset = \"utf-8\" >" +
_cssString +
$"<title >{_title} </title >" +
$"<meta name = \"viewport\" content = \"width=device-width, initial-scale=1\">";
_body += $"<h1>{_title}</h1>";
for (var i = 1; i < paraps.Length; i++)
{
var temp = Regex.Replace(paraps[i], "\r?\n", " ");
temp = this.ParseMarkdownLine(temp);
_body += $"<p>{temp}</p>";
}
}

_head = $"<meta charset = \"utf-8\" >" +
_cssString +
$"<title >{_title} </title >" +
$"<meta name = \"viewport\" content = \"width=device-width, initial-scale=1\">";
_body += $"<h1>{_title}</h1>";
for (var i = 1; i < paraps.Length; i++)
{
var temp = Regex.Replace(paraps[i], "\r?\n", " ");
temp = this.ParseMarkdownLine(temp);
_body += $"<p>{temp}</p>";
}
}
public string GetPage()
{
//Creates a new file, write the contents to the file, and then closes the file. If the target file already exists, it is overwritten
return $"<!DOCTYPE html> <html {_lang}> <head> {_head} </head> <body>{_body}</body> </html>";
}

public string GetPage()
{
//Creates a new file, write the contents to the file, and then closes the file. If the target file already exists, it is overwritten
return $"<!DOCTYPE html> <html> <head> {_head} </head> <body>{_body}</body> </html>";
}

// Parse the markdown line into html
private string ParseMarkdownLine(string line)
{
// If aiming for performance,
// ...use named groups and try to match italic, underline, etc.
// This matches anything between double asterisks
string boldPattern = @"\*\*(.*?)\*\*";
string boldReplacement = "<strong>$1</strong>";
// Parse the markdown line into html
private string ParseMarkdownLine(string line)
{
// If aiming for performance,
// ...use named groups and try to match italic, underline, etc.
// This matches anything between double asterisks
string boldPattern = @"\*\*(.*?)\*\*";
string boldReplacement = "<strong>$1</strong>";

return Regex.Replace(line, boldPattern, boldReplacement);
return Regex.Replace(line, boldPattern, boldReplacement);
}
}
}
}
11 changes: 8 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace shinny_ssg
static class Globals
{
public static string cssUrl;
public static string langAtr;
}

class Program
Expand All @@ -23,16 +24,19 @@ static void Main(string[] args)
//help option
app.HelpOption();
app.VersionOption("-v|--version", "0.1", "Shinny SSG 0.1");
var inputFileOption = app.Option<string>("-i|--input", "Input file/folder to convert to HTML", CommandOptionType.SingleValue)
var inputFileOption = app.Option<string>("-i|--input", "Input file/folder to convert source file to HTML", CommandOptionType.SingleValue)
.IsRequired();
var outputOption = app.Option<string>("-o|--output", "Output folder for converted file", CommandOptionType.SingleValue);
var cssOption = app.Option<string>("---stylesheet| -s", "Style Sheet for the HTML file", CommandOptionType.SingleValue);
var outputOption = app.Option<string>("-o|--output", "Output folder for converted file/files", CommandOptionType.SingleValue);
var cssOption = app.Option<string>("--stylesheet| -s", "Style Sheet for the converted HTML file", CommandOptionType.SingleValue);
//language option
var langOption = app.Option<string>("-l|--lang", "Language Attribute of the converted HTML file", CommandOptionType.SingleValue);
//on excute

app.OnExecute(() =>
{
var inputname = inputFileOption.Value();
Globals.cssUrl = cssOption.HasValue() ? cssOption.Value() : null;
Globals.langAtr = langOption.HasValue() ? langOption.Value() : null;
if (outputOption.HasValue() && Directory.Exists(outputOption.Value()))
{
destination = outputOption.Value();
Expand All @@ -51,6 +55,7 @@ static void Main(string[] args)
}

}

if (File.Exists(inputname) && (inputname.EndsWith(".txt") || inputname.EndsWith(".md")))
{
//if the file can not read or create , it will never be saved in the destinaiton folder
Expand Down
8 changes: 8 additions & 0 deletions Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"shinny-ssg": {
"commandName": "Project",
"commandLineArgs": "-i C:\\Users\\khoit\\Desktop\\OSD600\\Sherlock-Holmes-Selected-Stories -l fr"
}
}
}
1 change: 1 addition & 0 deletions bin/Debug/netcoreapp3.1/dist/Silver Blaze.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions bin/Debug/netcoreapp3.1/dist/The Naval Treaty.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions bin/Debug/netcoreapp3.1/dist/The Red Headed League.html

Large diffs are not rendered by default.

Binary file modified bin/Debug/netcoreapp3.1/shinny-ssg.dll
Binary file not shown.
Binary file modified bin/Debug/netcoreapp3.1/shinny-ssg.pdb
Binary file not shown.
Binary file modified obj/Debug/netcoreapp3.1/shinny-ssg.csprojAssemblyReference.cache
Binary file not shown.
Binary file modified obj/Debug/netcoreapp3.1/shinny-ssg.dll
Binary file not shown.
Binary file modified obj/Debug/netcoreapp3.1/shinny-ssg.pdb
Binary file not shown.

0 comments on commit f9943a5

Please sign in to comment.