Skip to content

Commit fccd31f

Browse files
committed
version 1.3.0
with basic support of css to style elements
1 parent 90db61c commit fccd31f

File tree

6 files changed

+66
-8
lines changed

6 files changed

+66
-8
lines changed

.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
"-p..\\AzureDevOps.WikiPDFExport.Test\\Tests\\Real",
1717
"-h",
1818
"-b",
19-
"-d",
19+
"--debug",
2020
"--pathToHeading",
2121
"--header-left=LEFT page: [page] of [topage]",
2222
"--header-center=CENTER [section]",
2323
"--header-right=RIGHT [date]",
2424
"--footer-left=LEFT [subsection]",
2525
"--footer-center=CENTER [DATE]",
2626
"--footer-right=RIGHT page: [page] of [topage]",
27+
"--css=..\\AzureDevOps.WikiPDFExport.Test\\Tests\\Real\\styles.css"
2728
//"-s..\\AzureDevOps.WikiPDFExport.Test\\Tests\\Real\\AzureDevOps.WikiPDFExport\\TEST%2DPAGE.md"
2829
],
2930
"cwd": "${workspaceFolder}/AzureDevOps.WikiPDFExport",

AzureDevOps.WikiPDFExport/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,7 @@ public class Options
6262
[Option("header-right", Required = false, HelpText = "Text in the header on the right, supports placeholders")]
6363
public string HeaderRight { get; set; }
6464

65+
[Option("css", Required = false, HelpText = "Path to a css file that is used for styling the PDF")]
66+
public string CSS { get; set; }
6567
}
6668
}

AzureDevOps.WikiPDFExport/WikiPDFExporter.cs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ public void Export()
8282

8383
var html = ConvertMarkdownToHTML(files);
8484

85+
if (!string.IsNullOrEmpty(_options.CSS))
86+
{
87+
html = AddCssStyles(html);
88+
}
89+
90+
if (_options.Debug)
91+
{
92+
var htmlPath = Path.Combine(_path, "html.html");
93+
Log($"Writing converted html to path: {htmlPath}");
94+
File.WriteAllText(htmlPath, html);
95+
}
96+
8597
ConvertHTMLToPDF(html);
8698

8799
Console.ForegroundColor = ConsoleColor.Green;
@@ -101,6 +113,25 @@ public void Export()
101113
}
102114
}
103115

116+
private string AddCssStyles(string html)
117+
{
118+
var path = Path.GetFullPath(_options.CSS);
119+
120+
if (!File.Exists(path))
121+
{
122+
return html;
123+
}
124+
125+
var styles = File.ReadAllText(path);
126+
127+
var start = $"<style>";
128+
var stop = $"</style>";
129+
130+
html = start + styles + stop + html;
131+
132+
return html;
133+
}
134+
104135
private void ConvertHTMLToPDF(string html)
105136
{
106137
Log("Converting HTML to PDF");
@@ -179,7 +210,7 @@ private string ConvertMarkdownToHTML(List<MarkdownFile> files)
179210
{
180211
// write the HTML output
181212
var renderer = new HtmlRenderer(writer);
182-
pipeline.Setup(renderer);
213+
pipeline.Setup(renderer);
183214
renderer.Render(document);
184215
}
185216
html = builder.ToString();
@@ -235,12 +266,7 @@ private string ConvertMarkdownToHTML(List<MarkdownFile> files)
235266

236267
var result = sb.ToString();
237268

238-
if (_options.Debug)
239-
{
240-
var htmlPath = Path.Combine(_path, "html.html");
241-
Log($"Writing converted html to path: {htmlPath}");
242-
File.WriteAllText(htmlPath, result);
243-
}
269+
244270
return result;
245271
}
246272

azuredevops-export-wiki.exe

301 Bytes
Binary file not shown.

export.pdf

-9.98 KB
Binary file not shown.

styles.css

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
body
2+
{
3+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
4+
font-size: 10pt;
5+
}
6+
7+
h1
8+
{
9+
font-size: 25pt;
10+
color: red;
11+
}
12+
13+
h2
14+
{
15+
font-size: 20pt;
16+
color: blue;
17+
}
18+
19+
h3
20+
{
21+
font-size: 15pt;
22+
color: green;
23+
}
24+
25+
h4
26+
{
27+
font-size: 12pt;
28+
color: pink;
29+
}

0 commit comments

Comments
 (0)