【发布时间】:2023-02-14 06:15:14
【问题描述】:
我对使用 ConvertFrom-Markdown cmdlet 来解析降价表中的值很感兴趣。该 cmdlet 使用 markdig markdown 处理器,它有一个 Abstract Syntax Tree 应该能够为此目的被遍历。
我们如何在以下 powershell sn-p 中搜索/枚举令牌以返回行和列?
(@'
# header1
## header2
| Column1 | Column2 |
| ------- | ------- |
| Row1Column1 | Row1Column2 |
| Row2Column1 | Ro2Column2 |
'@ | ConvertFrom-Markdown).Tokens
我在令牌中看到的值看起来很有希望,我可以在 Parent 字段中看到 Markdig.Extensions.Tables.TableCell,但这是我所能得到的。
【问题讨论】:
-
使用这个
ConvertFrom-SourceTable:$YourMD | ConvertFrom-SourceTable -
为降价创建变量:$input = @' Your table '@.然后(没有标记): $table = $input | ConvertFrom-Markdown。现在你有了一个 Markdown 表格。代币只会让你得到代币。该 cmdlet 将返回一个 c# 类,因为 PS 是用 c# 编写的。因此,您应该能够调用 c# 类中的任何方法,例如 $table.Parse(sourceText, pipeline)。您可能需要将 PS 对象转换为它们的 c# 类型,例如 $table.Parse([string]sourceText, pipeline)
标签: powershell markdown