mconf := markup_config.Default
mconf.AsciidocExt.Backend = "disallowed-backend"
mconf.AsciidocExt.Extensions = []string{"./disallowed-extension"}
- mconf.AsciidocExt.Attributes = map[string]string{"outdir": "disallowed-attribute"}
+ mconf.AsciidocExt.Attributes = map[string]any{"outdir": "disallowed-attribute"}
mconf.AsciidocExt.SafeMode = "disallowed-safemode"
mconf.AsciidocExt.FailureLevel = "disallowed-failurelevel"
[markup.asciidocext.attributes]
my-base-url = "https://gohugo.io/"
my-attribute-name = "my value"
+my-attribute-true = true
+my-attribute-false = false
`)
conf := testconfig.GetTestConfig(nil, cfg)
p, err := asciidocext.Provider.New(
expectedValues := map[string]bool{
"my-base-url=https://gohugo.io/": true,
"my-attribute-name=my value": true,
+ "my-attribute-true": true,
+ "'!my-attribute-false'": true,
}
args := ac.ParseArgs(converter.DocumentContext{})
- c.Assert(len(args), qt.Equals, 5)
+ c.Assert(len(args), qt.Equals, 9)
c.Assert(args[0], qt.Equals, "-a")
c.Assert(expectedValues[args[1]], qt.Equals, true)
c.Assert(args[2], qt.Equals, "-a")
c.Assert(expectedValues[args[3]], qt.Equals, true)
- c.Assert(args[4], qt.Equals, "--no-header-footer")
+ c.Assert(args[4], qt.Equals, "-a")
+ c.Assert(expectedValues[args[5]], qt.Equals, true)
+ c.Assert(args[6], qt.Equals, "-a")
+ c.Assert(expectedValues[args[7]], qt.Equals, true)
+ c.Assert(args[8], qt.Equals, "--no-header-footer")
}
func getProvider(c *qt.C, mConfStr string) converter.Provider {
"github.com/gohugoio/hugo/markup/converter"
"github.com/gohugoio/hugo/markup/internal"
"github.com/gohugoio/hugo/markup/tableofcontents"
+ "github.com/spf13/cast"
"golang.org/x/net/html"
)
continue
}
- args = append(args, "-a", attributeKey+"="+attributeValue)
+ // To set a document attribute to true: -a attributeKey
+ // To set a document attribute to false: -a '!attributeKey'
+ // For other types: -a attributeKey=attributeValue
+ if b, ok := attributeValue.(bool); ok {
+ arg := attributeKey
+ if !b {
+ arg = "'!" + attributeKey + "'"
+ }
+ args = append(args, "-a", arg)
+ } else {
+ args = append(args, "-a", attributeKey+"="+cast.ToString(attributeValue))
+ }
}
if cfg.WorkingFolderCurrent {