fix: made the good importable Markdown module.
This commit is contained in:
parent
f211cc2841
commit
9eaa0ee444
2 changed files with 18 additions and 1 deletions
|
@ -66,8 +66,11 @@ func DefaultPP(mod string) *tpp.Preprocessor {
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
s *tpp.Script,
|
s *tpp.Script,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
s.SetImportDir(mod)
|
s.SetImportDir(mod)
|
||||||
s.SetImports(xmodules.Modules)
|
modules := xmodules.GetModules()
|
||||||
|
modules.Add("markdown", mdx.GetModule())
|
||||||
|
s.SetImports(modules)
|
||||||
s.EnableFileImport(true)
|
s.EnableFileImport(true)
|
||||||
|
|
||||||
vals := ctx.Value(KeyValues).(*ContextValues)
|
vals := ctx.Value(KeyValues).(*ContextValues)
|
||||||
|
@ -78,6 +81,7 @@ func DefaultPP(mod string) *tpp.Preprocessor {
|
||||||
s.Add("__index_suffix__", vals.IndexSuffix)
|
s.Add("__index_suffix__", vals.IndexSuffix)
|
||||||
s.Add("__tpp_ext__", vals.Ext)
|
s.Add("__tpp_ext__", vals.Ext)
|
||||||
s.Add("__source_path__", vals.SourcePath)
|
s.Add("__source_path__", vals.SourcePath)
|
||||||
|
|
||||||
}).SetPreCode(func(ctx context.Context) []byte {
|
}).SetPreCode(func(ctx context.Context) []byte {
|
||||||
return []byte(`
|
return []byte(`
|
||||||
markdown := func(...args) {
|
markdown := func(...args) {
|
||||||
|
|
13
mdx/main.go
13
mdx/main.go
|
@ -5,6 +5,19 @@ import "github.com/gomarkdown/markdown/parser"
|
||||||
import "github.com/d5/tengo/v2"
|
import "github.com/d5/tengo/v2"
|
||||||
import "bytes"
|
import "bytes"
|
||||||
|
|
||||||
|
func GetModule() tengo.Importable {
|
||||||
|
return &tengo.BuiltinModule{Attrs:map[string]tengo.Object{
|
||||||
|
"new": &tengo.BuiltinFunction{
|
||||||
|
Name: "new",
|
||||||
|
Value: func(
|
||||||
|
args ...tengo.Object,
|
||||||
|
) (tengo.Object, error){
|
||||||
|
return MakeDefaultMarkdown(), nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
type Markdown struct {
|
type Markdown struct {
|
||||||
tengo.ObjectImpl
|
tengo.ObjectImpl
|
||||||
MakeParser func() *parser.Parser
|
MakeParser func() *parser.Parser
|
||||||
|
|
Loading…
Reference in a new issue