Fast attachments with markdown

0

I have a document like this:

A lot of text. 
insert:good graph:x
More text. insert: :y

Even more text. 

insert:another figure:z

I want to change all insert:description:x to ![description][A_Standardized_filepath/x.pdf] because that command ![][] will attach a file into my markdown-document. Note that x is the variable I'm changing, and the description is unique for each variable. The file path, however, is always the same. (Note that y had no description, which I solved by adding a space.)

This would allow me to speed up the process of creating documents.


I'm on Windows 7; I prefer to use Notepad++ for writing.

user1603548

Posted 2014-11-09T10:29:00.030

Reputation: 484

Answers

2

I don't know notepad++, but if it has find and replace using regular expressions then you should be able to adapt this. In vim, I would use:

:%s/insert:\([^:]*\):\([^ :]*\)/![\1][A_Standardized_filepath\/\2.pdf]/g

The % means 'act on every line'; the s starts the substitute command (s/change this/to this/), and the g on the end means 'act on every match on a line' (as opposed to just the first match, which is vim's default behaviour).

The meat of it is in the first part. the \(\) indicate capture groups; since notepad++ is relatively new, I expect you won't need the backslashes there. Everything between the first set of \(\) is referred to as \1 on the right-hand side of the command (again, this may be different in notepad++: perl uses $1 instead, for example), everything between the second set of \(\) is referred to as \2 on the right-hand side, etc.

[^:] means 'any character except for :', while [^ :] means 'any character except for space or :'. This assumes that you'll never have spaces in the filename part of your construction.

If someone with knowledge of notepad++ comes along, they should feel free to cannibalise this regex into an answer.

evilsoup

Posted 2014-11-09T10:29:00.030

Reputation: 10 085