-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConvertToMarkdown.ps1
60 lines (37 loc) · 2.24 KB
/
ConvertToMarkdown.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 0.2 2021-04-11
# cd .\Dropbox\Documents\VisualStudio\LinkAggregatorTutorial
param([switch]$gist)
(Get-Content .\LinkAggregatorTutorial.ps1 -Raw) -replace '(?s)# IGNORE-START.*?# IGNORE-END', '' | Set-Content pass-1.ps1
(Get-Content .\pass-1.ps1 -Raw) -replace "\`$file = '(.*?)'", ("`n---`n" + 'File: `$1`') | Set-Content pass-1.ps1
# Explanation of (?s) in regex below
# https://stackoverflow.com/a/12573413/268581
(Get-Content .\pass-1.ps1 -Raw) -replace '(?s)\$original_text = @"(.*?)"@', ("Original text: `n" + '```$1```') | Set-Content pass-1.ps1
(Get-Content .\pass-1.ps1 -Raw) -replace '(?s)\$replacement_text = @"(.*?)"@', ("Replacement text: `n" + '```$1```') | Set-Content pass-1.ps1
# (Get-Content .\pass-1.ps1 -Raw) -replace ('(?s)^@"(.*?)"@ \| ' + "Set-Content '(.*?)'"), ('File: `$2`' + "`n`n" + '```$1```') | Set-Content pass-1.ps1
# (Get-Content .\pass-1.ps1 -Raw) -replace ('(?s)@"(.*?)"@ \| ' + "Set-Content '(.*?)'"), ('File: `$2`' + "`n`n" + '```$1```') | Set-Content pass-1.ps1
# (?sm)
# s use single-line mode
# m use multiline mode
# (.*?)
# . any character
# *? zero or more times, but as few times as possible
(Get-Content .\pass-1.ps1 -Raw) -replace ('(?sm)^@"(.*?)"@ \| ' + "Set-Content '(.*?)'"), ('File: `$2`' + "`n`n" + '```$1```') | Set-Content pass-1.ps1
# diff
(Get-Content .\pass-1.ps1 -Raw) -replace '(?sm)^@"(.*?)"@ \| git apply --whitespace=nowarn', ('```diff $1```') | Set-Content pass-1.ps1
# (Get-Content .\pass-1.ps1 -Raw) -replace '(?sm)^@"(.*?)"@ \| git apply', ('```diff $1```') | Set-Content pass-1.ps1
(Get-Content .\pass-1.ps1) | ForEach-Object {
if ($_ -match '^# ') { $_ -replace '^# ', '' }
elseif ($_ -match '^#') { $_ -replace '^#', '' }
elseif ($_ -match "^cmt '") { $_ -replace "^cmt '(.*)'", '$1' }
elseif ($_ -match '^cmt "') { $_ -replace '^cmt "(.*)"', '$1' }
elseif ($_ -match '^Edit \$file -Replacing') { }
elseif ($_ -match 'IGNORE-LINE-FOR-MARKDOWN') { }
else { $_ }
} | Set-Content LinkAggregatorTutorial.md
if ($gist)
{
$result = gh gist create LinkAggregatorTutorial.md
Start-Process $result
}
Remove-Item .\pass-1.ps1