Zettelkasten Forum


An easy to use Markdown bulk editing tool

2»

Comments

  • I did try one of my earlier experiments (written by Copilot AI)
    search:
    (## Note sequences\s\n\s\n)(\d+(?:, \d+)*)
    replace:
    $1[[$2]]

    This will find single instances of Cross references or Note sequences with no following comma but it will not change the numbers at the end of a line of numbers
    so:
    251 yes it changes
    but
    [[123]] [[2345]] [[120]] 251 no it will not change.

  • In principle, the patterns I gave you will do the job, they work. However, different tools support different regex syntax, and different tools use different regex default settings. This is the issue here. You have to find a pattern that works for the tools you’re using.

    Sublime Text should support the PCRE engine which itself supports regex modifiers like (?m). But this Regex cheat sheet for Sublime text also doesn’t list the modifiers. So maybe they are simply not supported by Sublime Text? OTOH, Sublime Text is said to use the Boost library for its Regex searches and this does seem to support the regex modifiers.

    It sounds dumb but it may be easiest to try yet another tool.

    The Copilot patterns are definitely wrong and I think they confuse things more than they are helpful.

  • edited September 22

    If we don't manage to find a single pattern that also works for you in all cases, you could always convert just the last numbers by running a separate search & replace action with a pattern like this:

    Find: (## (?:Cross references|Note sequences)\s\n\s\n.*? )(\d+)(?=\s\n)
    Replace: $1[[$2]]

    This is under the assumption that Sublime Text supports positive lookaheads ((?=...)) as indicated by the above mentioned cheat sheet.

  • edited September 22

    Notepad++ seems to support regex modifiers and have ^ and $ match embedded newlines by default. So these search & replace patterns may work out of the box with Notepad++:

    Find: (## (?:Cross references|Note sequences)\s\n\s\n.*?)( )?(\d+)(?:,|$)
    Replace: \1\2[[\3]]

  • edited September 23

    @msteffens said:

    It sounds dumb but it may be easiest to try yet another tool.

    The Copilot patterns are definitely wrong and I think they confuse things more than they are helpful.

    Agreed about a new tool. One of my objectives in this exercise is to make the process of converting Zkn3 Markdown exports into 'proper working' Markdown is to make it as simple as possible for the non technically minded (like myself!) Visual Studio is pretty daunting and I have spend hours on getting to know it and to get it to work, so it does not meet the criteria of being 'easy to use of out of the box'. Sublime Text is powerful but again difficult to use for the non-regex user. Am investigating Notepad++ as an alternative and it looks hopeful so far.....

    I tried Copilot as an experiment following the press reports about AI being used to write code. Simple answer, it can't.
    I also asked it to write a history paper on the Holocaust. Looked good but to a historian on the subject, complete garbage.

  • @msteffens said:
    Notepad++ seems to support regex modifiers and have ^ and $ match embedded newlines by default. So these search & replace patterns may work out of the box with Notepad++:

    Find: (## (?:Cross references|Note sequences)\s\n\s\n.*?)( )?(\d+)(?:,|$)
    Replace: \1\2[[\3]]

    I ran a whole sequence of four steps with Visual Studio and still ended up with unchanged links.

    So as suggested I am trying Notepad++ which seems pretty easy to use with Ctrl+H giving access to an easy Replace screen. On running the first two sequences, it appears to have changed all the links including the stubborn 'single links with no comma' and the 'end of line with no comma links'.

    So the complete sequence for migration is:

    Zkn3 migration to Markdown

    1. Amend Keywords to Tags  
        a. From  Apples Pears  to  #Apples-Pears
    
    2. Migrate Notes as individual Markdown files
    
    3. Bulk rename files to remove Note titles and leave just Note number
        a. From 123-apples-and-pears.md    to 123.md 
    
    4. Convert Zkn3 text links to Markdown Wiki Links  so    [z 123]text[\z]    to ## 123 using Find/Replace
        a. Find \[z ([0-9]+)\](.*?)\[/z\]
        b. Replace  [[${1}]]${2}
    
    5. Convert Note Sequences and Cross Reference Headings 
        a. From 
        ##Note Sequences  line 
        (blank line)
        123, 345, 789
        b. To
        ##Note Sequences
        (blank line)
        [[123]] [[345]] [[789]]
    
    6. Step 1  change the numbers separated by commas and a space
        a. Find (## Cross references\s\n\s\n.*?)( )?(\d+)(?:,|$)
        b. Replace  $1$2[[$3]]
        c. Click Find 
        d. When you are happy with the results Click Replace all
        e. Repeat until replace sequence reports zero in bottom left hand corner of Find/Replace box
        f. Repeat sequence replacing ## Cross references with ##  Note sequences in Find term
    

    Repeat until replace sequence reports zero as before

  • @Der_Alte_Fritz said:
    On the plus side, I imported the 2,500 markdown zettels into Obsidian as a test and the links are all there and working well.

    Plugins like these can show names instead of IDs on graph and search
    https://github.com/snezhig/obsidian-front-matter-title
    https://github.com/muhammadspace/obsidian-frontmatter-alias-display

  • @msteffens said:
    Notepad++ seems to support regex modifiers and have ^ and $ match embedded newlines by default. So these search & replace patterns may work out of the box with Notepad++:

    Find: (## (?:Cross references|Note sequences)\s\n\s\n.*?)( )?(\d+)(?:,|$)
    Replace: \1\2[[\3]]

    Success! Well done msteffens, the code works in Notepad++ and replaces both terms at the same time for all instances including our tricky end note variants.

    Thank you very much for all your help and perservence in overcoming this problem, it really has been a life saver for me to find an easy to use programme and the code to go with it. Thanks again.

    I shall write this up in part 4 of my Zkn3 manual
    https://www.hgwdavie.com/blog/2024/9/16/zettelkasten-zkn3-english-language-manual-part-3-doomsday-planning

  • @Der_Alte_Fritz said:
    Success! Well done msteffens, the code works in Notepad++ and replaces both terms at the same time for all instances including our tricky end note variants.

    That's great to hear! You're very welcome!

Sign In or Register to comment.