diff --git a/cmd/gh-md-toc/main.go b/cmd/gh-md-toc/main.go
index 8a0d205..ca96885 100644
--- a/cmd/gh-md-toc/main.go
+++ b/cmd/gh-md-toc/main.go
@@ -23,6 +23,7 @@ var (
indent = kingpin.Flag("indent", "Indent space of generated list").Default("2").Int()
debug = kingpin.Flag("debug", "Show debug info").Bool()
ghurl = kingpin.Flag("github-url", "GitHub URL, default=https://api.github.com").String()
+ reVersion = kingpin.Flag("re-version", "RegExp version, default=0").Default("0").String()
)
// check if there was an error (and panic if it was)
@@ -41,7 +42,7 @@ func processPaths() {
for _, p := range *paths {
ghdoc := ghtoc.NewGHDoc(p, absPathsInToc, *startDepth, *depth, !*noEscape, *token, *indent, *debug)
- ghdoc.SetGHURL(*ghurl)
+ ghdoc.SetGHURL(*ghurl).SetReVersion(*reVersion)
if *serial {
ch <- ghdoc.GetToc()
@@ -74,6 +75,7 @@ func processSTDIN() {
check(os.WriteFile(file.Name(), bytes, 0644))
check(ghtoc.NewGHDoc(file.Name(), false, *startDepth, *depth, !*noEscape, *token, *indent, *debug).
SetGHURL(*ghurl).
+ SetReVersion(*reVersion).
GetToc().
Print(os.Stdout))
}
diff --git a/ghdoc.go b/ghdoc.go
index c7b1c87..bac99da 100644
--- a/ghdoc.go
+++ b/ghdoc.go
@@ -46,6 +46,7 @@ type GHDoc struct {
httpGetter httpGetter
httpPoster httpPoster
ghURL string
+ reVersion string
}
// NewGHDoc create GHDoc
@@ -64,6 +65,7 @@ func NewGHDoc(Path string, AbsPaths bool, StartDepth int, Depth int, Escape bool
httpGetter: internal.HttpGet,
httpPoster: internal.HttpPost,
ghURL: "https://api.github.com",
+ reVersion: "0",
}
}
@@ -81,6 +83,12 @@ func (doc *GHDoc) SetGHURL(url string) *GHDoc {
return doc
}
+// SetReVersion sets reg exp version
+func (doc *GHDoc) SetReVersion(v string) *GHDoc {
+ doc.reVersion = v
+ return doc
+}
+
// IsRemoteFile checks if path is for remote file or not
func (doc *GHDoc) IsRemoteFile() bool {
u, err := url.Parse(doc.Path)
@@ -160,16 +168,18 @@ func (doc *GHDoc) GrabToc() *GHToc {
// si:
// - s - let . match \n (single-line mode)
// - i - case-insensitive
- // re := `(?si)[1-6]) id="[^"]+">\s*` +
- // `[^"]+)">\s*` +
- // `(?P.*?)[1-6])>\s*` +
- `[^"]*)"[^>]*>\s*` +
- `.*?(?P.*?)[1-6]) id="[^"]+">\s*` +
+ `[^"]+)">\s*` +
+ `(?P.*?)[1-6])>\s*` +
+ `[^"]*)"[^>]*>\s*` +
+ `.*?(?P.*?)