Documentation
¶
Overview ¶
Copyright © 2024 Guzmán Monné guzman.monne@cloudbridge.com.uy
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Index ¶
- func BuildPage(body, title, chromaCSS, linksHTML string) string
- func ChromaCSS() (string, error)
- func ExtractTitle(src []byte, fallback string) string
- func LinksFooter(links []Link) string
- func RenderMarkdown(src []byte) (string, error)
- func ResolveOutputPath(inputPath, outputFlag string) string
- func StripFrontmatter(src []byte) []byte
- type Link
- type OutputTarget
- type RenderConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildPage ¶
BuildPage assembles a complete HTML document from a rendered body fragment, a page title, a generated chroma stylesheet, and an optional links footer (pass "" for documents without external links).
func ExtractTitle ¶
ExtractTitle returns the text of the first ATX H1 heading ("# ..."). Without an H1, the fallback is returned.
func LinksFooter ¶
LinksFooter renders the Links footer section for a page. An empty slice yields an empty string so the template placeholder collapses cleanly.
func RenderMarkdown ¶
RenderMarkdown converts Markdown source into an HTML body fragment.
func ResolveOutputPath ¶
ResolveOutputPath determines where the HTML output is written. An empty outputFlag swaps the input file's extension for ".html"; an extensionless input gains ".html". A set outputFlag is returned verbatim.
func StripFrontmatter ¶
StripFrontmatter removes a leading YAML frontmatter block delimited by "---" lines. Input without a complete frontmatter block is returned unchanged.
Types ¶
type Link ¶
Link is one external reference found in a Markdown document.
func ExtractLinks ¶
ExtractLinks parses src with the same GFM parser used for rendering and returns every external (http/https) link, autolink, and image, in document order, deduplicated by URL with the first occurrence winning (a URL appearing as both link and image keeps only its first form). Code fences produce no link nodes, so their contents are ignored by construction.
type OutputTarget ¶
OutputTarget says where the rendered HTML goes. Temp=false: Path is the concrete output path. Temp=true: Path is an os.CreateTemp pattern like "doc-*.html"; the imperative shell turns it into a real file in the OS temp directory.
func ResolveOutputTarget ¶
func ResolveOutputTarget(inputPath, outputFlag string, open bool) OutputTarget
ResolveOutputTarget decides the output destination. An explicit outputFlag always wins and is never temporary. Without it, open renders to a temporary file so the source directory stays clean; otherwise the sibling rule from ResolveOutputPath applies.
When constructing the temp pattern the directory portion of inputPath is stripped — only the basename without its extension feeds the pattern. Nameless inputs (empty string, dotfiles) fall back to "markdown".
type RenderConfig ¶
type RenderConfig struct {
InputPath string
Output OutputTarget
Open bool
}
RenderConfig holds the fully resolved configuration for one render run. Open drives the browser-open step in the shell; it is distinct from Output.Temp, which only selects the destination.
func NewRenderConfig ¶
func NewRenderConfig(inputPath, outputFlag string, open bool) RenderConfig
NewRenderConfig resolves raw CLI inputs into a valid RenderConfig. The output destination is decided once, at the boundary, so the rest of the program holds only valid state.