I have just performed changes in multiple markdown documents in Notepad . What I managed — what I have now — is the following format:
#### <u>Author name</u> writes in his 'Title of some Book/Essay/Article':
> First sentence with soft line breaks at the end.
Second sentence.
Third sentence.
Any number of sentences if there are any will follow — all need to be in quote blocks.
Some other text not belonging to above author comes after empty line (**no changes needed here**).
I would like all sentences with soft line breaks (= two spaces) at the end to be in quote blocks. Which means these lines should be prefixed with a >
and a whitespace character.
Desired result:
#### <u>Author name</u> writes in his 'Title of some Book/Essay/Article':
> First sentence with soft line breaks at the end.
> Second sentence.
> Third sentence.
> Any number of sentences if there are any will follow — all need to be in quote blocks.
Some other text not belonging to above author comes after empty line.
My method to match any number of sentences before the empty line is unsuccessful. Probably the whole approach is too static ("dumb") and a different approach is needed (with pipes or whatever).
So basically I would need to know how to iterate through items where the empty line breaks the pattern. Bear in mind, cases like this can appear multiple times within a given document so the four dashes will need to be used as anchors.
For whatever it's worth, I put up a Regex demo, if anyone cares to take a look (they will see it's unfinished and cannot work the way it is).
Any pointers are much appreciated.
CodePudding user response:
You can use
Find What: (?:\G(?!\A)|^\#{4}\s.*:\s*^>.*)\R\K.
Replace With: > $0
See the regex demo.
Details:
(?:\G(?!\A)|^\#{4}\s.*:\s*^>.*)
- end of the preceding match, or start of a line, four#
chars, a whitespace, zero or more chars other than line break chars as many as possible,:
, zero or more whitespaces, start of a line,>
char, and zero or more chars other than line break chars as many as possible\R
- a line break char sequence\K
- match reset operator that discards the text matched so far from the overall match memory buffer.
- a non-empty line