Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## MarkX 0.1.3:

* Property Improvement:
* Late binding MarkX.DataSet (#44)
* New Properties:
* MarkX.Liquid ( #45 )
* MarkX.LiquidPattern ( #46 )

---


## MarkX 0.1.2:

Minor performance improvements:
Expand Down
13 changes: 7 additions & 6 deletions MarkX.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'MarkX.psm1'

# Version number of this module.
ModuleVersion = '0.1.2'
ModuleVersion = '0.1.3'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -63,12 +63,13 @@ PrivateData = @{

# ReleaseNotes of this module
ReleaseNotes = @'
## MarkX 0.1.2:
## MarkX 0.1.3:

Minor performance improvements:

* Directly using Markdig (#38)
* Preferring `[IO.File]::Exists` (#42)
* Property Improvement:
* Late binding MarkX.DataSet (#44)
* New Properties:
* MarkX.Liquid ( #45 )
* MarkX.LiquidPattern ( #46 )

---

Expand Down
242 changes: 152 additions & 90 deletions MarkX.types.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,94 +210,7 @@ $this |

if (-not $this.'#XML') { return }

$tables = $this.'#XML' | Select-Xml //table
filter innerText {
$in = $_
if ($in -is [string]) { "$in" }
elseif ($in.innerText) { "$($in.innerText)" }
elseif ($in.'#text') { "$($in.'#text')" }
}

function bestType {
$allIn = @($input) + @(if ($args) { $args})
switch ($true) {
{ $allIn -as [float[]] } {
[float]; break
}
{ $allIn -as [double[]] } {
[double]; break
}
{ $allIn -as [long[]] } {
[long]; break
}
{ $allIn -as [ulong[]] } {
[uint32]; break
}
{ $allIn -as [decimal[]] } {
[decimal]; break
}
{ $allIn -as [timespan[]] } {
[timespan]; break
}
{ $allIn -as [DateTime[]] } {
[DateTime]; break
}
default {
[string]
}
}
}

$markdownData = [Data.DataSet]::new('MarkX')
$tableNumber = 0
foreach ($table in $tables) {
$tableNumber++
$markdownDataTable = $markdownData.Tables.Add("MarkdownTable$tableNumber")

[string[]]$PropertyNames = @( $table.Node.thead.tr.th | innerText )

# We want to upcast our datatable as much as possible
# so we need to collect the rows first
$TableDictionary = [Ordered]@{}
$propertyIndex = 0
foreach ($property in $propertyNames) {
$TableDictionary[$property] = @(
foreach ($row in $table.Node.tbody.tr) {
@($row.td)[$propertyIndex] | innerText
}
)
$propertyIndex++
}

# Now that we have all of the data collected,
$markdownDataTable.Columns.AddRange(@(
foreach ($property in $propertyNames) {
$propertyIndex = 0
$bestType = $TableDictionary[$property] | bestType
[Data.DataColumn]::new($property, $bestType, '', 'Attribute')
}
[Data.DataColumn]::new('tr', [xml.xmlelement], '', 'Hidden')
))

foreach ($row in $table.Node.tbody.tr) {
$propertyValues = @(
$row.td | innerText
$row
)
$null = $markdownDataTable.Rows.Add($propertyValues)
}

$previous = $table.Node.PreviousSibling
if ($previous.LocalName -eq 'blockquote') {
$markdownDataTable.ExtendedProperties.Add("description", $previous.InnerText)
$previous = $previous.PreviousSibling
}
if ($previous.LocalName -match 'h[1-6]') {
$markdownDataTable.TableName = $previous.InnerText
}
}

$this | Add-Member NoteProperty '#DataSet' $markdownData -Force
$this.psobject.Properties.Remove('#DataSet')

</Script>
</ScriptMethod>
Expand Down Expand Up @@ -474,7 +387,99 @@ return $codeByLanguage
<ScriptProperty>
<Name>DataSet</Name>
<GetScriptBlock>
return $this.'#DataSet'
if ($this.'#DataSet') {return $this.'#DataSet' }

$tables = $this.'#XML' | Select-Xml //table
filter innerText {
$in = $_
if ($in -is [string]) { "$in" }
elseif ($in.innerText) { "$($in.innerText)" }
elseif ($in.'#text') { "$($in.'#text')" }
}

function bestType {
$allIn = @($input) + @(if ($args) { $args})
switch ($true) {
{ $allIn -as [float[]] } {
[float]; break
}
{ $allIn -as [double[]] } {
[double]; break
}
{ $allIn -as [long[]] } {
[long]; break
}
{ $allIn -as [ulong[]] } {
[uint32]; break
}
{ $allIn -as [decimal[]] } {
[decimal]; break
}
{ $allIn -as [timespan[]] } {
[timespan]; break
}
{ $allIn -as [DateTime[]] } {
[DateTime]; break
}
default {
[string]
}
}
}

$markdownData = [Data.DataSet]::new('MarkX')
$tableNumber = 0
foreach ($table in $tables) {
$tableNumber++
$markdownDataTable = $markdownData.Tables.Add("MarkdownTable$tableNumber")

[string[]]$PropertyNames = @( $table.Node.thead.tr.th | innerText )

# We want to upcast our datatable as much as possible
# so we need to collect the rows first
$TableDictionary = [Ordered]@{}
$propertyIndex = 0
foreach ($property in $propertyNames) {
$TableDictionary[$property] = @(
foreach ($row in $table.Node.tbody.tr) {
@($row.td)[$propertyIndex] | innerText
}
)
$propertyIndex++
}

# Now that we have all of the data collected,
$markdownDataTable.Columns.AddRange(@(
foreach ($property in $propertyNames) {
$propertyIndex = 0
$bestType = $TableDictionary[$property] | bestType
[Data.DataColumn]::new($property, $bestType, '', 'Attribute')
}
[Data.DataColumn]::new('tr', [xml.xmlelement], '', 'Hidden')
))

foreach ($row in $table.Node.tbody.tr) {
$propertyValues = @(
$row.td | innerText
$row
)
$null = $markdownDataTable.Rows.Add($propertyValues)
}

$previous = $table.Node.PreviousSibling
if ($previous.LocalName -eq 'blockquote') {
$markdownDataTable.ExtendedProperties.Add("description", $previous.InnerText)
$previous = $previous.PreviousSibling
}
if ($previous.LocalName -match 'h[1-6]') {
$markdownDataTable.TableName = $previous.InnerText
}
}

$this | Add-Member NoteProperty '#DataSet' $markdownData -Force

return $this.'#DataSet'

</GetScriptBlock>
</ScriptProperty>
<ScriptProperty>
Expand Down Expand Up @@ -653,6 +658,55 @@ $markdownData = $this.DataSet
}
</GetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>Liquid</Name>
<GetScriptBlock>
&lt;#
.SYNOPSIS
Get Liquid
.DESCRIPTION
Get Liquid within the Markdown
#&gt;
if ($this.LiquidPattern -is [regex]) {
return $this.LiquidPattern.Matches("$($this.Markdown)")
}

</GetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>LiquidPattern</Name>
<GetScriptBlock>
&lt;#
.SYNOPSIS
Get the Liquid Pattern
.DESCRIPTION
Gets the regular expression pattern used to match Liquid tags.
#&gt;
param()
$liquidPattern = @(
'(?&gt;'
'\{\%\s{0,}'
'(?&lt;tag&gt;[^\%]+)'
'\s{0,}\%}'

'|'

'(?&lt;noescape&gt;\{{3})'
'(?&lt;expression&gt;[^\}]+)'
'\}{3}'

'|'

'\{{2}'
'(?&lt;expression&gt;[^\}]+)'
'\}{2}'
')'
) -join ''

return [Regex]::new($liquidPattern)

</GetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>Markdown</Name>
<GetScriptBlock>
Expand All @@ -670,7 +724,15 @@ $this.Input = $Markdown
<ScriptProperty>
<Name>Table</Name>
<GetScriptBlock>
$this.XML | Select-Xml -XPath '//table' | Select-Object -ExpandProperty Node
&lt;#
.SYNOPSIS
Gets any tables
.DESCRIPTION
Gets any tables present in the markdown
#&gt;
$this.XML |
Select-Xml -XPath '//table' |
Select-Object -ExpandProperty Node
</GetScriptBlock>
</ScriptProperty>
<ScriptProperty>
Expand Down
Loading
Loading