Skip to content

Commit

Permalink
Fix logicworld links
Browse files Browse the repository at this point in the history
  • Loading branch information
pipe01 committed Apr 9, 2024
1 parent 872f633 commit bca9a8c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
6 changes: 3 additions & 3 deletions inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

var (
urlRe = `((https?|ftp):\/\/|\/)[-A-Za-z0-9+&@#\/%?=~_|!:,.;\(\)]+`
urlRe = `((https?|ftp|logicworld):\/\/|\/)[-A-Za-z0-9+&@#\/%?=~_|!:,.;\(\)]+`
anchorRe = regexp.MustCompile(`^(<a\shref="` + urlRe + `"(\stitle="[^"<>]+")?\s?>` + urlRe + `<\/a>)`)

// https://www.w3.org/TR/html5/syntax.html#character-references
Expand Down Expand Up @@ -764,7 +764,7 @@ var protocolPrefixes = [][]byte{
[]byte("ftp://"),
[]byte("file://"),
[]byte("mailto:"),
[]byte("logicworld:"),
[]byte("logicworld://"),
}

const shortestPrefix = 6 // len("ftp://"), the shortest of the above
Expand All @@ -775,7 +775,7 @@ func maybeAutoLink(p *Markdown, data []byte, offset int) (int, *Node) {
return 0, nil
}
for _, prefix := range protocolPrefixes {
endOfHead := offset + 8 // 8 is the len() of the longest prefix
endOfHead := offset + 13 // 13 is the len() of the longest prefix
if endOfHead > len(data) {
endOfHead = len(data)
}
Expand Down
45 changes: 25 additions & 20 deletions markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ func New(opts ...Option) *Markdown {
p.inlineCallback['H'] = maybeAutoLink
p.inlineCallback['M'] = maybeAutoLink
p.inlineCallback['F'] = maybeAutoLink
p.inlineCallback['l'] = maybeAutoLink
}
if p.extensions&Footnotes != 0 {
p.notes = make([]*reference, 0)
Expand Down Expand Up @@ -360,8 +361,8 @@ func WithImageFound(fn func(src string)) Option {
// In Markdown, the link reference syntax can be made to resolve a link to
// a reference instead of an inline URL, in one of the following ways:
//
// * [link text][refid]
// * [refid][]
// - [link text][refid]
// - [refid][]
//
// Usually, the refid is defined at the bottom of the Markdown document. If
// this override function is provided, the refid is passed to the override
Expand All @@ -378,21 +379,25 @@ func WithRefOverride(o ReferenceOverrideFunc) Option {
// block of markdown-encoded text.
//
// The simplest invocation of Run takes one argument, input:
// output := Run(input)
//
// output := Run(input)
//
// This will parse the input with CommonExtensions enabled and render it with
// the default HTMLRenderer (with CommonHTMLFlags).
//
// Variadic arguments opts can customize the default behavior. Since Markdown
// type does not contain exported fields, you can not use it directly. Instead,
// use the With* functions. For example, this will call the most basic
// functionality, with no extensions:
// output := Run(input, WithNoExtensions())
//
// output := Run(input, WithNoExtensions())
//
// You can use any number of With* arguments, even contradicting ones. They
// will be applied in order of appearance and the latter will override the
// former:
// output := Run(input, WithNoExtensions(), WithExtensions(exts),
// WithRenderer(yourRenderer))
//
// output := Run(input, WithNoExtensions(), WithExtensions(exts),
// WithRenderer(yourRenderer))
func Run(input []byte, opts ...Option) []byte {
r := NewHTMLRenderer(HTMLRendererParameters{
Flags: CommonHTMLFlags,
Expand Down Expand Up @@ -506,35 +511,35 @@ func (p *Markdown) parseRefsToAST() {
//
// Consider this markdown with reference-style links:
//
// [link][ref]
// [link][ref]
//
// [ref]: /url/ "tooltip title"
// [ref]: /url/ "tooltip title"
//
// It will be ultimately converted to this HTML:
//
// <p><a href=\"/url/\" title=\"title\">link</a></p>
// <p><a href=\"/url/\" title=\"title\">link</a></p>
//
// And a reference structure will be populated as follows:
//
// p.refs["ref"] = &reference{
// link: "/url/",
// title: "tooltip title",
// }
// p.refs["ref"] = &reference{
// link: "/url/",
// title: "tooltip title",
// }
//
// Alternatively, reference can contain information about a footnote. Consider
// this markdown:
//
// Text needing a footnote.[^a]
// Text needing a footnote.[^a]
//
// [^a]: This is the note
// [^a]: This is the note
//
// A reference structure will be populated as follows:
//
// p.refs["a"] = &reference{
// link: "a",
// title: "This is the note",
// noteID: <some positive int>,
// }
// p.refs["a"] = &reference{
// link: "a",
// title: "This is the note",
// noteID: <some positive int>,
// }
//
// TODO: As you can see, it begs for splitting into two dedicated structures
// for refs and for footnotes.
Expand Down

0 comments on commit bca9a8c

Please sign in to comment.