Skip to content

Commit

Permalink
feat(format): escape link text
Browse files Browse the repository at this point in the history
  • Loading branch information
princjef committed Jun 11, 2023
1 parent 43f2be8 commit 2ae7442
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 25 deletions.
2 changes: 1 addition & 1 deletion format/formatcore/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func Link(text, href string) string {
return text
}

return fmt.Sprintf("[%s](<%s>)", text, href)
return fmt.Sprintf("[%s](<%s>)", Escape(text), href)
}

// ListEntry generates an unordered list entry with the provided text at the
Expand Down
12 changes: 6 additions & 6 deletions testData/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ We also have constants like [Constant](<#Constant>) and [Const1](<#Const1>) plus

- [Constants](<#constants>)
- [Variables](<#variables>)
- [func Func(param int) int](<#Func>)
- [func Func\(param int\) int](<#Func>)
- [type AnotherStruct](<#AnotherStruct>)
- [func NewAnotherStruct() *AnotherStruct](<#NewAnotherStruct>)
- [func (s *AnotherStruct) GetField() string](<#AnotherStruct.GetField>)
- [func NewAnotherStruct\(\) \*AnotherStruct](<#NewAnotherStruct>)
- [func \(s \*AnotherStruct\) GetField\(\) string](<#AnotherStruct.GetField>)
- [type Type](<#Type>)
- [func (t *Type) Func()](<#Type.Func>)
- [func \(t \*Type\) Func\(\)](<#Type.Func>)


## Constants
Expand Down Expand Up @@ -123,7 +123,7 @@ Func is present in this file.
<a name="AnotherStruct"></a>
## type [AnotherStruct](<https://github.com/princjef/gomarkdoc/blob/master/testData/docs/anotherFile.go#L5-L7>)

AnotherStruct has methods like [\*AnotherStruct.GetField](<#AnotherStruct.GetField>) and also has an initializer called [NewAnotherStruct](<#NewAnotherStruct>).
AnotherStruct has methods like [\\\*AnotherStruct.GetField](<#AnotherStruct.GetField>) and also has an initializer called [NewAnotherStruct](<#NewAnotherStruct>).

```go
type AnotherStruct struct {
Expand All @@ -138,7 +138,7 @@ type AnotherStruct struct {
func NewAnotherStruct() *AnotherStruct
```

NewAnotherStruct\(\) makes [\*AnotherStruct](<#AnotherStruct>).
NewAnotherStruct\(\) makes [\\\*AnotherStruct](<#AnotherStruct>).

<a name="AnotherStruct.GetField"></a>
### func \(\*AnotherStruct\) [GetField](<https://github.com/princjef/gomarkdoc/blob/master/testData/docs/anotherFile.go#L17>)
Expand Down
6 changes: 3 additions & 3 deletions testData/embed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Package embed tests out embedding of documentation in an existing readme.

## Index

- [func EmbeddedFunc(param int) int](<#EmbeddedFunc>)
- [func EmbeddedFunc\(param int\) int](<#EmbeddedFunc>)


<a name="EmbeddedFunc"></a>
Expand Down Expand Up @@ -47,7 +47,7 @@ Package embed tests out embedding of documentation in an existing readme.

## Index

- [func EmbeddedFunc(param int) int](<#EmbeddedFunc>)
- [func EmbeddedFunc\(param int\) int](<#EmbeddedFunc>)


<a name="EmbeddedFunc"></a>
Expand Down Expand Up @@ -80,7 +80,7 @@ Package embed tests out embedding of documentation in an existing readme.

## Index

- [func EmbeddedFunc(param int) int](<#EmbeddedFunc>)
- [func EmbeddedFunc\(param int\) int](<#EmbeddedFunc>)


<a name="EmbeddedFunc"></a>
Expand Down
55 changes: 55 additions & 0 deletions testData/generics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!-- Code generated by gomarkdoc. DO NOT EDIT -->

# generics

```go
import "github.com/princjef/gomarkdoc/testData/generics"
```

## Index

- [func Func\[S int | float64\]\(s S\) S](<#Func>)
- [type Generic](<#Generic>)
- [func NewGeneric\[T any\]\(param T\) Generic\[T\]](<#NewGeneric>)
- [func \(g Generic\[T\]\) Method\(\)](<#Generic[T].Method>)


<a name="Func"></a>
## func [Func](<https://github.com/princjef/gomarkdoc/blob/master/testData/generics/generics.go#L17>)

```go
func Func[S int | float64](s S) S
```

Func is a generic function.

<a name="Generic"></a>
## type [Generic](<https://github.com/princjef/gomarkdoc/blob/master/testData/generics/generics.go#L4-L6>)

Generic is a generic struct.

```go
type Generic[T any] struct {
Field T
}
```

<a name="NewGeneric"></a>
### func [NewGeneric](<https://github.com/princjef/gomarkdoc/blob/master/testData/generics/generics.go#L9>)

```go
func NewGeneric[T any](param T) Generic[T]
```

NewGeneric produces a new [Generic](<#Generic>) struct.

<a name="Generic[T].Method"></a>
### func \(Generic\[T\]\) [Method](<https://github.com/princjef/gomarkdoc/blob/master/testData/generics/generics.go#L14>)

```go
func (g Generic[T]) Method()
```

Method is a method of a generic type.

Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
19 changes: 19 additions & 0 deletions testData/generics/generics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package generics

// Generic is a generic struct.
type Generic[T any] struct {
Field T
}

// NewGeneric produces a new [Generic] struct.
func NewGeneric[T any](param T) Generic[T] {
return Generic[T]{Field: param}
}

// Method is a method of a generic type.
func (g Generic[T]) Method() {}

// Func is a generic function.
func Func[S int | float64](s S) S {
return s
}
10 changes: 5 additions & 5 deletions testData/lang/function/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import "github.com/princjef/gomarkdoc/testData/lang/function"

- [Constants](<#constants>)
- [Variables](<#variables>)
- [func Standalone(p1 int, p2 string) (int, error)](<#Standalone>)
- [func Standalone\(p1 int, p2 string\) \(int, error\)](<#Standalone>)
- [type Generic](<#Generic>)
- [func (r Generic[T]) WithGenericReceiver()](<#Generic[T].WithGenericReceiver>)
- [func \(r Generic\[T\]\) WithGenericReceiver\(\)](<#Generic[T].WithGenericReceiver>)
- [type Receiver](<#Receiver>)
- [func New() Receiver](<#New>)
- [func (r *Receiver) WithPtrReceiver()](<#Receiver.WithPtrReceiver>)
- [func (r Receiver) WithReceiver()](<#Receiver.WithReceiver>)
- [func New\(\) Receiver](<#New>)
- [func \(r \*Receiver\) WithPtrReceiver\(\)](<#Receiver.WithPtrReceiver>)
- [func \(r Receiver\) WithReceiver\(\)](<#Receiver.WithReceiver>)


## Constants
Expand Down
2 changes: 1 addition & 1 deletion testData/nested/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "github.com/princjef/gomarkdoc/testData/nested"

## Index

- [func Parent() int](<#Parent>)
- [func Parent\(\) int](<#Parent>)


<a name="Parent"></a>
Expand Down
2 changes: 1 addition & 1 deletion testData/nested/inner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "github.com/princjef/gomarkdoc/testData/nested/inner"

## Index

- [func Child() int](<#Child>)
- [func Child\(\) int](<#Child>)


<a name="Child"></a>
Expand Down
4 changes: 2 additions & 2 deletions testData/simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Package simple contains, some simple code to exercise basic scenarios for docume
## Index

- [type Num](<#Num>)
- [func AddNums(num1, num2 Num) Num](<#AddNums>)
- [func (n Num) Add(num Num) Num](<#Num.Add>)
- [func AddNums\(num1, num2 Num\) Num](<#AddNums>)
- [func \(n Num\) Add\(num Num\) Num](<#Num.Add>)


<a name="Num"></a>
Expand Down
4 changes: 2 additions & 2 deletions testData/tags/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Package tags contains code to demonstrate usage of build tags.

## Index

- [func Tagged() int](<#Tagged>)
- [func Untagged() int](<#Untagged>)
- [func Tagged\(\) int](<#Tagged>)
- [func Untagged\(\) int](<#Untagged>)


<a name="Tagged"></a>
Expand Down
6 changes: 3 additions & 3 deletions testData/unexported/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Package unexported contains some simple code to exercise basic scenarios for doc
## Index

- [type Num](<#Num>)
- [func AddNums(num1, num2 Num) Num](<#AddNums>)
- [func addInternal(num1, num2 Num) Num](<#addInternal>)
- [func (n Num) Add(num Num) Num](<#Num.Add>)
- [func AddNums\(num1, num2 Num\) Num](<#AddNums>)
- [func addInternal\(num1, num2 Num\) Num](<#addInternal>)
- [func \(n Num\) Add\(num Num\) Num](<#Num.Add>)


<a name="Num"></a>
Expand Down
2 changes: 1 addition & 1 deletion testData/untagged/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Package untagged contains code to demonstrate usage of build tags.

## Index

- [func Untagged() int](<#Untagged>)
- [func Untagged\(\) int](<#Untagged>)


<a name="Untagged"></a>
Expand Down

0 comments on commit 2ae7442

Please sign in to comment.