From 7aef4c19dd9b4b9da2460e22395b6a25a476100f Mon Sep 17 00:00:00 2001 From: Shulhan Date: Fri, 18 Apr 2025 19:35:03 +0700 Subject: all: fix the logic when applying default embedded CSS By default, the document contains ":stylesheet:" attribute, which means using the default embedded CSS. To disable it, unset the attribute using ":stylesheet!:". To overwrite it, set the attribute to path of CSS file ":stylesheet: my.css". While at it, export the DocAttrStylesheet. --- document.go | 4 ++-- document_attribute.go | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/document.go b/document.go index aa89434..1fa88ed 100644 --- a/document.go +++ b/document.go @@ -215,8 +215,8 @@ func (doc *Document) ToHTML(out io.Writer) (err error) { var ok bool - _, ok = doc.Attributes.Entry[docAttrStylesheet] - if ok { + docAttrValue, ok = doc.Attributes.Entry[DocAttrStylesheet] + if ok && len(docAttrValue) == 0 { buf.WriteByte('\n') buf.WriteString(_defaultCSS) } diff --git a/document_attribute.go b/document_attribute.go index 9419084..3217c16 100644 --- a/document_attribute.go +++ b/document_attribute.go @@ -11,6 +11,13 @@ const ( DocAttrGenerator = `generator` DocAttrKeywords = `keywords` + // By default, the document contains ":stylesheet:" attribute, which + // means using the default embedded CSS. + // To disable it, unset the attribute using ":stylesheet!:". + // To overwrite it, set the attribute to path of CSS file + // ":stylesheet: my.css". + DocAttrStylesheet = `stylesheet` + docAttrAuthorInitials = `authorinitials` docAttrDocdir = `docdir` docAttrDocTitle = `doctitle` @@ -36,7 +43,6 @@ const ( docAttrSectNumLevel = `sectnumlevels` docAttrSectNums = `sectnums` docAttrShowTitle = `showtitle` - docAttrStylesheet = `stylesheet` docAttrTOC = `toc` docAttrTOCLevels = `toclevels` docAttrTOCTitle = `toc-title` @@ -70,7 +76,7 @@ func newDocumentAttribute() DocumentAttribute { docAttrLastUpdateValue: ``, docAttrSectIDs: ``, docAttrShowTitle: ``, - docAttrStylesheet: ``, + DocAttrStylesheet: ``, // Default to embedded CSS. docAttrTableCaption: ``, docAttrVersionLabel: ``, }, -- cgit v1.3