How to select paragraphs after other paragraphs with particular styles?

Everything related to our flagship word processor.
Post Reply
User avatar
xiamenese
Posts: 543
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

How to select paragraphs after other paragraphs with particular styles?

Post by xiamenese »

Hi all,

This new macro — which Martin modified to help me … thank you Martin … following my posting in https://nisus.com/forum/viewtopic.php?f=17&t=11975 — works really well.

I do however need to know one more thing: how do I create a search for all paragraphs following a heading of any level, blockquote, etc. — i.e. following anything other than a paragraph in "Normal" style — so that I can re-style them with no first line indent?

:)

Mark
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Support for Markdown

Post by adryan »

G'day, Mark et al

I'm not sure whether this is too simplistic a solution here, but remember that, if you have an easy way to find something (eg, "Normal" paragraphs), an easy way to find everything else is to use Invert Selection (in the Edit menu).

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: How to select paragraphs after other paragraphs with particular styles?

Post by martin »

I split this question into its own topic since the answer may be involved.

Selecting all paragraphs in a particular style is very easy, e.g. use the menu Format > Paragraph Style > Select All in Style, but you have a much trickier request. You want to find all paragraphs using a mix of multiple styles. That might be relatively straightforward with a formatting-sensitive find expression. But you don't actually want to select those paragraphs, you want to select the paragraphs that appear afterwards. That's going to involve some custom macro code.

I'm attaching a zip file with three macros:

1. The first macro "Paragraph Styles, Select Multiple" makes it easy to select all paragraphs using a mix of multiple paragraph styles. The macro will ask you to checkmark all the styles you want to select.

2. The macro "Paragraphs, Select Following" simply looks at the current selections and adjusts them, so all the following paragraphs are selected instead.

I think those macros might be useful on their own. If you put them together you get:

3. The final macro "Paragraphs, Select Following After Styles" asks you to choose styles and then selects all paragraphs that come after any paragraphs using those styles. You can then alter the formatting of those paragraphs as desired.

I hope that helps!
Attachments
Paragraph-Selection-Macros.zip
(7.42 KiB) Downloaded 168 times
User avatar
xiamenese
Posts: 543
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

Re: How to select paragraphs after other paragraphs with particular styles?

Post by xiamenese »

Thank you very much Martin. I'll give them a try and let you know how I get on.

:)

Mark
User avatar
xiamenese
Posts: 543
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

Re: How to select paragraphs after other paragraphs with particular styles?

Post by xiamenese »

Hello, Martin, Adrian, et .al.

I've been trying out Martin's Macro and it works beautifully. so the workflow is currently:
  • Export text to .MD from Scrivener;
  • Open .MD file in NWP;
  • Run the "MarkDown Preview" macro;
  • Run my "Set Styles" macro to import and apply my standard styles;
  • Run a simple macro to remove empty lines;
  • Run the "Paragraphs, Select Following after Styles" macro and apply my non-indented paragraph style from the palette;
  • Run the "Remove Unused Styles" macro;
At some point, I'll explore concatenating all, or most of that, into a single macro. There are only a couple of issues remaining for me to be able to use, with no fussing, a Scrivener --> MD --> NWP workflow:

The first is more important and concerns footnotes/endnotes. Scrivener has "Inspector footnotes" and "Inline Footnotes" resulting in two note-streams in the MD. These are marked [^fn1]: etc. for Inspector Footnotes, and [^cf1]: etc. for Inline Footnotes; both streams are treated as Endnotes by MD. For my usage the Inline footnote should be Endnotes in NWP and the Inspector Footnotes should remain as footnotes. That said, for most of my usage I don't have that many, the most important ones being bibliography references, which would be endnotes. I can sort this out manually without too much trouble, but if anyone would like to automate converting the .MD syntax to Nisus' RTF syntax, other people might find that useful.

The second item, and this is more for info, concerns working with Bookends. Markdown escapes literal { } and # — and maybe @ though I haven't checked — with a backslash. Those characters are used in the Bookends temporary citations so I presume that Bookends would not recognise them with the \s in place, but I'll check. If the escaping is a problem, it is easy enough to remove all \s by find and replace, but I might ask on the Bookends forum.

All that said, if any of you are interested in writing a macro to convert the .MD footnote/endnote syntax into Nisus' RTF syntax, I attach a short "mmd-trial.md" document exported from Scrivener that you can use for testing.

:)

Mark
User avatar
xiamenese
Posts: 543
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

Re: How to select paragraphs after other paragraphs with particular styles?

Post by xiamenese »

Oops! I forgot to attach the file! :roll:

Here it is (zipped 'cos the forum software doesn't like .md files :) ).

Mark
mmd-trial.md.zip
(3.38 KiB) Downloaded 183 times
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: How to select paragraphs after other paragraphs with particular styles?

Post by martin »

xiamenese wrote: 2022-01-31 06:38:56 Oops! I forgot to attach the file! :roll:

Here it is (zipped 'cos the forum software doesn't like .md files :) ).
Thanks for the file Mark! Please try this macro. It should detect the Markdown notes you described and convert them to proper footnotes and endnotes.
Attachments
Notes, Convert Markdown to Proper Notes.nwm.zip
(3.9 KiB) Downloaded 155 times
User avatar
xiamenese
Posts: 543
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

Re: How to select paragraphs after other paragraphs with particular styles?

Post by xiamenese »

Thanks Martin. It works brilliantly. With just a few small things that I might occasionally need to sort on the fly, I have a pretty much automated workflow Scrivener --> MD --> NWP, which means I no longer have to worry about styles and other layout matters.

I'll have a go at concatenating it all into a single macro, and if I succeed, I'll try to get other Scrivener and NWP users — I know there are some — interested.

Many thanks indeed.

:)

Mark
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: How to select paragraphs after other paragraphs with particular styles?

Post by martin »

xiamenese wrote: 2022-02-01 09:56:08 Thanks Martin. It works brilliantly.
Awesome, glad to hear it!
I'll have a go at concatenating it all into a single macro, and if I succeed, I'll try to get other Scrivener and NWP users — I know there are some — interested.
Thanks Mark :) please do share your results, or let us know if you need any help forming the concatenated macro
User avatar
xiamenese
Posts: 543
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

Re: How to select paragraphs after other paragraphs with particular styles?

Post by xiamenese »

Martin, here is my concatenated Scrivener --> MD --> NWP macro. It:
  • Uses the "MarkDown Preview" macro code to open an RTF copy of the file;
  • Uses the "Import Styles" macro code you created years ago to import a style collection and apply those styles;
  • A simple code removes blank lines;
  • Uses the code from your "Paragraph, Select Following After Styles" macro;
  • Applies a "No Indent" paragraph style to the selection — basically "Normal" with the first line indent removed;
  • Uses the code from your "Notes, Convert Markdown to Proper Notes";
  • Uses the code from the "Removes Unused Styles" macro.
It works well for all basic text including headings and block quotes. and for Level 1 lists. If the source has list entries above level one, they are merely returned as "Normal" and indented, but with no list style implemented. For me, personally, lists are not a major issue; I would deal with them individually by making them all Level 1 and then adjusting the levels in NWP.

Another problem is that though footnotes and Endnotes are duly converted, they don't conform to the Footnote and Endnote settings in the style sheet, and the Note References are simply a number or whatever included in the text with the style of that paragraph. They can be sorted out by selecting all the footnotes, removing the "Normal" style applied and adjusting the ruler; then doing the same for endnotes. Then, by right-clicking on a note, choosing "Go to Note Reference" and adjusting it either to superscript — or in my case 2 points smaller, baseline raised 2 points — the result is applied to all Note References.

That said, although this is working fine for me, other users might find the list and footnote/endnote issues more annoying. However, I'll post it on the Scrivener forum with a readme outlining these matters, but, I'll leave it up to you or any of the other macro gurus to automate them more, if any of you you think it worthwhile.

I attach a zipped folder with the MD-RTF.nwm macro and a modified sample text with list items included for people to play around with. NB The style collection chosen needs to include a "Block Quote" style and a "No Indent" style.

Of course it can be applied to a .MD file from whatever source; I just happen to be a Scrivener user.

Mark
MD-RTF.zip
(9.51 KiB) Downloaded 150 times
Post Reply