Skip to content

Commit ae5c43e

Browse files
author
James Brundage
committed
Adding Markdown Formatting (#40). Adding Inline OpenSCAD (#41)
1 parent 4d86617 commit ae5c43e

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

Formatting/Markdown.format.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Write-FormatView -TypeName Markdown -Action {
2+
$thisObject = $_
3+
if ($thisObject -is [string]) {
4+
$thisObject
5+
}
6+
elseif ($thisObject.Table) {
7+
$thisObject.Table | Format-Markdown
8+
}
9+
elseif ($thisObject.InputObject) {
10+
$thisObject.InputObject | Format-Markdown
11+
}
12+
elseif ($thisObject.psobject.Properties.Length) {
13+
$thisObject | Format-Markdown
14+
} else {
15+
''
16+
}
17+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<#
2+
.SYNOPSIS
3+
OpenSCAD Inline PipeScript Transpiler.
4+
.DESCRIPTION
5+
Transpiles OpenSCAD with Inline PipeScript into OpenSCAD.
6+
7+
Multiline comments with /*{}*/ will be treated as blocks of PipeScript.
8+
9+
Multiline comments can be preceeded or followed by 'empty' syntax, which will be ignored.
10+
11+
This for Inline PipeScript to be used with operators, and still be valid OpenSCAD syntax.
12+
13+
The OpenSCAD Inline Transpiler will consider the following syntax to be empty:
14+
15+
* ```"[^"]+"```
16+
* ```[\d\.]+```
17+
.EXAMPLE
18+
.> {
19+
$OpenScadWithInlinePipeScript = @'
20+
Shape = "cube" /*{'"cube"', '"sphere"', '"circle"' | Get-Random}*/;
21+
Size = 1 /*{Get-Random -Min 1 -Max 100}*/ ;
22+
23+
if (Shape == "cube") {
24+
cube(Size);
25+
}
26+
if (Shape == "sphere") {
27+
sphere(Size);
28+
}
29+
if (Shape == "circle") {
30+
circle(Size);
31+
}
32+
'@
33+
34+
[OutputFile(".\RandomShapeAndSize.ps1.scad")]$OpenScadWithInlinePipeScript
35+
}
36+
37+
.> .\RandomShapeAndSize.ps1.scad
38+
#>
39+
[ValidateScript({
40+
$cmdInfo = $_
41+
if ($cmdInfo.Source -match '\.scad$') {
42+
return $true
43+
}
44+
return $false
45+
})]
46+
param(
47+
# The command information. This will include the path to the file.
48+
[Parameter(Mandatory,ValueFromPipeline)]
49+
$CommandInfo
50+
)
51+
52+
begin {
53+
# We start off by declaring a number of regular expressions:
54+
$startComment = '/\*' # * Start Comments ```\*```
55+
$endComment = '\*/' # * End Comments ```/*```
56+
$Whitespace = '[\s\n\r]{0,}'
57+
# * IgnoredContext ```String.empty```, ```null```, blank strings and characters
58+
$IgnoredContext = "(?<ignore>(?>$('[\d\.]+','"[^"]+"' -join '|'))\s{0,}){0,1}"
59+
# * StartRegex ```$IgnoredContext + $StartComment + '{' + $Whitespace```
60+
$startRegex = "(?<PSStart>${IgnoredContext}${startComment}\{$Whitespace)"
61+
# * EndRegex ```$whitespace + '}' + $EndComment + $ignoredContext```
62+
$endRegex = "(?<PSEnd>$Whitespace\}${endComment}\s{0,}${IgnoredContext})"
63+
64+
$sourcePattern = [Regex]::New("(?>$(
65+
$startRegex, $endRegex -join ([Environment]::NewLine + '|' + [Environment]::NewLine)
66+
))", "IgnoreCase, IgnorePatternWhitespace", "00:00:05")
67+
}
68+
69+
process {
70+
71+
$fileInfo = $commandInfo.Source -as [IO.FileInfo]
72+
$fileText = [IO.File]::ReadAllText($fileInfo.Fullname)
73+
74+
.>PipeScript.Inline -SourceFile $CommandInfo.Source -SourceText $fileText -SourcePattern $sourcePattern
75+
}
76+

0 commit comments

Comments
 (0)