Skip to content

Commit

Permalink
Tag color names: They don't generalize to chair and private tags.
Browse files Browse the repository at this point in the history
So ~red is red, and ~~red is red, but if reject is red, then ~~reject is not.
  • Loading branch information
kohler committed Mar 6, 2021
1 parent 2d25c64 commit ca3f049
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
24 changes: 16 additions & 8 deletions lib/tagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,12 +646,20 @@ function is_style($tag, $match = self::STYLE_FG_BG) {
}

/** @return string */
function color_regex() {
private function color_regex() {
if (!$this->color_re) {
$re = "{(?:\\A| )(?:\\d*~|~~|)(" . join("|", array_keys($this->style_info_lmap));
foreach ($this->filter("colors") as $t)
$re .= "|" . $t->tag_regex();
$this->color_re = $re . ")(?=\\z|[# ])}i";
$re = "{(?:\\A| )(?:(?:\\d*~|~~|)(" . join("|", array_keys($this->style_info_lmap));
$any = false;
foreach ($this->filter("colors") as $t) {
if (!$any) {
$re .= ")|(";
$any = true;
} else {
$re .= "|";
}
$re .= $t->tag_regex();
}
$this->color_re = $re . "))(?=\\z|[# ])}i";
}
return $this->color_re;
}
Expand All @@ -663,13 +671,13 @@ function styles($tags, $match = 0, $no_pattern_fill = false) {
}
if (!$tags
|| $tags === " "
|| !preg_match_all($this->color_regex(), $tags, $m)) {
|| !preg_match_all($this->color_regex(), $tags, $ms, PREG_SET_ORDER)) {
return null;
}
$classes = [];
$info = 0;
foreach ($m[1] as $tag) {
$ltag = strtolower($tag);
foreach ($ms as $m) {
$ltag = strtolower($m[1] ? : $m[2]);
$t = $this->check($ltag);
$ks = $t ? $t->colors : [$ltag];
foreach ($ks as $k) {
Expand Down
2 changes: 1 addition & 1 deletion src/settings/s_tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function parse(SettingValues $sv, Si $si) {
$ts = array();
foreach ($sv->conf->tags()->canonical_colors() as $k) {
if ($sv->has_reqv("tag_color_$k")) {
foreach ($this->my_parse_list($sv->si("tag_color_$k"), Tagger::NOPRIVATE | Tagger::NOCHAIR | Tagger::NOVALUE | Tagger::ALLOWSTAR, false) as $t) {
foreach ($this->my_parse_list($sv->si("tag_color_$k"), Tagger::NOPRIVATE | Tagger::NOVALUE | Tagger::ALLOWSTAR, false) as $t) {
$ts[] = $t . "=" . $k;
}
}
Expand Down

0 comments on commit ca3f049

Please sign in to comment.