當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Markdown.Process方法代碼示例

本文整理匯總了Golang中github.com/mholt/caddy/middleware/markdown.Markdown.Process方法的典型用法代碼示例。如果您正苦於以下問題:Golang Markdown.Process方法的具體用法?Golang Markdown.Process怎麽用?Golang Markdown.Process使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/mholt/caddy/middleware/markdown.Markdown的用法示例。


在下文中一共展示了Markdown.Process方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Markdown

// Markdown configures a new Markdown middleware instance.
func Markdown(c *Controller) (middleware.Middleware, error) {
	mdconfigs, err := markdownParse(c)
	if err != nil {
		return nil, err
	}

	md := markdown.Markdown{
		Root:       c.Root,
		FileSys:    http.Dir(c.Root),
		Configs:    mdconfigs,
		IndexFiles: []string{"index.md"},
	}

	// For any configs that enabled static site gen, sweep the whole path at startup
	c.Startup = append(c.Startup, func() error {
		for _, cfg := range mdconfigs {
			if cfg.StaticDir == "" {
				continue
			}

			// If generated site already exists, clear it out
			_, err := os.Stat(cfg.StaticDir)
			if err == nil {
				err := os.RemoveAll(cfg.StaticDir)
				if err != nil {
					return err
				}
			}

			fp := filepath.Join(md.Root, cfg.PathScope)
			filepath.Walk(fp, func(path string, info os.FileInfo, err error) error {
				for _, ext := range cfg.Extensions {
					if !info.IsDir() && strings.HasSuffix(info.Name(), ext) {
						// Load the file
						body, err := ioutil.ReadFile(path)
						if err != nil {
							return err
						}

						// Get the relative path as if it were a HTTP request,
						// then prepend with "/" (like a real HTTP request)
						reqPath, err := filepath.Rel(md.Root, path)
						if err != nil {
							return err
						}
						reqPath = "/" + reqPath

						// Generate the static file
						_, err = md.Process(cfg, reqPath, body)
						if err != nil {
							return err
						}

						break // don't try other file extensions
					}
				}

				return nil
			})
		}

		return nil
	})

	return func(next middleware.Handler) middleware.Handler {
		md.Next = next
		return md
	}, nil
}
開發者ID:bigtiger,項目名稱:caddy,代碼行數:70,代碼來源:markdown.go


注:本文中的github.com/mholt/caddy/middleware/markdown.Markdown.Process方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。