Merge pull request #121 from theSuess/master

feat: allow for custom link resolving
This commit is contained in:
Niklas Fasching 2025-05-12 19:51:31 +02:00 committed by GitHub
commit 6d8701e84d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 1 deletions

View file

@ -29,6 +29,7 @@ type Configuration struct {
DefaultSettings map[string]string // Default values for settings that are overriden by setting the same key in BufferSettings. DefaultSettings map[string]string // Default values for settings that are overriden by setting the same key in BufferSettings.
Log *log.Logger // Log is used to print warnings during parsing. Log *log.Logger // Log is used to print warnings during parsing.
ReadFile func(filename string) ([]byte, error) // ReadFile is used to read e.g. #+INCLUDE files. ReadFile func(filename string) ([]byte, error) // ReadFile is used to read e.g. #+INCLUDE files.
ResolveLink func(protocol string, description []Node, link string) Node
} }
// Document contains the parsing results and a pointer to the Configuration. // Document contains the parsing results and a pointer to the Configuration.
@ -93,6 +94,9 @@ func New() *Configuration {
}, },
Log: log.New(os.Stderr, "go-org: ", 0), Log: log.New(os.Stderr, "go-org: ", 0),
ReadFile: ioutil.ReadFile, ReadFile: ioutil.ReadFile,
ResolveLink: func(protocol string, description []Node, link string) Node {
return RegularLink{protocol, description, link, false}
},
} }
} }

View file

@ -329,7 +329,7 @@ func (d *Document) parseRegularLink(input string, start int) (int, Node) {
if len(linkParts) == 2 { if len(linkParts) == 2 {
protocol = linkParts[0] protocol = linkParts[0]
} }
return consumed, RegularLink{protocol, description, link, false} return consumed, d.ResolveLink(protocol, description, link)
} }
func (d *Document) parseTimestamp(input string, start int) (int, Node) { func (d *Document) parseTimestamp(input string, start int) (int, Node) {