Skip to content

In note text tagging improvement#283

Open
luginf wants to merge 15 commits intoqownnotes:mainfrom
luginf:in-note-text-tagging-improvement
Open

In note text tagging improvement#283
luginf wants to merge 15 commits intoqownnotes:mainfrom
luginf:in-note-text-tagging-improvement

Conversation

@luginf
Copy link
Copy Markdown

@luginf luginf commented Apr 16, 2026

fix non white space before a tag. Allow to use either # or @ for tags (# is default because it's generally more used, but we can change that if needed)

It looks like the other PR is still mixed up with this one...

luginf and others added 10 commits April 11, 2026 23:21
- Enable html:true by default so HTML comments (<!-- -->) are passed
  through as-is instead of being escaped as visible text
- Fix --strikethrough-- to use <s> tag instead of <del>, consistent
  with markdown ~~strikethrough~~ rendering
- Remove + item ordered list editor highlighting rule (was applying
  an unwanted heading style to list lines)
- Fix basePath undefined variable → path in relative URL resolution
- Register txt2tags_link before adding autolink/wikilink rules:
  ruler.before("txt2tags_link", ...) threw "Parser rule not found"
  when called before txt2tags_link was itself registered, aborting
  the entire plugin initialisation and breaking all txt2tags rendering

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…namespace

In Qt5, importing a JS file in QML binds the module's top-level `this` to
the QML global scope, so UMD modules export their constructors onto the
component via `g = this; g.markdownit = f()`, and `this.markdownit` works
in init().

In Qt6, the module's top-level `this` is the module namespace object
(e.g. MarkdownIt, MarkdownItTxt2tags), not the QML component scope.
So the constructors land on `MarkdownIt.markdownit` etc., and
`this.markdownit` in init() is undefined — causing silent init failure
and a blank preview.

Fix: resolve each constructor with `Namespace.name || this.name` so that
Qt6 uses the module namespace and Qt5 falls back to the component scope.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
In Qt6 QML, JavaScript files imported via 'import "foo.js" as Foo'
run in strict mode where `this` at the top level is undefined.
The UMD wrappers in markdown-it, markdown-it-deflist, markdown-it-katex
and markdown-it-txt2tags all fell back to `g = this` when window/global/self
were undefined, then threw TypeError setting a property on undefined.

Fix: insert `globalThis` before the `this` fallback in each UMD chain.
globalThis is always the real global object in Qt6's JS engine.

In init(), resolve constructors via `_g = globalThis || this` so that
Qt6 uses globalThis (where the modules now export) and Qt5 falls back
to the component scope (where the modules previously exported via this).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The root cause of Qt6 breakage: UMD modules used `g = this; g.markdownit = f()`
where `this` at module top-level is undefined in Qt6 strict mode, so the
assignment threw and nothing was exported.

Fix: declare `var markdownit` and `var markdownitTxt2tags` at the top level
of each JS file (outside the IIFE). Top-level vars are always accessible via
the QML module qualifier (MarkdownIt.markdownit, MarkdownItTxt2tags.markdownitTxt2tags)
in both Qt5 and Qt6 — no runtime this/globalThis lookup needed.

Also removed the unused deflist and katex plugins to simplify the script.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@pbek
Copy link
Copy Markdown
Member

pbek commented Apr 16, 2026

You are changing two scripts with that PR.

@pbek pbek added the wip Work in progress label Apr 16, 2026
@pbek
Copy link
Copy Markdown
Member

pbek commented Apr 17, 2026

@Maboroshy, are you ok with those changes?

Comment thread in-note-text-tagging/info.json Outdated
@@ -4,7 +4,7 @@
"script": "in-note-text-tagging.qml",
"authors": ["@Maboroshy"],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add yourself.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the in-note text tagging script by expanding tag detection to support multiple configurable markers (defaulting to #), and by tightening the “tag boundary” rules (requiring whitespace/start-of-line before a tag).

Changes:

  • Add settings to enable/disable two independent tag markers (tagMarker / tagMarker2) and a maxTagLength limit for tag extraction.
  • Update tag parsing and autocompletion logic to recognize tags prefixed by any enabled marker and to avoid matching tags preceded by non-whitespace.
  • Bump script version to 0.2.1.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
in-note-text-tagging/info.json Version bump for the script release.
in-note-text-tagging/in-note-text-tagging.qml Adds multi-marker support, max tag length handling, and updated regex-based detection/replacement logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +168 to +173
}

const tag = tagMarker + tagName.replace(/ /g, "_");
var tag = tagMarker + tagName.replace(/ /g, "_");
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the "add" action, noteText.search(tagRegExp) > 0 fails to detect an existing tag at the start of the note (search returns 0). This can cause duplicate tags to be added. Use a condition that treats index 0 as found (e.g., >= 0 / !== -1).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Changed > 0 to !== -1 on line 169 so a tag at position 0 (start of note) is correctly detected as
already existing, preventing duplicates.

Comment on lines 172 to 174

const tag = tagMarker + tagName.replace(/ /g, "_");
var tag = tagMarker + tagName.replace(/ /g, "_");

Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var tag = tagMarker + ... always uses the primary marker when writing tags. If useMarker1 is disabled (and only the secondary marker is enabled), the script will still insert tags with the disabled marker. Pick the marker to write based on which marker(s) are enabled (e.g., prefer primary if enabled, otherwise secondary).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines +219 to +220
case "rename":
return noteText.replace(tagRegExp, tagMarker + newTagName.replace(/ /g, "_"));
return noteText.replace(tagRegExp, "$1" + tagMarker + newTagName.replace(/ /g, "_"));
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rename replacement uses tagMarker (primary) regardless of which marker was actually present in the note text, so renaming an @tag can silently turn it into a #newTag (and it also breaks if useMarker1 is off). Consider capturing the matched marker in the regex (or otherwise determining which marker matched) and reusing that marker in the replacement.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also fixed

  • Regex: (%1) captures the marker found in the note → group 2
  • rename: "$1$2" + newTagName — reuses the exact marker from the note (@tag@newTag, #tag → #newtag)
  • remove: "$1" — unchanged, still correct
  • add: writeMarker() — unchanged, uses the preferred marker for new tags

@Maboroshy
Copy link
Copy Markdown
Contributor

@Maboroshy, are you ok with those changes?

As you say. That was so long ago, I'm not into reviewing them. I'm certainly not against the progress.

@pbek
Copy link
Copy Markdown
Member

pbek commented Apr 17, 2026

Fine with me then. 😉

luginf added 2 commits April 17, 2026 19:59
 Changed > 0 to !== -1 on line 169 so a tag at position 0 (start of note) is correctly detected as
  already existing, preventing duplicates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wip Work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants