Open mafredri opened 7 years ago
I would like to be able to write some substitutions / transformations for the outputted text produced by embedmd.
embedmd
Use case: Include example_test.go in readme, but replace package my_test with package main and func Example with func main.
example_test.go
package my_test
package main
func Example
func main
This could be expressed as s/find/replace/, and when used in practice:
s/find/replace/
[embedmd]:# (example_test.go s/^package .*_test$/package main/)
Due to the s-prefix we can differentiate this from start / end and allow multiple occurances:
OK: [embedmd]:# (pathOrURL language s/find/replace/ /start regexp/ /end regexp/) OK: [embedmd]:# (pathOrURL language s/find/replace/ s/find2/replace2/ /start regexp/ /end regexp/) OK: [embedmd]:# (pathOrURL language /start regexp/ /end regexp/ s/find/replace/) ERROR: [embedmd]:# (pathOrURL language /start regexp/ s/find/replace/ /end regexp/)
[embedmd]:# (pathOrURL language s/find/replace/ /start regexp/ /end regexp/)
[embedmd]:# (pathOrURL language s/find/replace/ s/find2/replace2/ /start regexp/ /end regexp/)
[embedmd]:# (pathOrURL language /start regexp/ /end regexp/ s/find/replace/)
[embedmd]:# (pathOrURL language /start regexp/ s/find/replace/ /end regexp/)
Thoughts?
EDIT: I don't mind implementing if this is accepted.
EDIT 2: For reference, an alternative (with go:generate and sed) can be seen here, but it's far from ideal.
go:generate
sed
I would like to be able to write some substitutions / transformations for the outputted text produced by
embedmd
.Use case: Include
example_test.go
in readme, but replacepackage my_test
withpackage main
andfunc Example
withfunc main
.This could be expressed as
s/find/replace/
, and when used in practice:Due to the s-prefix we can differentiate this from start / end and allow multiple occurances:
OK:
[embedmd]:# (pathOrURL language s/find/replace/ /start regexp/ /end regexp/)
OK:[embedmd]:# (pathOrURL language s/find/replace/ s/find2/replace2/ /start regexp/ /end regexp/)
OK:[embedmd]:# (pathOrURL language /start regexp/ /end regexp/ s/find/replace/)
ERROR:[embedmd]:# (pathOrURL language /start regexp/ s/find/replace/ /end regexp/)
Thoughts?
EDIT: I don't mind implementing if this is accepted.
EDIT 2: For reference, an alternative (with
go:generate
andsed
) can be seen here, but it's far from ideal.