Styled Note Markup trimmer gramplet?

The Note Editor has a Clear Markup feature. It clears ALL stylings applied to the selected text in a Note.

But you cannot clear text with multiple stylings without clearing all markup on that text. (I had to boost text size on a few notes to be readable on high-res monitor. Beginning with 5.2, the base font size in Themes began working with notes too. Yay! But now I want to eliminate those no-longer-needed re-sizings without clearing all the other stylings.)


It would be useful to have a Gramplet for the Notes category (only) that lists the stylings in a table with columns for: a checkbox, startswith, styling type, and the 1st 40 chars of text.

The first generation of the addon could just allow sorting on the columns and have a Delete for the selected checkboxes. Selecting a row could navigate the Note Editor focus to the string and select that string. (Which would allow adding another styling from the Note Editor toolbar.)

A future generation could have a ‘paintbrush’ that adds temporary Rows to the table with the Active styling. If the Active styling was “Link”, then you could paint all the Names (or Places or text to be hotlinked) to create a placeholder row for each startswith string, undock the gramplet, change to a Category and drag objects (or paste URLs) to finish the linking.

Prior to Gramps 5.2, The Notes display of base font size was absolute. It ignored when the Themes addon preferences selection that was used to increase the font size in the rest of the interface.

So, to increase the tiny default of 9pt to something readable by the eyes of … ahem… mature users, it was necessary to Edit the styling of the Note content to increase the font size. Note Displays were enhanced for 5.2 … found the Enhancement Request but I cannot find the PR.)

Now that the Note Editor uses the Themes to set the base font size, I need to clear those extra stylings out of the Notes. (The varying manually-set sizes make Notes in Reports appear irregular.)

But the ⌫ (Clear Markup) button clears ALL the markup for the selected text. And I really don’t want to clear the Links and rebuild them. They are too painful to set.

Individual Note cannot be targeted for export. So editing the XML and overwriting is not an option. There is no “exploded” view for an object that allows direct editing outside the klutz proofing of the GUI

Perhaps it might be possible to use SuperTool by @kku to generate a table of stylings for a particular Note… (with columns for styling type, begin, end, and a 20 character snippet of the affected text) and allow row to be selected, then that style deleted? I did not find the font decorations listed in the SuperTool help for Note objects.

I posted an idea that had no response. So maybe a scaled back idea would raise comments?

(Gramps 5.22 and Fedora 37)

I wrote a quick Supertool script as a proof-of-concept:

Is this something you had in mind? I can tweak it as needed or e.g. make it a gramplet or something.

This is Great! Thank you! I will have to try it out. With this example, I should be able puzzle out how to filter for notes that have a “Fontsize” (or other) markup too. Then filter to walk through just that problem.

Thanks again!

This was a good experiment for trying the @include in the SuperTool Initialization statements too.

I always forget what the fallback paths would be when looking for SuperTool Include files (Since the first fallback is the location of the script, I wondered where it would look when the script was loaded from a Note… which is my preferred organizational method.)

There are sure to be some typos. The text in the errors section cannot be selected for copying. And isn’t piped to the “Capture output”. So the following is transcribed.

Include file 'note-markup.py' not found; looked at
- /home/<username>/.gramps/plugins/SuperTool/scripts/note-markup.py
- /home/<username>/supertool/note-markup.py
- /home/<username>/.gramps/plugins/SuperTool/note-markup.py
- /home/<username>/note-markup.py

After a bit of experimenting to discover when changes are applied, this worked extremely well. Thank you!

It did feel more safe after changing the checkboxes to default to be deselected. With them set to True, it was too easy to clear markup unintentionally.

Paste the following into a new Note of type “SuperTool script” and save
Change to Notes category
Run Tools → Isotammi tools → SuperTool
File → Load from Note
select the record(s) in the Notes view (select only a small number …25 for fewer)
Click Execute

Select the checkbox of the style(s) to cleared and click Clear markup
The Undo is only effective until clicking Next or Quit

Some link samples:

[Gramps SuperTool script file]
version=1

[title]
Note markup cleanup

[description]
Open a dialog listing text stylings in selected Notes, allow deleting from a list

https://gramps.discourse.group/t/styled-note-markup-trimmer-gramplet/5396

created by Kari Kujansuu Feb 2025
https://github.com/kkujansuu/supertool-scripts/tree/main/note-markup

[category]
Notes

[initial_statements]
# @include note-markup.py
from gi.repository import Gtk
from gramps.gen.lib import StyledTextTag
from gramps.gui.widgets import StyledTextEditor

def get_markup(note):
    for tag in note.get_styledtext().tags:
	    print(tag.name, tag.value, tag.ranges)
#	    s = note.get_styledtext()._string
	    s = note.get()
	    for a,b in tag.ranges:
		    print("-", s[a:b])
		    yield (tag.name, tag.value, (a,b), s[a:b])

def show_note(note):
    grid = Gtk.Grid()
    grid.set_column_spacing(5)
    grid.set_row_spacing(2)
    cb_list = []
    for row, (name, value, range, text) in enumerate(get_markup(note)):
        if not value: value = ""
        cb = Gtk.CheckButton()
        cb.set_active(False)
        lbl_name = Gtk.Label(name)
        lbl_name.set_halign(Gtk.Align.START)
        lbl_value = Gtk.Label(value)
        lbl_value.set_halign(Gtk.Align.START)
        lbl_text = Gtk.Label(text)
        lbl_text.set_halign(Gtk.Align.START)
        grid.attach(cb, 0, row, 1, 1)
        grid.attach(lbl_name, 1, row, 1, 1)
        grid.attach(lbl_value, 2, row, 1, 1)
        grid.attach(lbl_text, 3, row, 1, 1)
        tag = StyledTextTag(name, value, [range])
        cb_list.append((cb, tag))
    if len(cb_list) == 0:
        return
    dlg = Gtk.Dialog()
    dlg.set_title("Note markup")
    c = dlg.get_content_area()
    c.add(Gtk.Label("Note " + note.gramps_id))
    c.add(grid)
    c.pack_start(Gtk.HSeparator(), False, False, 10)

    scrolledwindow = Gtk.ScrolledWindow()
    scrolledwindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
    texteditor = StyledTextEditor()
    texteditor.set_editable(False)
    texteditor.set_wrap_mode(Gtk.WrapMode.WORD)
    texteditor.set_text(note.get_styledtext())
    scrolledwindow.set_size_request(600, 300)
    scrolledwindow.add(texteditor)
    c.add(scrolledwindow) #, True, True, 0)

    dlg.add_button("Clear markup", 1)
    dlg.add_button("Undo", 6)
    dlg.add_button("Next", 2)
    dlg.add_button("Quit", 3)
    dlg.show_all()
    old_text = None
    old_tags = note.get_styledtext().tags[:]
    while True:
        rsp = dlg.run()
        if rsp == 2:
            break
        if rsp == 6:
            note.get_styledtext().tags = old_tags
            db.commit_note(note, trans)
            texteditor.set_text(note.get_styledtext())
        if rsp == 3:
            dlg.destroy()
            raise RuntimeError("Canceled")
        if rsp == 1:
            tags = []
            for cb, tag in cb_list:
                print(cb.get_active())
                if not cb.get_active():
                    tags.append(tag)
            note.get_styledtext().tags = tags
            db.commit_note(note, trans)
            texteditor.set_text(note.get_styledtext())
    dlg.destroy()

[statements]
show_note(note)

[scope]
selected

This would make a great Notes category gramplet.

The wide layout makes use in Bottombar gramplet splitbar preferred.

However, the action buttons would be more consistently accessible at the top rather than then bottom of the gramplet. And right aligning the buttons would ensure the primary Clear markup action is always accessible.

Similar access to buttons problem exist in the Place Cleanup by @prculley and Data Entry by @dsblank (and Gary Burton) gramplets. Even Find and Reset buttons of the Filter Gramplets suffer from occasionally scrolling off the bottom.) Another approach is used by the Import Text by @dsblank and Consanguinity by @ukulelehans gramplets. They lock the buttons to the bottom of the view area. (But Consanguinity’s action buttons should probably be to the left of its radio buttons.)

As a Note category Gramplet it would apply to the Active Note focus, so the Next button could be eliminated. As could the Quit button. A select all/none toggle would be useful too.

Rather than create the Gramplet, can we discuss the process of adapting a SuperTool script to a plugin, then illustrate the workflow?

I imagine that the steps are:

  1. develop and test the functionality in SuperTool
  2. create a placeholder plugin shell and Experimental/Beta registration
  3. share to a personal GitHub repository with a README.md containing the original SuperTool script (so that its functionality can be beta tested while developing the plugin) and Rationale.
  4. link the help_url to the shared GitHub README.md file
  5. convert the SuperTool script to the plugin using SuperTool’s libraries with a requires
  6. try “publishing” a private repository (with Addon Manager compatibility) for beta testing
  7. adapt the plugin to not have any "requires’ prerequisites
  8. establish a wiki Addon: page (can just forward to the README.md file) and
  9. promote registration to Stable status, appropriate Audience, wiki help_url
  10. contribute to one of the curated Addon collections (preferably, the gramps-project/addons-source repo)
  11. request inclusion of the Addon in the Third-party_Addons list
  12. maintain the personal GitHub repository version for the next beta test cycle

Am I missing something?

Decided to make this an experiment in prompting Claude AI to adapt a SuperTool Script to a gramplet. (Uploaded to my GitHub collection.)

Note Styling Editor - help

An Experimental Gramps gramplet that shows the StyledText markup (bold, italic, font color, links, etc.) attached to a Note – or to the first Note attached to the active record in any other note-holding category – as a scrolling, checkable list, with buttons to strip selected markup or undo the last change.

This gramplet began as Kari Kujansuu’s SuperTool script note-markup.py, originally written to be run inside the SuperTool gramplet against one note at a time. Claude AI re-packaged that same logic into a standalone gramplet that reacts automatically to active item in the views. (With some missteps along the way. Claude did not recognize that because the script was manually triggered and Gramplets react dynamically, the INIT of the script did not translate directly.)
For Notes category views, it focuses on the directly selected Active Note. For the other categories focus is more indirect, it has to focus on the topmost Note that is secondary to the Active object.

Features

  • Lists every styling applied to the active note, one row per style, in the order it appears in the text – showing the style’s name, its value (e.g. a font color), and the bit of text it applies to.
  • Click a row – its checkbox or its text – to scroll the preview to that spot and briefly flash the affected text. This helps you focus on exactly what a style covers.
  • Click anywhere in the preview to select whichever row’s style is closest to that spot; the checklist and preview stay in sync in both directions.
  • Double-click in the preview to open the note in Gramps’ regular Note Editor, for changes beyond what this gramplet handles (new stylings, wording, spelling, etc.).
  • Clear Styling – check the rows you want stripped, then click to remove just that styling and save the change.
  • Undo – puts back the styling the note had when you first opened it here, in case you clear the wrong thing.
  • A read-only preview showing how the note actually renders, so you can see the effect of your changes.
  • A Help button, lower-left, that opens this help page (provided that the Markdown viewer addon is available, opens the Discourse thread if not.)

Heads up: this gramplet and the Note Editor each work from their own copy of the note while they’re open. If you open the Note Editor (by double-clicking the preview) and make changes there and in this gramplet before saving either one, whichever you save last will overwrite the other’s changes – there’s no merging between them. Finish and save one before editing in the other.

Where to find it in Gramps

You can add this gramplet to the sidebar or bottom bar of the Notes, Citations, People, Families, Events, Places, Sources, Repositories, and Media views – and dock, undock, or move it between them freely; it keeps following the view it was added to.

  • In the Notes view, it always shows whichever note is currently selected.
  • In any other view, since those records don’t have styling of their own, it shows the first note attached to whichever record is currently selected. If that record has no notes at all, it says so – e.g. “The F0004 Family has no Note to review.”

Requirements

  • Gramps 5.2 or newer.
  • Optional: the Markdown Dash addon, so the Help button can open this page in its own window instead of your browser.

Credits

  • Original concept and styling-editing logic: Kari Kujansuu, from the SuperTool script note-markup.py discussed at Styled Note Markup trimmer gramplet.
  • Gramplet adaptation and maintenance: Brian McCullough.
  • AI assistance: Claude (Anthropic) – see the developer notes below for the full disclosure.

License

GNU General Public License v2 or later, consistent with Gramps itself.


Developer notes

The rest of this page is for anyone maintaining or reviewing the addon’s code rather than using the gramplet – feel free to stop here.

Files in this addon

File Purpose
NoteStylingEditor.gpr.py Gramps addon registration. Also where the supported Gramps version range and the list of views it can be added to are set.
NoteStylingEditor.py The gramplet itself.
help_doc_button.py Shared Help-button widget (icon lookup, README-vs-browser routing); not specific to this addon.
test/note_styling_editor_test.py Dev-only unit tests for the pure tag-filtering logic (build_row_data, kept_tags_after_clear); no GTK/Gramps dependency, run with python3 -m unittest discover -p "*_test.py" from this folder.
README.md This file.

How it tracks the right record across views

Gramps tracks each view’s “active object” independently, so the gramplet works out once, when it’s created, which single view is actually hosting it – by reading that from the page it was added to – rather than checking every view at once. That stays correct even after it’s undocked into its own floating window: undocking only reparents the widget, it doesn’t change which page created it, so it keeps following the view it was originally added to no matter where the main window navigates afterward. See resolve_primary_navtype() in NoteStylingEditor.py for the implementation.

AI-generated-code disclosure

  • Tool, provider, version:
    • NoteStylingEditor.py, NoteStylingEditor.gpr.py, note_styling_editor_test.py, and this README: Claude (Anthropic), model “Claude Sonnet 5”, web chat (claude.ai). Generated 2026-09-18.
    • help_doc_button.py (companion module, reused as-is by this addon): Claude (Anthropic), model “Claude Sonnet 4.6”, web chat (claude.ai); see that module’s own HelpDocButton.md for its disclosure.
  • Prompts used (summarized across the conversation):
    Convert Kari Kujansuu’s SuperTool note-markup.py script into a Gramps Note/Citation gramplet with a scrolling checklist and Clear Markup/Undo buttons; add a Help button following the help_doc_button.py sample; a follow-up pass to make internal naming consistent throughout (dropping a redundant “Gramplet” suffix from file and class names to match the addon’s own title); write a README crediting the original script’s author and disclosing AI assistance; several rounds of bug fixes and features (a resizable divider, selectable/highlighted rows, a settings .ini file, working across every note-holding category, a friendly no-notes message); reorganize this README to be end-user-oriented with the technical/policy material moved to this section.
  • Constraint documents worked under:
    Gramps AGENTS.md and the “AI generated code” wiki section linked above. This addon’s Python files have been brought to full AGENTS.md style compliance (type hints, Sphinx docstrings, Black/Pylint, GPL license-header boilerplate, import-group headers) at the requester’s ask; re-run Black/Pylint/mypy after any further change before treating the .py files as commit-ready.
  • Provenance:
    NoteStylingEditor.py’s core logic (the tag-per-range checklist, and the Clear/Undo semantics of keeping unchecked tags or reverting to a snapshot) is adapted directly from Kari Kujansuu’s note-markup.py. Its Help button is reused from help_doc_button.py, which carries its own separate AI disclosure.
  • Verification:
    The pure, GTK-free logic (build_row_data, kept_tags_after_clear) has passing unittest coverage in test/note_styling_editor_test.py. The GTK/Gramps-specific parts of NoteStylingEditor.py (signal wiring, the view-detection in resolve_primary_navtype(), DbTxn commits, the highlight animation, etc.) have not been exercised against a real Gramps install – test in a live Gramps environment before relying on this addon.

If you want to read Claude’s comparison of the March 2025 imagined developmental workflow (of a ne developer converting a SuperTool script to a gramplet) to what was actually done with an AI assistant in September 2026: