Skip to content

Commit

Permalink
Add support for COMMENT headlines
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasfasching committed Aug 20, 2024
1 parent 7bc6100 commit 6cfae31
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion org/headline.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Headline struct {
Index int
Lvl int
Status string
IsComment bool
Priority string
Properties *PropertyDrawer
Title []Node
Expand Down Expand Up @@ -59,7 +60,10 @@ func (d *Document) parseHeadline(i int, parentStop stopFn) (int, Node) {
headline.Priority = text[2:3]
text = strings.TrimSpace(text[4:])
}

if strings.HasPrefix(text, "COMMENT ") {
headline.IsComment = true
text = strings.TrimPrefix(text, "COMMENT ")
}
if m := tagRegexp.FindStringSubmatch(text); m != nil {
text = m[1]
headline.Tags = strings.FieldsFunc(m[2], func(r rune) bool { return r == ':' })
Expand Down Expand Up @@ -104,6 +108,9 @@ func (h Headline) ID() string {
}

func (h Headline) IsExcluded(d *Document) bool {
if h.IsComment {
return true
}
for _, excludedTag := range strings.Fields(d.Get("EXCLUDE_TAGS")) {
for _, tag := range h.Tags {
if tag == excludedTag {
Expand Down
2 changes: 2 additions & 0 deletions org/testdata/headlines.org
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ it's possible to use =#+SETUPFILE= - in this case the setup file contains the fo
this headline and it's content are not exported as it is marked with an =EXCLUDE_TAGS= tag.
By default =EXCLUDE_TAGS= is just =:noexport:=.

* TODO [#A] COMMENT commented headline
this headline is commented out. see [[https://orgmode.org/manual/Comment-Lines.html][comment lines]]
* malformed property drawer
:PROPERTIES:
not a property
Expand Down
2 changes: 2 additions & 0 deletions org/testdata/headlines.pretty_org
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ it's possible to use =#+SETUPFILE= - in this case the setup file contains the fo
this headline and it's content are not exported as it is marked with an =EXCLUDE_TAGS= tag.
By default =EXCLUDE_TAGS= is just =:noexport:=.

* TODO [#A] commented headline
this headline is commented out. see [[https://orgmode.org/manual/Comment-Lines.html][comment lines]]
* malformed property drawer
:PROPERTIES:
not a property
Expand Down
2 changes: 2 additions & 0 deletions org/testdata/misc.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ <h4 id="headline-5">
this headline and it&#39;s content are not exported as it is marked with an =EXCLUDE_TAGS= tag.
By default =EXCLUDE_TAGS= is just =:noexport:=.

* TODO [#A] COMMENT commented headline
this headline is commented out. see [[https://orgmode.org/manual/Comment-Lines.html][comment lines]]
* malformed property drawer
:PROPERTIES:
not a property
Expand Down

0 comments on commit 6cfae31

Please sign in to comment.