Skip to content

Commit 88b05a7

Browse files
committed
error positions
1 parent bf8df43 commit 88b05a7

File tree

17 files changed

+238
-82
lines changed

17 files changed

+238
-82
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ GOPATH := $(shell go env GOPATH)
1111

1212
NOW := $(shell date -u +%FT%T%z)
1313
BUILD_FLAGS := "-s -w \
14-
-X github.com/mandelsoft/mdref/version.gitVersion=$(EFFECTIVE_VERSION) \
15-
-X github.com/mandelsoft/mdref/version.gitTreeState=$(GIT_TREE_STATE) \
16-
-X github.com/mandelsoft/mdref/version.gitCommit=$(COMMIT) \
17-
-X github.com/mandelsoft/mdref/version.buildDate=$(NOW)"
14+
-X main.gitVersion=$(EFFECTIVE_VERSION) \
15+
-X main.gitTreeState=$(GIT_TREE_STATE) \
16+
-X main.gitCommit=$(COMMIT) \
17+
-X main.buildDate=$(NOW)"
1818

1919
build: ${SOURCES}
2020
mkdir -p bin

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ This markdown reference generator uses
55
a document tree with markdown files containing
66
a special annotation syntax for tags and references
77
as input and generates an appropriate target tree with
8-
references resolved to resolved Markdown links
8+
references resolved to consistent Markdown links
99
and anchors.
1010

11-
- Never fix heading anymore with corrupting links all over the document tree
11+
- Never fix headings anymore with corrupting links all over the document tree
1212
- Never move text blocks or even complete files around in the document tree with corrupting links all over the document tree
1313
- Use terms all over the document tree, which are automatically linked to their explanation.
14+
- Provide examples documentation consistent with working code.
1415

1516
## Command Line Syntax
1617

@@ -36,6 +37,17 @@ and usage list is printed.
3637

3738
The source folder may not only contain markdown files. The generator copies all non-markdown files in the same structure to the target folder.
3839

40+
## General Annotation Syntax
41+
42+
Annotations used by this generator use a common syntax
43+
44+
```
45+
{{<elementsyntax>}}
46+
```
47+
48+
Elements may be [anchors](doc/chapters/references.md#anchors), [term anchors](doc/chapters/terms.md#anchors), [references](doc/chapters/references.md#references) or [commands](doc/chapters/commands.md#commands).
49+
50+
3951
## Reference and Anchor Syntax
4052

4153
Anchors and references are character sequences
@@ -53,8 +65,8 @@ may be copied or even moved into a completely different folder structure without
5365
Therefore, the anchors must be globally unique in the
5466
complete document tree.
5567

56-
The generator supports two kinds of references:
57-
- [Reference targets](doc/chapters/references.md#reference-targets)
68+
The generator supports two kinds of references as well as anchors:
69+
- [References](doc/chapters/references.md#references)
5870
- [Terms](doc/chapters/terms.md#terms)
5971

6072
## Commands

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0
1+
0.2.0

cmds.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import (
1010
)
1111

1212
type Command interface {
13+
Position() string
1314
GetSubstitution(path string) ([]byte, error)
1415
}
1516

1617
type Commands map[string]Command
1718

1819
type Include struct {
20+
_Position
1921
file string
2022
}
2123

@@ -49,7 +51,7 @@ var includeExpPat = regexp.MustCompile("^{([^}]+)}{([a-zA-Z -]+)}$")
4951
// --- end include args ---
5052
// --- end example ---
5153

52-
func NewInclude(args []byte) (Command, error) {
54+
func NewInclude(line, col int, args []byte) (Command, error) {
5355
var err error
5456

5557
matches := includeExpNum.FindSubmatch(args)
@@ -68,12 +70,12 @@ func NewInclude(args []byte) (Command, error) {
6870
return nil, fmt.Errorf("invalid start line: %w", err)
6971
}
7072
}
71-
return &IncludeNum{Include{string(matches[1])}, int(start), int(end)}, nil
73+
return &IncludeNum{Include{Position{line, col}, string(matches[1])}, int(start), int(end)}, nil
7274
}
7375

7476
matches = includeExpPat.FindSubmatch(args)
7577
if len(matches) != 0 {
76-
return &IncludePat{Include{string(matches[1])}, string(matches[2])}, nil
78+
return &IncludePat{Include{Position{line, col}, string(matches[1])}, string(matches[2])}, nil
7779
}
7880

7981
return nil, fmt.Errorf("invalid include arguments %q", string(args))

doc/chapters/commands.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,25 @@ The following commands are supported:
1313

1414
The include command uses the following syntax
1515
<pre>
16-
{{include}{<filepath>}[{[<startline>][:[<endline>]]}]}
17-
{{include}{<filepath>}{<key>}&rcub;
16+
{{include}{&lt;filepath>}[{[&lt;startline>][:[&lt;endline>]]}]}
17+
{{include}{&lt;filepath>}{<key>}&rcub;
1818
</pre>
1919

20-
In the first flavor numberimg starts from 1, given start and end line are included.
21-
If omitted the selection starts from the beginng or is taken to the end.
2220

23-
In the second flavotr the content between two lines containing the pattern
21+
In the first flavor numbering starts from 1, given start and end line are included.
22+
If omitted the selection starts from the beginning or is taken to the end.
23+
24+
In the second flavor the content between two lines containing the pattern
2425
`--- begin <key> ---` and `--- end <key> ---` is used.
25-
Those pattern MUST occur exactly once.
26+
Those patterns MUST occur exactly once.
2627

27-
This way it is possible to include some
28-
content from another file, for example
29-
a Go file like in the following example
28+
This command can be used to embed some content of another file into the
29+
Markdown file, for example
30+
parts of a Go file to provide some documentation consistent with actual
31+
code like in the following example
3032

3133
<pre>
32-
{{include}{../../../scan.go}{90:93}&rcub;
34+
{{include}{../../../scan.go}{102:105}&rcub;
3335
</pre>
3436

3537
which extracts the regular expressions used
@@ -42,6 +44,9 @@ var tgtExp = regexp.MustCompile(`[^([]{{([a-z][a-z0-9.-]*)(:([a-zA-Z][a-zA-Z0-9-
4244
var cmdExp = regexp.MustCompile(`{{([a-z]+)}((?:{[^}]+})+)}`)
4345
```
4446

47+
The second example uses the pattern syntax
48+
to determine include content:
49+
4550
<pre>
4651
{{include}{../../../cmds.go}{include args}&rcub;
4752
</pre>

doc/chapters/references.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

2-
## Reference Targets
2+
## References
33

44
Any reference in a Markdown document may
5-
use the annotated reference syntax to refer to global logical anchors.
5+
use the annotated reference syntax to refer to a global logical anchors.
66

77

88
<pre>
@@ -31,4 +31,10 @@ For example
3131
</pre>
3232

3333
It might be placed anywhere in a markdown document,
34-
therefore, it is possible to link to any location, not only section headers.
34+
therefore, it is possible to link to any location, not only section headers.
35+
36+
If placed directly before or after a Markdown section heading
37+
(and the option `--headings`) is given, no explicit anchor is generated,
38+
but the Markdown anchor name is used for the references.
39+
This keeps the generated file viewable by Markdown viewers not able to
40+
work with anchors.

doc/chapters/terms.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
Instead of using a reference as target for a markdown
55
reference it may be used as complete markdown linked text.
6-
In this case the [logical reference](references.md#reference-targets) appears inside the `[]` pair of a markdown reference, but without the target part:
6+
In this case the [logical reference](references.md#references) appears inside the `[]` pair
7+
of a markdown reference, but without the target part:
78

89
<pre>
910
A [{{&lt;name>}}] is a ....
@@ -22,7 +23,8 @@ There are several flavors for using a term:
2223

2324
### Anchors
2425

25-
Anchors for terms are just defined by using the reference syntax outside the markdown reference syntax and adding a text separated by a colon ( `:`).
26+
Anchors for terms are just defined by using the reference syntax outside the
27+
Markdown reference syntax and adding a text separated by a colon ( `:`).
2628

2729
For example
2830

@@ -32,4 +34,6 @@ For example
3234
</pre>
3335

3436
It might be placed anywhere in a Markdown document,
35-
therefore, it is possible to link to any location, not only section headers.
37+
therefore, it is possible to link to any location, not only section headers.
38+
39+
Term anchors may be used for regular references, also.

generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func generate(files []*File, resolution Resolution, source, target string) error
7979
exp := regexp.MustCompile(regexp.QuoteMeta(k))
8080
sub, err := c.GetSubstitution(src)
8181
if err != nil {
82-
return fmt.Errorf("%s: %s; %w", f.relpath, k, err)
82+
return fmt.Errorf("%s: %s: %s; %w", f.relpath, c.Position(), k, err)
8383
}
8484
data = exp.ReplaceAll(data, sub)
8585
}

go.sum

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,35 @@ github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0
22
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
33
github.com/gertd/go-pluralize v0.2.1 h1:M3uASbVjMnTsPb0PNqg+E/24Vwigyo/tvyMTtAlLgiA=
44
github.com/gertd/go-pluralize v0.2.1/go.mod h1:rbYaKDbsXxmRfr8uygAEKhOWsjyrrqrkHVpZvoOp8zk=
5+
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
6+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
7+
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
8+
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
9+
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
10+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
11+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
12+
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
13+
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
14+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
15+
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
16+
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
17+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
18+
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
19+
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
20+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
21+
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
22+
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
23+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
24+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
25+
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
26+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
27+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
28+
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
29+
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
530
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
631
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
32+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
33+
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
34+
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
35+
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
36+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

mdref.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"fmt"
55
"os"
66
"strings"
7-
8-
"github.com/mandelsoft/mdref/version"
97
)
108

119
type Resolution map[string]*File
@@ -33,7 +31,7 @@ func main() {
3331
args := os.Args[1:]
3432
for len(args) > 0 && strings.HasPrefix(args[0], "--") {
3533
if args[0] == "--version" {
36-
info := version.Get()
34+
info := Get()
3735

3836
fmt.Printf("mdgen version %s.%s.%s (%s) [%s %s]\n", info.Major, info.Minor, info.Patch, info.PreRelease, info.GitTreeState, info.GitCommit)
3937
os.Exit(0)
@@ -91,6 +89,7 @@ printed, additionally.
9189

9290
resolution, err := resolve(files)
9391
Error(err)
92+
Error(checkCommands(src, files))
9493

9594
if opts.Print {
9695
Print(files, resolution)

0 commit comments

Comments
 (0)