fix: made the good importable Markdown module.

This commit is contained in:
Andrey Parhomenko 2024-06-18 17:34:12 +05:00
parent f211cc2841
commit 9eaa0ee444
2 changed files with 18 additions and 1 deletions

View file

@ -66,8 +66,11 @@ func DefaultPP(mod string) *tpp.Preprocessor {
ctx context.Context,
s *tpp.Script,
) {
s.SetImportDir(mod)
s.SetImports(xmodules.Modules)
modules := xmodules.GetModules()
modules.Add("markdown", mdx.GetModule())
s.SetImports(modules)
s.EnableFileImport(true)
vals := ctx.Value(KeyValues).(*ContextValues)
@ -78,6 +81,7 @@ func DefaultPP(mod string) *tpp.Preprocessor {
s.Add("__index_suffix__", vals.IndexSuffix)
s.Add("__tpp_ext__", vals.Ext)
s.Add("__source_path__", vals.SourcePath)
}).SetPreCode(func(ctx context.Context) []byte {
return []byte(`
markdown := func(...args) {

View file

@ -5,6 +5,19 @@ import "github.com/gomarkdown/markdown/parser"
import "github.com/d5/tengo/v2"
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 {
tengo.ObjectImpl
MakeParser func() *parser.Parser