Skip to content

Obsidian export: non-ASCII community labels collapse to community/_ tags, and canvas colorGroups query the unsanitized label #2862

Closed

Description

@josh-leung-KR

Summary

_obsidian_tag() strips every non-ASCII character, so a community label written in any
non-Latin script collapses to underscores. Every note in such a community gets the same
tag, and the per-community Dataview query in the _COMMUNITY_*.md note points at that
collapsed tag. Separately, the canvas colorGroups query is built from the unsanitized
label, so on the same vault the canvas asks for a tag that no note carries.

Repro (current HEAD, also 0.9.11)

from graphify.export import _obsidian_tag
_obsidian_tag("참여기업 로고 자산")     # -> '__'      (Korean)
_obsidian_tag("発注者 体系")            # -> '_'       (Japanese)
_obsidian_tag("Träning Pipeline")      # -> 'Trning_Pipeline'   (accented Latin dropped)
_obsidian_tag("Attention Mechanism")   # -> 'Attention_Mechanism'  (ASCII is fine)

graphify/export.py:

def _obsidian_tag(name: str) -> str:
    return re.sub(r"[^a-zA-Z0-9_\-/]", "", name.replace(" ", "_"))   # line 106

and the canvas group query does not go through it:

"query": f"tag:#community/{label.replace(' ', '_')}",                 # line 835

Impact (measured)

A 317-node vault with 20 Korean community labels: 290 of 337 notes ended up tagged
community/_ or community/__. Tag-based navigation and the generated
TABLE ... FROM #community/<tag> query stop distinguishing communities, and the canvas
color groups match nothing because they query #community/참여기업_로고_자산 while the
notes carry #community/__.

The community: frontmatter field keeps the readable name, so the data is not lost — only
the navigation surface is.

Why the sanitizer is stricter than it needs to be

Obsidian tags accept letters from any language (they exclude spaces and most punctuation,
and a tag cannot be digits-only). The docstring's premise — "alphanumerics, hyphens,
underscores and slashes only" — holds for ASCII punctuation but not for scripts.

Suggested fix

def _obsidian_tag(name: str) -> str:
    # \w is Unicode-aware in Python 3: keeps letters/digits/underscore in any script,
    # still strips spaces (already converted), '#', '·', and other punctuation.
    tag = re.sub(r"[^\w\-/]", "", name.replace(" ", "_"))
    return tag or "unnamed"          # digits-only / empty labels are invalid tags

and make the canvas use the same function so notes and canvas agree:

"query": f"tag:#community/{_obsidian_tag(label)}",

Happy to send a PR with the two-line change plus a test that asserts a Korean and an
accented-Latin label survive and that canvas/query use the identical string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions