Including content¶
Inline strings get unwieldy fast. The include() helper loads content from disk or a URL so your slide bodies stay short.
From a local file¶
fun includeFromFile() {
kslides {
presentation {
markdownSlide {
content {
include("src/main/resources/slides/intro.md")
}
}
}
}
}
Paths are resolved relative to the working directory of the running program.
From a URL¶
fun includeFromUrl() {
kslides {
presentation {
markdownSlide {
content {
include("https://raw.githubusercontent.com/kslides/kslides/master/README.md")
}
}
}
}
}
Useful for pulling READMEs or shared snippets without copy-pasting.
With code snippets¶
include() plays well with codeSnippet { } — see Code snippets:
fun codeSnippetFromUrl() {
kslides {
presentation {
dslSlide {
content {
codeSnippet {
language = "kotlin"
highlightPattern = "1|3-5"
code = include(
"https://raw.githubusercontent.com/kslides/kslides/master/kslides-examples/src/main/kotlin/playground/HelloWorld.kt",
)
}
}
}
}
}
}
Best practices¶
- Keep slide bodies in source-controlled files (
src/main/resources/slides/...) so reviewers can diff them. - Use URL includes for content owned by other repos to avoid duplication, but be mindful of network availability at build time.
Escaping¶
include() escapes markup so the file's contents render as text rather than being interpreted.
Which escaping applies is decided by the block you call it from, not by you: a markdownSlide, a
dslSlide, and a <code> block each escape their own output, so kslides hands them the content
raw; an htmlSlide is parsed as markup, so there the content is escaped on the way in.
The overloads are resolved by the enclosing receiver, so the same call is correct everywhere. One
caveat: that resolution is lexical. If you factor a content{} body out into a helper function,
the call leaves the receiver and reverts to the escaping form — keep interpolated include() calls
inside the block.