aboutsummaryrefslogtreecommitdiff
path: root/filehtml.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-01-29 21:07:22 +0700
committerShulhan <ms@kilabit.info>2026-02-02 16:40:16 +0700
commitf578b0ba7341f8bc97d13cd165070002596cb106 (patch)
tree44771b43cdcd4e36f56ec6dda2d7b4baab75d71e /filehtml.go
parent1af4644cb401e64ac20ecb7f12e898096470eb61 (diff)
downloadciigo-f578b0ba7341f8bc97d13cd165070002596cb106.tar.xz
all: allow combination of default and custom stylesheet
To combine default stylesheet with custom CSS, set the value to "default" and the file name of custom CSS, separated by comma. This is the recommended way to use custom stylesheet since it can be set only on specific pages. ---- // In asciidoctor: :stylesheet: default, custom.css // In markdown: stylesheet: default, custom.css ---- To disable default stylesheet and only using custom CSS, set the value only to the file name of custom CSS. Another way to use custom stylesheet is by creating your own template and pass it to `serve` or `convert` command. This method makes the stylesheet applied to all pages.
Diffstat (limited to 'filehtml.go')
-rw-r--r--filehtml.go40
1 files changed, 27 insertions, 13 deletions
diff --git a/filehtml.go b/filehtml.go
index 6e5a080..7731ec0 100644
--- a/filehtml.go
+++ b/filehtml.go
@@ -39,6 +39,10 @@ func (fhtml *fileHTML) unpackAdocMetadata(doc *asciidoctor.Document) {
k string
v string
)
+
+ // By default `:stylesheet:` is set in Attributes.
+ // If user remove it, by using `:stylesheet!:`, the key would not
+ // exist in the map.
var withStylesheet bool
fhtml.Title = doc.Title.String()
@@ -47,10 +51,14 @@ func (fhtml *fileHTML) unpackAdocMetadata(doc *asciidoctor.Document) {
for k, v = range doc.Attributes.Entry {
switch k {
case asciidoctor.DocAttrStylesheet:
- if len(v) != 0 {
- fhtml.Styles = append(fhtml.Styles, v)
- } else {
- withStylesheet = true
+ vals := strings.Split(v, ",")
+ for _, v = range vals {
+ v = strings.TrimSpace(v)
+ if v == `` || v == `default` {
+ withStylesheet = true
+ } else {
+ fhtml.Styles = append(fhtml.Styles, v)
+ }
}
case asciidoctor.DocAttrAuthorNames:
fhtml.Metadata[asciidoctor.DocAttrAuthor] = v
@@ -86,10 +94,20 @@ func (fhtml *fileHTML) unpackMarkdownMetadata(metadata map[string]any) {
key = strings.ToLower(key)
switch key {
case asciidoctor.DocAttrStylesheet:
- if vstr == `false` {
- withStylesheet = false
- } else {
- fhtml.Styles = append(fhtml.Styles, vstr)
+ vals := strings.Split(vstr, ",")
+ for _, v := range vals {
+ v = strings.TrimSpace(v)
+
+ switch v {
+ case ``:
+ // Skip it.
+ case `false`:
+ withStylesheet = false
+ case `default`:
+ // Use embedded stylesheet.
+ default:
+ fhtml.Styles = append(fhtml.Styles, vstr)
+ }
}
case metadataTitle:
fhtml.Title = vstr
@@ -105,12 +123,8 @@ func (fhtml *fileHTML) unpackMarkdownMetadata(metadata map[string]any) {
func (fhtml *fileHTML) initCSS(withStylesheet bool) {
var logp = `initCSS`
- if len(fhtml.Styles) != 0 {
- // User defined their custom CSS throught ":stylesheet:"
- return
- }
if !withStylesheet {
- // User unset the stylesheet throught ":stylesheet!".
+ // User explicitly unset the default stylesheet.
return
}
css, err := staticfs.Get(`/ciigo.css`)