Skip to content

Commit e09ad3a

Browse files
author
James Brundage
committed
Adding Inline Latex/Tex Transpiler (Fixes #230)
1 parent 889ab86 commit e09ad3a

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<#
2+
.SYNOPSIS
3+
Latex Inline PipeScript Transpiler.
4+
.DESCRIPTION
5+
Transpiles Latex with Inline PipeScript into Latex.
6+
7+
Multiline comments with %{}% will be treated as blocks of PipeScript.
8+
#>
9+
[ValidatePattern('\.(?>latex|tex)$')]
10+
param(
11+
# The command information. This will include the path to the file.
12+
[Parameter(Mandatory,ValueFromPipeline)]
13+
[Management.Automation.CommandInfo]
14+
$CommandInfo,
15+
16+
# A dictionary of parameters.
17+
[Collections.IDictionary]
18+
$Parameter,
19+
20+
# A list of arguments.
21+
[PSObject[]]
22+
$ArgumentList
23+
)
24+
25+
begin {
26+
# We start off by declaring a number of regular expressions:
27+
$startComment = '\%\{' # * Start Comments ```%{```
28+
$endComment = '\}\%' # * End Comments ```}%```
29+
$Whitespace = '[\s\n\r]{0,}'
30+
$startRegex = "(?<PSStart>${startComment})"
31+
$endRegex = "(?<PSEnd>${endComment}\s{0,})"
32+
33+
# Create a splat containing arguments to the core inline transpiler
34+
$Splat = [Ordered]@{
35+
StartPattern = $startRegex
36+
EndPattern = $endRegex
37+
}
38+
}
39+
40+
process {
41+
# Add parameters related to the file
42+
$Splat.SourceFile = $commandInfo.Source -as [IO.FileInfo]
43+
$Splat.SourceText = [IO.File]::ReadAllText($commandInfo.Source)
44+
if ($Parameter) { $splat.Parameter = $Parameter }
45+
if ($ArgumentList) { $splat.ArgumentList = $ArgumentList }
46+
47+
# Call the core inline transpiler.
48+
.>PipeScript.Inline @Splat
49+
}

0 commit comments

Comments
 (0)