Implement #+LINK
This commit is contained in:
parent
47a3653d61
commit
1e36b3b46b
6 changed files with 19 additions and 0 deletions
|
@ -36,6 +36,7 @@ type Document struct {
|
||||||
Path string // Path of the file containing the parse input - used to resolve relative paths during parsing (e.g. INCLUDE).
|
Path string // Path of the file containing the parse input - used to resolve relative paths during parsing (e.g. INCLUDE).
|
||||||
tokens []token
|
tokens []token
|
||||||
baseLvl int
|
baseLvl int
|
||||||
|
Links map[string]string
|
||||||
Nodes []Node
|
Nodes []Node
|
||||||
NamedNodes map[string]Node
|
NamedNodes map[string]Node
|
||||||
Outline Outline // Outline is a Table Of Contents for the document and contains all sections (headline + content).
|
Outline Outline // Outline is a Table Of Contents for the document and contains all sections (headline + content).
|
||||||
|
@ -121,6 +122,7 @@ func (c *Configuration) Parse(input io.Reader, path string) (d *Document) {
|
||||||
Outline: Outline{outlineSection, outlineSection, 0},
|
Outline: Outline{outlineSection, outlineSection, 0},
|
||||||
BufferSettings: map[string]string{},
|
BufferSettings: map[string]string{},
|
||||||
NamedNodes: map[string]Node{},
|
NamedNodes: map[string]Node{},
|
||||||
|
Links: map[string]string{},
|
||||||
Path: path,
|
Path: path,
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
|
@ -338,6 +338,9 @@ func (w *HTMLWriter) WriteRegularLink(l RegularLink) {
|
||||||
if l.Protocol == "file" {
|
if l.Protocol == "file" {
|
||||||
url = url[len("file:"):]
|
url = url[len("file:"):]
|
||||||
}
|
}
|
||||||
|
if prefix := w.document.Links[l.Protocol]; prefix != "" {
|
||||||
|
url = html.EscapeString(prefix) + url[len(l.Protocol)+1:]
|
||||||
|
}
|
||||||
description := url
|
description := url
|
||||||
if l.Description != nil {
|
if l.Description != nil {
|
||||||
description = w.WriteNodesAsString(l.Description...)
|
description = w.WriteNodesAsString(l.Description...)
|
||||||
|
|
|
@ -62,6 +62,11 @@ func (d *Document) parseKeyword(i int, stop stopFn) (int, Node) {
|
||||||
return d.loadSetupFile(k)
|
return d.loadSetupFile(k)
|
||||||
case "INCLUDE":
|
case "INCLUDE":
|
||||||
return d.parseInclude(k)
|
return d.parseInclude(k)
|
||||||
|
case "LINK":
|
||||||
|
if parts := strings.Split(k.Value, " "); len(parts) >= 2 {
|
||||||
|
d.Links[parts[0]] = parts[1]
|
||||||
|
}
|
||||||
|
return 1, k
|
||||||
case "CAPTION", "ATTR_HTML":
|
case "CAPTION", "ATTR_HTML":
|
||||||
consumed, node := d.parseAffiliated(i, stop)
|
consumed, node := d.parseAffiliated(i, stop)
|
||||||
if consumed != 0 {
|
if consumed != 0 {
|
||||||
|
|
5
org/testdata/inline.html
vendored
5
org/testdata/inline.html
vendored
|
@ -165,4 +165,9 @@ timestamps
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<p>
|
||||||
|
<code class="verbatim">#+LINK</code> based links: <a href="https://www.example.com/foobar">https://www.example.com/foobar</a>
|
||||||
|
</p>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
2
org/testdata/inline.org
vendored
2
org/testdata/inline.org
vendored
|
@ -37,3 +37,5 @@
|
||||||
- <2019-01-06 Sun 18:00 +1w>
|
- <2019-01-06 Sun 18:00 +1w>
|
||||||
- <2019-01-06 18:00>
|
- <2019-01-06 18:00>
|
||||||
- <2019-01-06 18:00 +1w>
|
- <2019-01-06 18:00 +1w>
|
||||||
|
- =#+LINK= based links: [[example:foobar]]
|
||||||
|
#+LINK: example https://www.example.com/
|
||||||
|
|
2
org/testdata/inline.pretty_org
vendored
2
org/testdata/inline.pretty_org
vendored
|
@ -37,3 +37,5 @@
|
||||||
- <2019-01-06 Sun 18:00 +1w>
|
- <2019-01-06 Sun 18:00 +1w>
|
||||||
- <2019-01-06 Sun 18:00>
|
- <2019-01-06 Sun 18:00>
|
||||||
- <2019-01-06 Sun 18:00 +1w>
|
- <2019-01-06 Sun 18:00 +1w>
|
||||||
|
- =#+LINK= based links: [[example:foobar]]
|
||||||
|
#+LINK: example https://www.example.com/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue