Skip to content

Commit 2f088a1

Browse files
Revert "Fix associated keywords for headlines"
This reverts commit 337f973. issues with rewinding - looks like lists and other places would need to be updated to handle -1 since they were built under the assumption of >= 0. Not finding the time for this right now so reverting to prevent people on latest from running into this See #127
1 parent 6b90da7 commit 2f088a1

File tree

5 files changed

+8
-65
lines changed

5 files changed

+8
-65
lines changed

org/document.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,6 @@ func (d *Document) parseMany(i int, stop stopFn) (int, []Node) {
255255
start, nodes := i, []Node{}
256256
for i < len(d.tokens) && !stop(d, i) {
257257
consumed, node := d.parseOne(i, stop)
258-
if consumed == -1 {
259-
break
260-
}
261258
i += consumed
262259
nodes = append(nodes, node)
263260
}

org/keyword.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,11 @@ func (d *Document) parseKeyword(i int, stop stopFn) (int, Node) {
7373
}
7474
return 1, k
7575
case "CAPTION", "ATTR_HTML":
76-
consumed, node, ok := d.parseAffiliated(i, stop)
77-
if ok {
76+
consumed, node := d.parseAffiliated(i, stop)
77+
if consumed != 0 {
7878
return consumed, node
79-
} else if i+consumed <= len(d.tokens)-1 {
80-
return -1, nil
8179
}
82-
return 1, k
80+
fallthrough
8381
default:
8482
if _, ok := d.BufferSettings[k.Key]; ok {
8583
d.BufferSettings[k.Key] = strings.Join([]string{d.BufferSettings[k.Key], k.Value}, "\n")
@@ -102,7 +100,7 @@ func (d *Document) parseNodeWithName(k Keyword, i int, stop stopFn) (int, Node)
102100
return consumed + 1, NodeWithName{k.Value, node}
103101
}
104102

105-
func (d *Document) parseAffiliated(i int, stop stopFn) (int, Node, bool) {
103+
func (d *Document) parseAffiliated(i int, stop stopFn) (int, Node) {
106104
start, meta := i, Metadata{}
107105
for ; !stop(d, i) && d.tokens[i].kind == "keyword"; i++ {
108106
switch k := parseKeyword(d.tokens[i]); k.Key {
@@ -127,18 +125,18 @@ func (d *Document) parseAffiliated(i int, stop stopFn) (int, Node, bool) {
127125
}
128126
meta.HTMLAttributes = append(meta.HTMLAttributes, attributes)
129127
default:
130-
return i - start, nil, false
128+
return 0, nil
131129
}
132130
}
133131
if stop(d, i) {
134-
return i - start, nil, false
132+
return 0, nil
135133
}
136134
consumed, node := d.parseOne(i, stop)
137135
if consumed == 0 || node == nil {
138-
return i - start, nil, false
136+
return 0, nil
139137
}
140138
i += consumed
141-
return i - start, NodeWithMeta{node, meta}, true
139+
return i - start, NodeWithMeta{node, meta}
142140
}
143141

144142
func parseKeyword(t token) Keyword {

org/testdata/keywords.html

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,35 +53,7 @@ <h2 id="headline-2">
5353
</li>
5454
<li><a href="#headline-2">table of contents</a>
5555
</li>
56-
<li><a href="#headline-3">meta keywords</a>
57-
<ul>
58-
<li><a href="#headline-4">nested</a>
59-
</li>
60-
</ul>
61-
</li>
62-
<li><a href="#headline-5">headline with dangling meta keyword</a>
63-
</li>
6456
</ul>
6557
</nav>
6658
</div>
6759
</div>
68-
<div id="outline-container-headline-3" class="outline-2 first">
69-
<h2 id="headline-3">
70-
meta keywords
71-
</h2>
72-
<div id="outline-text-headline-3" class="outline-text-2">
73-
<p>Keywords like <code class="verbatim">ATTR_HTML</code> and <code class="verbatim">CAPTION</code> are special and apply to the following node.
74-
We don&#39;t want them to become part of the previous headline body unilke everything
75-
else - unless there are no further nodes in the document.</p>
76-
<div id="outline-container-headline-4" class="outline-3 nested">
77-
<h3 id="headline-4">
78-
nested
79-
</h3>
80-
</div>
81-
</div>
82-
</div>
83-
<div id="outline-container-headline-5" class="outline-2 second">
84-
<h2 id="headline-5">
85-
headline with dangling meta keyword
86-
</h2>
87-
</div>

org/testdata/keywords.org

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,3 @@ A table of contents can be rendered anywhere in the document by using
3232
#+end_src
3333
Where =$n= is the max headline lvl that will be included. You can use =headlines 0= to include all headlines.
3434
#+TOC: headlines 0
35-
36-
#+ATTR_HTML: :class first
37-
* meta keywords
38-
Keywords like =ATTR_HTML= and =CAPTION= are special and apply to the following node.
39-
We don't want them to become part of the previous headline body unilke everything
40-
else - unless there are no further nodes in the document.
41-
#+ATTR_HTML: :class nested
42-
** nested
43-
#+ATTR_HTML: :class second
44-
* headline with dangling meta keyword
45-
#+ATTR_HTML: :class dangling1
46-
#+ATTR_HTML: :class dangling2

org/testdata/keywords.pretty_org

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,3 @@ A table of contents can be rendered anywhere in the document by using
3232
#+END_SRC
3333
Where =$n= is the max headline lvl that will be included. You can use =headlines 0= to include all headlines.
3434
#+TOC: headlines 0
35-
36-
#+ATTR_HTML: :class first
37-
* meta keywords
38-
Keywords like =ATTR_HTML= and =CAPTION= are special and apply to the following node.
39-
We don't want them to become part of the previous headline body unilke everything
40-
else - unless there are no further nodes in the document.
41-
#+ATTR_HTML: :class nested
42-
** nested
43-
#+ATTR_HTML: :class second
44-
* headline with dangling meta keyword
45-
#+ATTR_HTML: :class dangling1
46-
#+ATTR_HTML: :class dangling2

0 commit comments

Comments
 (0)