Skip to content

Commit

Permalink
Don't parse Markdown table headers a colon tags (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-menu authored Apr 24, 2022
1 parent 94e8a0d commit 7622d9e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ All notable changes to this project will be documented in this file.
* [#126](https://github.com/mickael-menu/zk/issues/126) Embedded image links shown as not found.
* [#152](https://github.com/mickael-menu/zk/issues/152) Incorrect timezone for natural dates.
* [#170](https://github.com/mickael-menu/zk/issues/170) Broken wiki links in subdirectories.
* [#185](https://github.com/mickael-menu/zk/issues/185) Don't parse a Markdown table header as a colon tag.


## 0.9.0
Expand Down
18 changes: 17 additions & 1 deletion internal/adapter/markdown/extensions/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (p *colontagParser) Parse(parent ast.Node, block text.Reader, pc parser.Con

} else if char == ':' {
tag = strings.TrimSpace(tag)
if len(tag) == 0 {
if !isValidTag(tag) {
break
}
tags = append(tags, tag)
Expand Down Expand Up @@ -260,3 +260,19 @@ func isValidTagChar(r rune, excluded rune) bool {
r == '&' || r == '+' || r == '=' || r == ':' ||
r == '#')
}

func isValidTag(tag string) bool {
if len(tag) == 0 {
return false
}

// Prevent Markdown table syntax to be parsed a a colon tag, e.g. |:---:|
// https://github.com/mickael-menu/zk/issues/185
for _, c := range tag {
if c != '-' {
return true
}
}

return false
}
12 changes: 12 additions & 0 deletions tests/issue-185.tesh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Markdown table syntax is parsed as colon tags
# https://github.com/mickael-menu/zk/issues/185

$ cd blank

$ echo "[format.markdown] colon-tags = true" > .zk/config.toml
$ echo "|:---:|" > test.md

$ zk tag list
2>
2>Found 0 tag

0 comments on commit 7622d9e

Please sign in to comment.