diff --git a/ghdoc.go b/ghdoc.go index 478b4af..0ce5a50 100644 --- a/ghdoc.go +++ b/ghdoc.go @@ -153,11 +153,13 @@ func (doc *GHDoc) GrabToc() *GHToc { doc.d("GrabToc: start, html size: " + strconv.Itoa(len(doc.html))) defer doc.d("GrabToc: done.") - re := `(?si)[1-6])>\s*` + - `]*>\s*` + - `.*?(?P.*?)[1-6]) id="[^"]+">\s*` + + `\s*` + + `(?P.*?)README in another language html: ` -

README in another language

+

README in another language

`, AbsPaths: false, Depth: 0, @@ -43,17 +47,19 @@ func TestGrabTocOneRow(t *testing.T) { } func TestGrabTocOneRowWithNewLines(t *testing.T) { + // https://raw.githubusercontent.com/ekalinin/envirius/f939d3b6882bfb6ecb28ef7b6e62862f934ba945/README.md + // $ go run cmd/gh-md-toc/main.go --debug https://raw.githubusercontent.com/ekalinin/envirius/f939d3b6882bfb6ecb28ef7b6e62862f934ba945/README.md tocExpected := []string{ "* [README in another language](#readme-in-another-language)", } doc := &GHDoc{ html: ` -

- - README in another language -

+

+ + README in another language + + +

`, AbsPaths: false, Depth: 0, Escape: true, @@ -66,7 +72,8 @@ func TestGrabTocOneRowWithNewLines(t *testing.T) { } func TestGrabTocMultilineOriginGithub(t *testing.T) { - + // https://github.com/ekalinin/envirius/blob/master/README.md#how-to-add-a-plugin + // $ go run cmd/gh-md-toc/main.go --debug https://raw.githubusercontent.com/ekalinin/envirius/f939d3b6882bfb6ecb28ef7b6e62862f934ba945/README.md tocExpected := []string{ "* [How to add a plugin?](#how-to-add-a-plugin)", " * [Mandatory elements](#mandatory-elements)", @@ -74,20 +81,15 @@ func TestGrabTocMultilineOriginGithub(t *testing.T) { } doc := &GHDoc{ html: ` -

How to add a plugin?

- +

How to add a plugin?

All plugins are in the directory nv-plugins. If you need to add support for a new language you should add it as plugin inside this directory.

- -

Mandatory elements

- +

Mandatory elements

If you create a plugin which builds all stuff from source then In a simplest case you need to implement 2 functions in the plugin's body:

- -

plug_list_versions

- +

plug_list_versions

This function should return list of available versions of the plugin. For example:

`, AbsPaths: false, @@ -104,6 +106,8 @@ For example:

} func TestGrabTocBackquoted(t *testing.T) { + // https://github.com/ekalinin/github-markdown-toc/blob/656b34011a482544a9ebb4116332c044834bdbbf/tests/test%20directory/test_backquote.md + // $ go run cmd/gh-md-toc/main.go --debug https://raw.githubusercontent.com/ekalinin/github-markdown-toc/656b34011a482544a9ebb4116332c044834bdbbf/tests/test%20directory/test_backquote.md tocExpected := []string{ "* [The command foo1](#the-command-foo1)", " * [The command foo2 is better](#the-command-foo2-is-better)", @@ -113,26 +117,17 @@ func TestGrabTocBackquoted(t *testing.T) { doc := &GHDoc{ html: ` -

-The command foo1 -

- +

The command foo1 +

Blabla...

- -

-The command foo2 is better

- +

The command foo2 is better

Blabla...

- -

-The command bar1 -

- +

The command bar1 +

Blabla...

- -

-The command bar2 is better

- +

The command bar2 is better

+

Blabla...

+

The command bar3 is the best

Blabla...

`, AbsPaths: false, Depth: 0, @@ -147,6 +142,8 @@ func TestGrabTocBackquoted(t *testing.T) { } func TestGrabTocDepth(t *testing.T) { + // https://github.com/ekalinin/github-markdown-toc/blob/656b34011a482544a9ebb4116332c044834bdbbf/tests/test%20directory/test_backquote.md + // $ go run cmd/gh-md-toc/main.go --debug https://raw.githubusercontent.com/ekalinin/github-markdown-toc/656b34011a482544a9ebb4116332c044834bdbbf/tests/test%20directory/test_backquote.md tocExpected := []string{ "* [The command foo1](#the-command-foo1)", "* [The command bar1](#the-command-bar1)", @@ -154,26 +151,17 @@ func TestGrabTocDepth(t *testing.T) { doc := &GHDoc{ html: ` -

-The command foo1 -

- +

The command foo1 +

Blabla...

- -

-The command foo2 is better

- +

The command foo2 is better

Blabla...

- -

-The command bar1 -

- +

The command bar1 +

Blabla...

- -

-The command bar2 is better

- +

The command bar2 is better

+

Blabla...

+

The command bar3 is the best

Blabla...

`, AbsPaths: false, Escape: true, @@ -190,45 +178,27 @@ func TestGrabTocDepth(t *testing.T) { } func TestGrabTocStartDepth(t *testing.T) { + // https://github.com/ekalinin/github-markdown-toc/blob/656b34011a482544a9ebb4116332c044834bdbbf/tests/test%20directory/test_backquote.md + // $ go run cmd/gh-md-toc/main.go --debug https://raw.githubusercontent.com/ekalinin/github-markdown-toc/656b34011a482544a9ebb4116332c044834bdbbf/tests/test%20directory/test_backquote.md tocExpected := []string{ "* [The command foo2 is better](#the-command-foo2-is-better)", - " * [The command foo3 is even betterer](#the-command-foo3-is-even-betterer)", "* [The command bar2 is better](#the-command-bar2-is-better)", - " * [The command bar3 is even betterer](#the-command-bar3-is-even-betterer)", + " * [The command bar3 is the best](#the-command-bar3-is-the-best)", } doc := &GHDoc{ html: ` -

-The command foo1 -

- +

The command foo1 +

Blabla...

- -

-The command foo2 is better

- +

The command foo2 is better

Blabla...

- -

-The command foo3 is even betterer

- +

The command bar1 +

Blabla...

- -

-The command bar1 -

- +

The command bar2 is better

Blabla...

- -

-The command bar2 is better

- -

Blabla...

- -

-The command bar3 is even betterer

- +

The command bar3 is the best

Blabla...

`, AbsPaths: false, Escape: true, @@ -251,7 +221,7 @@ func TestGrabTocWithAbspath(t *testing.T) { } doc := &GHDoc{ html: ` -

README in another language

+

README in another language

`, AbsPaths: true, Path: link, Depth: 0, @@ -270,13 +240,8 @@ func TestEscapedChars(t *testing.T) { doc := &GHDoc{ html: ` -

- - mod_* -

`, +

mod_*

+ `, AbsPaths: false, Escape: true, Depth: 0, @@ -298,15 +263,9 @@ func TestCustomSpaceIndentation(t *testing.T) { doc := &GHDoc{ html: ` -

-Header Level1 -

-

-Header Level2 -

-

-Header Level3 -

+

Header Level1

+

Header Level2

+

Header Level3

`, AbsPaths: false, Depth: 0, @@ -329,18 +288,8 @@ func TestMinHeaderNumber(t *testing.T) { doc := &GHDoc{ html: ` -

- - foo -

-

- - bar -

+

foo

+

bar

`, AbsPaths: false, Depth: 0, @@ -513,15 +462,13 @@ func TestGHDocConvert2HTML_issue35(t *testing.T) { } func TestGrabToc_issue35(t *testing.T) { - // As of 2022-08-25, GitHub API returns the HTML in the below format. + // As of 2023-08-31, GitHub API returns the HTML in the below format. doc := &GHDoc{ html: ` -

One

-

Uno

-

Two

-

Dos

-

Three

-

Tres

`, +

One

+

Two

+

Three

+`, AbsPaths: false, Depth: 0, Indent: 2,