Documentation
¶
Overview ¶
Package content provides a system for making content-focused apps and websites consisting of Markdown, HTML, and Cogent Core.
Index ¶
- Variables
- func AddCompiledCode(code map[string]CodeFunc)
- func AddCompiledGoal(pages map[string]*GoalPage)
- func BindCode(ed *textcore.Editor, parent *core.Frame, language string)
- func CodeKey(src string) string
- func OpenHelp(ctx core.Widget, docs fs.FS)
- func SetAppHelp(docs fs.FS)
- func ShowCodeErrors(ed *textcore.Editor, parent *core.Frame, err error)
- type CodeFunc
- type Content
- func (ct *Content) Init()
- func (ct *Content) LoadEachPage(after func()) error
- func (ct *Content) MakeToolbar(p *tree.Plan)
- func (ct *Content) MakeToolbarPDF(p *tree.Plan)
- func (ct *Content) MakeToolbarSearch(p *tree.Plan)
- func (ct *Content) MenuSearch(items *[]core.ChooserItem)
- func (ct *Content) Open(url string) *Content
- func (ct *Content) OpenEvent(url string, e events.Event) *Content
- func (ct *Content) PagePDF(path string) error
- func (ct *Content) PageRefs(page *bcontent.Page) *core.Frame
- func (ct *Content) RenderWidget()
- func (ct *Content) SetContent(content fs.FS) *Content
- func (t *Content) SetReferences(v *csl.KeyList) *Content
- func (ct *Content) SetSource(source fs.FS) *Content
- type GoalBlock
- type GoalPage
- type History
- type Location
- type MountFS
- type SettingsData
Constants ¶
This section is empty.
Variables ¶
BindTextEditor is a function set to cogentcore.org/core/mvmcore.BindTextEditor when importing mvmcore, which provides interactive editing functionality for Go code blocks in text editors.
var CodeSymbols = map[string]any{}
CodeSymbols are values of the app, by name, that its code blocks use, such as embedded files. Compiled code (see CompiledCode) uses them from the app's package directly; interpreters (see BindTextEditor) add them to the names that code can use without a package, when they are first needed.
var CompiledCode = map[string]CodeFunc{}
CompiledCode maps the CodeKey of the source of a code block to the function compiled from it at build time. A code block whose source has an entry here runs without an interpreter.
var CompiledGoal = map[string]*GoalPage{}
CompiledGoal maps the name of a page file (as in bcontent.Page.Filename) to its Goal code compiled into the app. When a page is shown, its Goal code blocks run without an interpreter as long as they match the compiled blocks, in order.
var Files fs.FS
Files is the source filesystem of the content of the app (the Content.Source that was set last), for the code of its pages to open data files in it by their path in the content, as in table.OpenFS(content.Files, "datasets/planets.csv", tensor.Comma).
var FormatCode = map[string]func(src string) (string, error){
"Go": formatGo,
}
FormatCode are the functions that format the code of the code blocks of each language (such as "Go") when it is edited, as gofmt does for Go code, which is the default. Other packages can add other languages, as cogentcore.org/lab/mvmlab does Goal. A function returns an error for code that it cannot format, which is left as it is.
var GoalReplay []string
GoalReplay are the sources of the Goal code blocks of the current page that ran compiled before the first one that runs in the interpreter (because it was edited or not compiled). An interpreter that makes a new Goal interpreter for the page (see BindTextEditor) first runs these sources, without showing anything, and clears them, so that the interpreted code sees the variables of the blocks before it, as it would if the whole page had run in the interpreter.
var ImageCacheBytes = 64 << 20
ImageCacheBytes is the maximum total size in bytes of the decoded images that a Content keeps in the htmlcore.ImageCache of its Content.Context, so that revisiting a page does not decode its images again.
var NewPageInitFunc func()
NewPageInitFunc is called when a new page is just being rendered. This can do any necessary new-page initialization, e.g., [mvmcore.ResetGoalInterpreter]
var OfflineURL = ""
OfflineURL is the non-web base url, which can be set to allow docs to refer to this in frontmatter.
Functions ¶
func AddCompiledCode ¶ added in v0.5.0
AddCompiledCode adds the given compiled code blocks to CompiledCode. Generated code calls it.
func AddCompiledGoal ¶ added in v0.5.0
AddCompiledGoal adds the given compiled pages to CompiledGoal. Generated code calls it.
func BindCode ¶ added in v0.5.0
BindCode runs the code of the given text editor in the given parent, and again whenever the code is edited. Code that was compiled into the app (see CompiledCode) runs directly. Other code, including edited code, runs in the interpreter of BindTextEditor if there is one (mvm, through cogentcore.org/core/mvmcore); otherwise an edit shows a message that this app can not run edited code. Goal code runs compiled while it matches the Goal code compiled for the page (see CompiledGoal).
func CodeKey ¶ added in v0.5.0
CodeKey returns the key of the given code block source in CompiledCode: a hash of the source without any whitespace, so that indentation (tabs or spaces) and blank lines do not matter. The generator in cogentcore.org/core/content/contentcode computes the same key.
func OpenHelp ¶
OpenHelp opens the given documentation of the app in a window, in the context of the given widget, or raises the window if it is open already. The content does not use the URL of the web page, which is the app's.
func SetAppHelp ¶
SetAppHelp sets the help of the app (core.AppHelp), from the Help item of the app menu, to open the given documentation of the app, whose home page is home.md, with OpenHelp.
func ShowCodeErrors ¶ added in v0.5.7
ShowCodeErrors shows the given error of running the code of the given text editor, if non-nil, and otherwise clears the errors of the editor. The errors at a position in the code are marked in the editor (see textcore.Base.SetCodeErrors), whose tooltips are their messages, and the messages of all of the errors are shown in the given parent, below the output of the code.
Types ¶
type CodeFunc ¶ added in v0.5.0
CodeFunc is a Go code block compiled into the app at build time (see cogentcore.org/core/content/contentcode, which the core tool runs in core build and core generate). It runs the code with the given parent widget, which the code knows as b, and writes what the code prints to out.
type Content ¶
type Content struct {
core.Splits
// Source is the source filesystem for the content.
// It should be set using [Content.SetSource] or [Content.SetContent].
Source fs.FS `set:"-"`
// Context is the [htmlcore.Context] used to render the content,
// which can be modified for things such as adding wikilink handlers.
Context *htmlcore.Context `set:"-"`
// References is a list of references used for generating citation text
// for literature reference wikilinks in the format [[@CiteKey]].
References *csl.KeyList
// contains filtered or unexported fields
}
Content manages and displays the content of a set of pages.
func NewContent ¶
NewContent returns a new Content with the given optional parent: Content manages and displays the content of a set of pages.
func (*Content) LoadEachPage ¶ added in v0.3.36
LoadEachPage is a helper function to iterate through loading each page, which is used for updating the math cache.
func (*Content) MakeToolbar ¶
MakeToolbar adds the standard toolbar buttons for the content. See Content.MakeToolbarPDF for the optional PDF button.
func (*Content) MakeToolbarPDF ¶ added in v0.3.13
MakeToolbarPDF adds the PDF button to the toolbar. This is optional.
func (*Content) MakeToolbarSearch ¶ added in v0.3.16
MakeToolbarSearch adds a within-page search button to the toolbar. This is optional.
func (*Content) MenuSearch ¶
func (ct *Content) MenuSearch(items *[]core.ChooserItem)
func (*Content) Open ¶
Open opens the page with the given URL and updates the display. If no pages correspond to the URL, it is opened in the default browser. This version is for programmatic use -- see also OpenEvent.
func (*Content) OpenEvent ¶ added in v0.3.16
OpenEvent opens the page with the given URL and updates the display. If no pages correspond to the URL, it is opened in the default browser. This version is for widget event cases, where the keyboard modifiers are used to control the way the page is opened: Ctrl/Meta = new tab.
func (*Content) PagePDF ¶ added in v0.3.13
PagePDF generates a PDF of the current page, to given file path (directory). the page name is the file name.
func (*Content) PageRefs ¶ added in v0.3.13
PageRefs returns a core.Frame with the contents of the references cited on the given page. if References is nil, or error, result will be nil.
func (*Content) RenderWidget ¶ added in v0.3.36
func (ct *Content) RenderWidget()
func (*Content) SetContent ¶
SetContent is a helper function that calls Content.SetSource with the "content" subdirectory of the given filesystem.
func (*Content) SetReferences ¶ added in v0.3.12
SetReferences sets the Content.References: References is a list of references used for generating citation text for literature reference wikilinks in the format [[@CiteKey]].
type GoalBlock ¶ added in v0.5.0
GoalBlock is a Goal code block compiled into the app at build time (see cogentcore.org/core/content/cmd/contentcode). It runs the code with the given parent widget, which the code knows as b, writes what the code prints to out, and returns the next Goal code block of its page (nil after the last one). The next block runs in the scope of this one, so that it sees the variables and functions this one declares, as in the Goal interpreter, which runs all the Goal code of a page in one interpreter.
type GoalPage ¶ added in v0.5.0
type GoalPage struct {
// Keys are the [CodeKey]s of the sources of the Goal code blocks of
// the page, in order.
Keys []string
// Start returns the first code block of a new run of the page,
// in a new scope.
Start func() GoalBlock
}
GoalPage is the Goal code of a page compiled into the app.
type History ¶ added in v0.3.16
type History struct {
// Index is the current index in the Records, which is typically the
// current page as saved. Back decrements then returns that.
Index int
// Records is the list of saved locations.
Records []*Location
}
History records the history of browsing locations, for back arrow navigation.
func (*History) Back ¶ added in v0.3.16
Back decrements Index and returns that location. If already at the start, returns false.
type MountFS ¶
type MountFS struct {
// contains filtered or unexported fields
}
MountFS is a filesystem of content that combines a root filesystem with other filesystems mounted in it at URL prefixes, such as the documentation of several apps on one website (each also used for the help of its app with SetAppHelp). Make it with NewMountFS and MountFS.Mount, and use it as the source of a Content with Content.SetSource.
The pages of a mounted filesystem are at its prefix: its root page (with URL = "" in its front matter, as for the home.md of the help of an app) has the URL of the prefix itself (such as "docs/lists"), and its other pages have their URLs under it (such as "docs/lists/settings"). The name of the root page is its Title, or else the sentence case of the last element of the prefix ("Lists"). The other pages keep their names unless a page of the root filesystem or of an earlier mount has the same name, in which case the name of the mount's root page is added in parentheses ("Settings (Cogent Lists)"). Relative URLs of images and other resources in a mounted page are relative to the page, so that a mounted filesystem works the same as on its own.
func NewMountFS ¶
NewMountFS returns a new MountFS with the given root filesystem, which may be nil for a filesystem that only has mounts.
func (*MountFS) Mount ¶
Mount mounts the given filesystem at the given prefix, a slash-separated path such as "docs/lists" (see MountFS). It panics if the prefix is not a valid path of fs.FS other than ".", or if it is mounted already.
type SettingsData ¶ added in v0.3.13
type SettingsData struct {
PDF paginate.Options
// SiteTitle is the title of the site, used in page headings and titles.
SiteTitle string
// PageSettings is a function that returns the settings data to use
// for the current page. Can set custom parameters for different pages.
// The default sets the PDF Header function to HeaderLeftPageNumber
// with current page Title.
PageSettings func(ct *Content, curPage *bcontent.Page) *SettingsData
}
SettingsData has settings parameters for content, including PDF rendering options.
var Settings SettingsData
Settings are the current settings for content rendering.
func (*SettingsData) Defaults ¶ added in v0.3.13
func (s *SettingsData) Defaults()
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package bcontent ("base content") provides base types and functions shared by both content and the core build tool for content.
|
Package bcontent ("base content") provides base types and functions shared by both content and the core build tool for content. |
|
cmd
|
|
|
contentcode
command
Command contentcode compiles the runnable Go and Goal code blocks (```Go, ```Goal) of the markdown files of a content app into the app (see cogentcore.org/core/content/contentcode).
|
Command contentcode compiles the runnable Go and Goal code blocks (```Go, ```Goal) of the markdown files of a content app into the app (see cogentcore.org/core/content/contentcode). |
|
Package contentcode compiles the runnable Go and Goal code blocks (```Go, ```Goal) of the markdown files of a content app into the app: it writes a Go file to the app's package that defines a function for each code block and registers it in cogentcore.org/core/content.CompiledCode (Goal: cogentcore.org/core/content.CompiledGoal).
|
Package contentcode compiles the runnable Go and Goal code blocks (```Go, ```Goal) of the markdown files of a content app into the app: it writes a Go file to the app's package that defines a function for each code block and registers it in cogentcore.org/core/content.CompiledCode (Goal: cogentcore.org/core/content.CompiledGoal). |
|
examples
|
|
|
basic
command
|