문서의 컴포넌트
컴포넌트는 문서의 일부가 될 수 있어요: 발견 사항, 방법, 서명 블록 등이 여기에 해당해요. 그 render에는 문서 요소가 담기거나, Markdown 또는 LaTeX로 작성된 부분을 반환해요.
<import package="KScript.Document" />
<type name="Panel" extends="Component">
<construct>
<field name="heading" type="string" />
</construct>
<fn name="render">
<Section title="{.heading}">
<slot />
</Section>
</fn>
</type>
<type name="Finding" extends="Component">
<construct>
<field name="title" type="string" />
<field name="count" type="int" />
</construct>
<fn name="render" value="```md
## {$title}
We saw **{$count}** of them in \( 10^{3} \) generations.
```" />
</type>
<type name="Method" extends="Component">
<construct>
<field name="name" type="string" />
<field name="share" type="string" />
</construct>
<fn name="render" value="```latex
\subsection{Method: {$name}}
We used \textbf{$name} on {$share} of the runs.
\begin{equation}
N(t) = N_0 e^{rt}
\end{equation}
```" />
</type>
<Document title="Gliders" into="report">
<Panel heading="Results">
<Finding title="Gliders" count="3" />
<Method name="counting" share="50%" />
</Panel>
</Document>
<echo value="$report->convert(to: markdown)" />import KScript.Document
type Panel extends Component {
construct({ heading: string })
fn render() {
Section(title: "{.heading}") {
slot
}
}
}
type Finding extends Component {
construct({ title: string, count: int })
fn render() => ```md
## {$title}
We saw **{$count}** of them in \( 10^{3} \) generations.
```
}
type Method extends Component {
construct({ name: string, share: string })
fn render() => ```latex
\subsection{Method: {$name}}
We used \textbf{$name} on {$share} of the runs.
\begin{equation}
N(t) = N_0 e^{rt}
\end{equation}
```
}
Document(title: "Gliders", into: report) {
Panel(heading: "Results") {
Finding(title: "Gliders", count: 3)
Method(name: "counting", share: "50%")
}
}
echo $report->convert(to: markdown)Document안에서 컴포넌트는 문서render를 사용해 그립니다. 추가하는 내용은 작성된 위치에 그대로 놓이므로,Section안에 있는 부분의 제목은 하위 섹션이 됩니다.slot는 요소를 담는render안에서 동작합니다. 블록은 텍스트만 담으므로 호출자의 내용을 넣을 곳이 없습니다.- 문서는 한 번 그려지므로, 그 안의 컴포넌트는 그리기 사이에 상태를 유지하지 않아요.
md블록에서{ }는Paragraph에서와 마찬가지로 값을 보관해요. 수학식은\( x^{2} \)와\[ x^{2} \]로 작성하며, 중괄호를 그대로 유지해요.latex블록에서 중괄호는 LaTeX의 것입니다.{$name}나{@today()}처럼 값만 담고 있는 그룹은 값으로 채워지며 중괄호를 그대로 유지하므로,\textbf{$name}는 굵은 글씨의 이름이 됩니다. 값은 이스케이프되므로, 그 안의%,&,_은 텍스트로 표시됩니다.- LaTeX 문서에서 보통 사용하는 방식으로 작성된 부분을
latex블록이 읽어요:
| LaTeX | 읽는 내용 |
|---|---|
| 구조 | \section, \subsection, \subsubsection(숫자가 없으면 *)및 \label |
| Text | \textbf, \textit, \emph, \texttt, \underline, \href, \url, \footnote, \cite, \ref, \\, ~, ``, '', --, ---, % 주석 |
| 수학 | $...$, \( \), \[ \], $$ $$, 그리고 equation, equation*, displaymath, align, align* 환경 |
| 블록 | itemize, enumerate, quote, quotation, center, verbatim 및 figure (\includegraphics, \caption 및 \label 포함) |
| 레이아웃 | \newpage, \clearpage, \tableofcontents, \hrule, \smallskip, \medskip, \bigskip 및 \par |
인식하지 못하는 명령은 그 이름을 밝히는 오류로 보고되므로, 아무 말 없이 빠지는 것은 없습니다. kscript check와 편집기가 그 위치에서 이를 보고합니다. 이 부분은 문서 요소로 작성하세요.