Reply to topic  [ 1 post ] 
A macro to preserve styles between Scrivener and Nisus 
Author Message

Joined: 2015-01-18 10:38:33
Posts: 5
Hello friends,

My workflow is writing in Scrivener, then compiling to RTF and transferring to Nisus. I am new to Nisus, but I notice from a scan of the forums that a number of you do the same.

My technical needs are not great; I only needed a quick way to automate the process of tagging paragraphs as ‘Title’, ‘Header 1’, ‘Header 2’ and all others ‘Normal’, and converting bold and italic attributes to ‘Strong’ and ‘Emphatic’ styles.
I want the result to be an entirely styled document, to which I can apply the style sheets of my choice in Nisus.

Disclaimer: I am new to Nisus and this is my first macro, a segment of which I got to work with phspaelti’s help. I searched the forum for a macro which would do this and didn’t find one, so I wrote this one. It works for me, and I’m sharing it in case it may be helpful, but I’d welcome feedback on how I might have done this more elegantly.

Code:
# This macro massages a standard Scrivener-compiled RTF file. It assigns any text with the bold attribute the style “Strong”, anything italic gets assigned the style “Emphatic” and any text tagged <tit>|</tit>, <h1>|</h1> and <h2>|</h2> is assigned the styles “Title”, “Heading 1” and “Heading 2” respectively. All other paragraphs are assigned the style “Normal”.

# This macro works best if a Scrivener compile preset is created in which, in the formatting panel, the title and heading coding noted above is inserted in the prefix and suffix fields (under “Section Layout…”). I set mine so that folder names are styled ‘Title’, document names with sub-documents become ‘Heading 1’, and simple document names become ‘Heading 2’. Adjust to taste. Of course you may elect not to use Documents names in your compile settings and hand code in the main body text if you wish.

# Note that any bold or italic formatting within Titles and Headings is stripped. That is my preference, but it may not be yours.

# This block prepares the file’s style sheet by first deleting any unused pre-existing styles (typically ‘Header’ and ‘Normal’ in Scrivener compiled RTF) to avoid name conflict when they are subsequently recreated

$doc = Document.active

foreach $style in $doc.allStyles
   $found = Find $style
   if ! $found
      $doc.removeStyle $style
   end
end

# This block creates the necessary styles

$doc.addNewStyle ‘Paragraph’, ‘Title’
$doc.addNewStyle ‘Paragraph’, ‘Heading 1’
$doc.addNewStyle ‘Paragraph’, ‘Heading 2’
$doc.addNewStyle ‘Paragraph’, ‘Normal’
$doc.addNewStyle ‘Character’, ‘Strong’
$doc.addNewStyle ‘Character’, ‘Emphatic’

# This block applies the character style “Strong” to bold text (code within first set of single quotes must be styled bold)

Find All '[^\\n\\f]+', 'Eau'
$myPath = ":Format:Character Style:Strong"
Menu $myPath

# This block applies the character style “Emphatic” to italic text (code within first set of single quotes must be styled italic)

Find All '[^\\n\\f]+', 'Eau'
$myPath = ":Format:Character Style:Emphatic"
Menu $myPath

# This block applies the paragraph style “Normal” to the entire document

$myPath = "Select All"
Menu $myPath
$myPath = ":Format:Paragraph Style:Normal"
Menu $myPath

# This block strips of h1, h2 and Tit tagged headings of bold formatting that is the default for many Scrivener compile presets

Find All '<tit>[^\\n\\f]+</tit>', 'Ea'
$myPath = ":Format:Remove Attributes and Styles"
Menu $myPath

Find All '<h1>[^\\n\\f]+</h1>', 'Ea'
$myPath = ":Format:Remove Attributes and Styles"
Menu $myPath

Find All '<h2>[^\\n\\f]+</h2>', 'Ea'
$myPath = ":Format:Remove Attributes and Styles"
Menu $myPath

# This block applies paragraphs styles Title, Heading 1 and Heading 2 to tagged text

Find All '<tit>[^\\n\\f]+</tit>', 'Ea'
$myPath = ":Format:Paragraph Style:Title"
Menu $myPath

Find All '<h1>[^\\n\\f]+</h1>', 'Ea'
$myPath = ":Format:Paragraph Style:Heading 1"
Menu $myPath

Find All '<h2>[^\\n\\f]+</h2>', 'Ea'
$myPath = ":Format:Paragraph Style:Heading 2"
Menu $myPath

# This block strips the remaining heading codes

Find and Replace '<tit>|</tit>|<h1>|</h1>|<h2>|</h2>', '', 'Ea'


2015-01-24 04:51:04
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software