func loadParams(c *Controller, mdc *markdown.Config) error { switch c.Val() { case "ext": for _, ext := range c.RemainingArgs() { mdc.Extensions[ext] = struct{}{} } return nil case "css": if !c.NextArg() { return c.ArgErr() } mdc.Styles = append(mdc.Styles, c.Val()) return nil case "js": if !c.NextArg() { return c.ArgErr() } mdc.Scripts = append(mdc.Scripts, c.Val()) return nil case "template": tArgs := c.RemainingArgs() switch len(tArgs) { default: return c.ArgErr() case 1: fpath := filepath.ToSlash(filepath.Clean(c.Root + string(filepath.Separator) + tArgs[0])) if err := markdown.SetTemplate(mdc.Template, "", fpath); err != nil { c.Errf("default template parse error: %v", err) } return nil case 2: fpath := filepath.ToSlash(filepath.Clean(c.Root + string(filepath.Separator) + tArgs[1])) if err := markdown.SetTemplate(mdc.Template, tArgs[0], fpath); err != nil { c.Errf("template parse error: %v", err) } return nil } case "templatedir": if !c.NextArg() { return c.ArgErr() } _, err := mdc.Template.ParseGlob(c.Val()) if err != nil { c.Errf("template load error: %v", err) } if c.NextArg() { return c.ArgErr() } return nil default: return c.Err("Expected valid markdown configuration property") } }
func markdownParse(c *Controller) ([]markdown.Config, error) { var mdconfigs []markdown.Config for c.Next() { md := markdown.Config{ Renderer: blackfriday.HtmlRenderer(0, "", ""), Templates: make(map[string]string), StaticFiles: make(map[string]string), } // Get the path scope if !c.NextArg() || c.Val() == "{" { return mdconfigs, c.ArgErr() } md.PathScope = c.Val() // Load any other configuration parameters for c.NextBlock() { switch c.Val() { case "ext": exts := c.RemainingArgs() if len(exts) == 0 { return mdconfigs, c.ArgErr() } md.Extensions = append(md.Extensions, exts...) case "css": if !c.NextArg() { return mdconfigs, c.ArgErr() } md.Styles = append(md.Styles, c.Val()) case "js": if !c.NextArg() { return mdconfigs, c.ArgErr() } md.Scripts = append(md.Scripts, c.Val()) case "template": tArgs := c.RemainingArgs() switch len(tArgs) { case 0: return mdconfigs, c.ArgErr() case 1: if _, ok := md.Templates[markdown.DefaultTemplate]; ok { return mdconfigs, c.Err("only one default template is allowed, use alias.") } fpath := filepath.Clean(c.Root + string(filepath.Separator) + tArgs[0]) md.Templates[markdown.DefaultTemplate] = fpath case 2: fpath := filepath.Clean(c.Root + string(filepath.Separator) + tArgs[1]) md.Templates[tArgs[0]] = fpath default: return mdconfigs, c.ArgErr() } case "sitegen": if c.NextArg() { md.StaticDir = path.Join(c.Root, c.Val()) } else { md.StaticDir = path.Join(c.Root, markdown.DefaultStaticDir) } if c.NextArg() { // only 1 argument allowed return mdconfigs, c.ArgErr() } default: return mdconfigs, c.Err("Expected valid markdown configuration property") } } // If no extensions were specified, assume .md if len(md.Extensions) == 0 { md.Extensions = []string{".md"} } mdconfigs = append(mdconfigs, md) } return mdconfigs, nil }
func loadParams(c *Controller, mdc *markdown.Config) error { switch c.Val() { case "ext": exts := c.RemainingArgs() if len(exts) == 0 { return c.ArgErr() } mdc.Extensions = append(mdc.Extensions, exts...) return nil case "css": if !c.NextArg() { return c.ArgErr() } mdc.Styles = append(mdc.Styles, c.Val()) return nil case "js": if !c.NextArg() { return c.ArgErr() } mdc.Scripts = append(mdc.Scripts, c.Val()) return nil case "template": tArgs := c.RemainingArgs() switch len(tArgs) { case 0: return c.ArgErr() case 1: if _, ok := mdc.Templates[markdown.DefaultTemplate]; ok { return c.Err("only one default template is allowed, use alias.") } fpath := filepath.ToSlash(filepath.Clean(c.Root + string(filepath.Separator) + tArgs[0])) mdc.Templates[markdown.DefaultTemplate] = fpath return nil case 2: fpath := filepath.ToSlash(filepath.Clean(c.Root + string(filepath.Separator) + tArgs[1])) mdc.Templates[tArgs[0]] = fpath return nil default: return c.ArgErr() } case "sitegen": if c.NextArg() { mdc.StaticDir = path.Join(c.Root, c.Val()) } else { mdc.StaticDir = path.Join(c.Root, markdown.DefaultStaticDir) } if c.NextArg() { // only 1 argument allowed return c.ArgErr() } return nil case "dev": if c.NextArg() { mdc.Development = strings.ToLower(c.Val()) == "true" } else { mdc.Development = true } if c.NextArg() { // only 1 argument allowed return c.ArgErr() } return nil default: return c.Err("Expected valid markdown configuration property") } }