markdown 字段与方法 字段是关于值的一个普通事实,用点号读取,不需要方括号:$value.name。方法会接收参数或执行操作,调用方式为 ->:$value->name(arguments),也可以把值通过管道传入:$value |> name(arguments)。
字段 来自 KScript.Document 这些需要 <import package="KScript.Document" />import KScript.Document 。参见 KScript.Document 。
首个字面匹配的从零开始的源偏移量,若无匹配则为 -1。
示例
.kscript XML 复制
<let name="notes" value="```markdown
# Notes
Some *ideas* for the launch.
```" />
<echo>{ $notes->find('ideas') }</echo>.kscript XML 复制
$notes = ```markdown
# Notes
Some *ideas* for the launch.
```
echo $notes->find('ideas')返回一个副本,在从零开始的偏移位置插入相同格式的文本或源码。未指定偏移时则追加到末尾。
参数 接受 content 必填 任意值 at 可选 int
参数可以使用命名方式:->insert(…, at: …)。
示例
.kscript XML 复制
<let name="notes" value="```markdown
# Notes
Some *ideas* for the launch.
```" />
<echo>{ $notes->insert(' More soon.').text }</echo>.kscript XML 复制
$notes = ```markdown
# Notes
Some *ideas* for the launch.
```
echo $notes->insert(' More soon.').textPDF 文件的页数。
示例
.kscript XML 复制
<let name="notes" value="```markdown
# Notes
Some *ideas* for the launch.
```" />
<echo>{ $notes->pages() } pages</echo>.kscript XML 复制
$notes = ```markdown
# Notes
Some *ideas* for the launch.
```
echo "{ $notes->pages() } pages"# markdown ->replace (search: string , replacement: string ) → markdown KScript.Document 返回一个副本,其中每个字面匹配项都被替换。
参数可以使用命名方式:->replace(…, replacement: …)。
示例
.kscript XML 复制
<let name="notes" value="```markdown
# Notes
Some *ideas* for the launch.
```" />
<echo>{ $notes->replace('ideas', 'plans').text }</echo>.kscript XML 复制
$notes = ```markdown
# Notes
Some *ideas* for the launch.
```
echo $notes->replace('ideas', 'plans').text# markdown ->save (path: string , as?: pdf|docx|'latex'|'markdown'|html ) KScript.Document 将文档写入文件。文件扩展名(或 as:)决定格式:.md 保留源码,.pdf、.docx、.tex 或 .html 则进行渲染。若无扩展名,则默认为 .md。
参数 接受 path 必需 string as 可选 以下词之一:pdf|docx|'latex'|'markdown'|html
参数可以使用命名方式:->save(…, as: …)。
示例
.kscript XML 复制
<let name="notes" value="```markdown
# Notes
Some *ideas* for the launch.
```" />
<do>$notes->save('notes.pdf')</do>
<do>$notes->save('notes.docx')</do>.kscript XML 复制
$notes = ```markdown
# Notes
Some *ideas* for the launch.
```
$notes->save('notes.pdf')
$notes->save('notes.docx')文本的字数(不计数学公式和代码)。
示例
.kscript XML 复制
<let name="notes" value="```markdown
# Notes
Some *ideas* for the launch.
```" />
<echo>{ $notes->words() } words</echo>.kscript XML 复制
$notes = ```markdown
# Notes
Some *ideas* for the launch.
```
echo "{ $notes->words() } words"来自 any 的方法