all repos — vite @ a15978fe24a2e105d347adbc857a0af0c143bdeb

a fast (this time, actually) and minimal static site generator

Separate syntax highlight configuration
Anirudh Oppiliappan x@icyphox.sh
Thu, 24 Feb 2022 12:05:06 +0530
commit

a15978fe24a2e105d347adbc857a0af0c143bdeb

parent

1c86a5361dbf3d809d45e0d0066e59a0d65f9070

3 files changed, 44 insertions(+), 18 deletions(-)

jump to
M markdown/markdown.gomarkdown/markdown.go

@@ -9,14 +9,17 @@ "git.icyphox.sh/vite/config"

"git.icyphox.sh/vite/markdown/template" bfc "github.com/Depado/bfchroma" + "github.com/alecthomas/chroma/formatters/html" bf "github.com/russross/blackfriday/v2" ) -var bfFlags = bf.UseXHTML | bf.Smartypants | bf.SmartypantsFractions | - bf.SmartypantsDashes | bf.NofollowLinks -var bfExts = bf.NoIntraEmphasis | bf.Tables | bf.FencedCode | bf.Autolink | - bf.Strikethrough | bf.SpaceHeadings | bf.BackslashLineBreak | - bf.HeadingIDs | bf.Footnotes | bf.NoEmptyLineBeforeBlock +var ( + bfFlags = bf.UseXHTML | bf.Smartypants | bf.SmartypantsFractions | + bf.SmartypantsDashes | bf.NofollowLinks + bfExts = bf.NoIntraEmphasis | bf.Tables | bf.FencedCode | bf.Autolink | + bf.Strikethrough | bf.SpaceHeadings | bf.BackslashLineBreak | + bf.HeadingIDs | bf.Footnotes | bf.NoEmptyLineBeforeBlock +) type Output struct { HTML []byte

@@ -32,7 +35,10 @@ out.HTML = bf.Run(

md.Body, bf.WithRenderer( bfc.NewRenderer( - bfc.ChromaStyle(Icy), + bfc.ChromaOptions( + html.TabWidth(4), + html.WithClasses(true), + ), bfc.Extend( bf.NewHTMLRenderer(bf.HTMLRendererParameters{ Flags: bfFlags,
M markdown/style.gocontrib/style.go

@@ -1,10 +1,15 @@

-package markdown +// style.go: generate chroma css +// go run contrib/style.go > syntax.css +package main import ( + "os" + "github.com/alecthomas/chroma" + "github.com/alecthomas/chroma/formatters/html" ) -var Icy = chroma.MustNewStyle("icy", chroma.StyleEntries{ +var syntax = chroma.MustNewStyle("syntax", chroma.StyleEntries{ chroma.CommentMultiline: "italic #999988", chroma.CommentPreproc: "bold #999999", chroma.CommentSingle: "italic #999988",

@@ -30,11 +35,11 @@ chroma.LiteralStringSymbol: "#990073",

chroma.LiteralString: "#509c93", chroma.NameAttribute: "#008080", chroma.NameBuiltinPseudo: "#999999", - chroma.NameBuiltin: "#0086B3", + chroma.NameBuiltin: "#509c93", chroma.NameClass: "bold #666666", chroma.NameConstant: "#008080", chroma.NameDecorator: "bold #3c5d5d", - chroma.NameEntity: "#800080", + chroma.NameEntity: "#509c93", chroma.NameException: "bold #444444", chroma.NameFunction: "bold #444444", chroma.NameLabel: "bold #444444",

@@ -48,3 +53,8 @@ chroma.Operator: "bold #000000",

chroma.TextWhitespace: "#bbbbbb", chroma.Background: " bg:#ffffff", }) + +func main() { + formatter := html.New(html.WithClasses(true)) + formatter.WriteCSS(os.Stdout, syntax) +}
M readmereadme

@@ -39,6 +39,16 @@

Example config: https://git.icyphox.sh/site/tree/config.yaml +SYNTAX HIGHLIGHTING + +vite uses chroma (https://github.com/alecthomas/chroma) for syntax +highlighting. Note that CSS is not provided, and will have to be +included by the user in the templates. A sample style can be generated +by running: + + go run contrib/style.go > syntax.css + + TEMPLATING Non-index templates have access to the below objects:

@@ -62,10 +72,10 @@ |-- project/

|-- index.html `-- project.html -The templates under 'project/' are referenced as 'project/index.html'. +The templates under project/ are referenced as project/index.html. This deserves mention because Go templates don't recurse into subdirectories by default (template.ParseGlob uses filepath.Glob, and -doesn't support deep-matching, i.e. '**'). +doesn't support deep-matching, i.e. **). More templating examples can be found at: https://git.icyphox.sh/site/tree/templates

@@ -73,8 +83,8 @@

FEEDS -Atom feeds are generated for all directories under 'pages/'. So -'pages/foo' will have a Atom feed at 'build/foo/feed.xml'. +Atom feeds are generated for all directories under pages/. So +pages/foo will have a Atom feed at build/foo/feed.xml. FILE TREE

@@ -86,7 +96,7 @@ |-- pages/

|-- static/ |-- templates/ -The entire 'static/' directory gets copied over to 'build/', and can be -used to reference static assets -- css, images, etc. 'pages/' supports -only nesting one directory deep; for example: 'pages/blog/*.md' will -render, but 'pages/blog/foo/*.md' will not. +The entire static/ directory gets copied over to build/, and can be +used to reference static assets -- css, images, etc. pages/ supports +only nesting one directory deep; for example: pages/blog/*.md will +render, but pages/blog/foo/*.md will not.