Regex to update markdown headers.
I am a novice both with regex and editorial.
I am trying to use regex to shift markdown headers on level down. I have tried find (#+) replace #\1 but this doesn't seem to work with the included find and replace popover workflow. Can anyone suggest how else I can accomplish this?
Rob last edited by
Not sure of the context, and this workflow is probably overkill, but it throws up a menu allowing you to adjust the number of levels in an outline which have hash headers.
Thanks Rob. That is very interesting, especially as I have never tried to use JSON but is more complex than I hoped for! The task seems as if it should be accomplished using the standard macro building blocks but none of the approaches I have tried have been successful!
I have confirmed that the regex does what I want in notepad++. I created a 1 action workflow using the find an replace action with the same regex but it seems to cause editorial to crash! Are the regex used in editorial different to those in notepad++? Is there some aspect of the find and replace action I have missed? I am frustrated to be stumped by something that seems so simple!
@Chrishphoto I have no idea what flavor of regular expressions notepad++ uses, they tend to differ a little bit with different languages/libraries.
Could you share the workflow that caused the crash? I'd be interested in reproducing the crash, so that I can hopefully fix it. Thanks!
I realised that the workflow can't actually do anything as I had not set the input and output. Having said that, it does always cause a crash for me and must represent some error!
An updated workflow does the find and replace but doesn't include the found token where I have used \1. How should I include the token in the replace for editorial?
The crash is probably due to a bug in the current version with find-replace actions that don't have an input (will be fixed in the update I'm working on).
I'd recommend adding a "Document Text" action before the find/replace, then an "Extend Selection" (both directions, start/end of document), and finally a "Replace selected text".
Editorial uses dollar symbols for match groups, so if you replace
$1it should work.
Here's how it should look:
Thanks. That's the ticket. I implemented for a selection rather than the whole document as this suits my use case better. http://editorial-app.appspot.com/workflow/5029996724748288/03zOfG0O2RI
Is there documentation for the variant of regex used by editorial?
Thanks. I now have a pair of macros to promote and demote headers.