Macro for RTF to Markfown

Get help using and writing Nisus Writer Pro macros.
Post Reply
davidrcalvert
Posts: 28
Joined: 2014-07-18 18:32:13

Macro for RTF to Markfown

Post by davidrcalvert » 2014-07-18 18:44:39

Hi,

I wonder if it I'd possible to create a Macro to convert Nisus RTF to Markdown.
Or do you know of a workflow besides just writing in. Nisus in plaintext using Markdown syntax .
Any thoughts would be appreciated.

User avatar
phspaelti
Posts: 912
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Macro for RTF to Markfown

Post by phspaelti » 2014-07-18 21:28:13

It certainly would be possible to write such a macro (and of course you can write in plaintext and insert markdown by hand, or macro, or glossary, etc.). It's mainly a question of setting things up. How detailed a markup are you looking for. One place to start would be this thread http://www.nisus.com/forum/viewtopic.php?f=17&t=5494.
philip

davidrcalvert
Posts: 28
Joined: 2014-07-18 18:32:13

Re: Macro for RTF to Markfown

Post by davidrcalvert » 2014-07-25 15:30:32

What I would like to do is strip out all the extra stuff I guess it is meta data of an rtf file created in Nisus and convert it it to a a markdown/multi markdown
file with MMD syntax.

Does that make sense or is there another strategy that can be taken?

User avatar
phspaelti
Posts: 912
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Macro for RTF to Markfown

Post by phspaelti » 2014-07-25 16:39:53

By MMD you have something specific in mind. (I wasn't aware of this format.)
davidrcalvert wrote:What I would like to do is strip out all the extra stuff I guess it is meta data of an rtf file created in Nisus …
The "stripping out" simply amounts to saving as plain text, but of course after you convert the information you want to keep from WYSIWYG styles/attributes to markdown code.
…and convert it it to a a markdown/multi markdown
file with MMD syntax.

Does that make sense or is there another strategy that can be taken?
So you want to write the document in Nisus with styles, but then convert it to MMD, perhaps to transfer to another device?

MMD seems to be intended for humans, rather than computers. As long as the specification is clear and un-ambiguous this should be possible. For example you can use a find/replace to insert the correct number of "#" for each level of heading, and wrap bold and italic bits in "*". Lists, too, should be simple enough, although multi-level lists, and non-contiguous lists could be troublesome.
Tables would be a big hassle. It would probably be easiest to just convert them to HTML tables (again see that other thread), since MMD presumably can incorporate bits with HTML markup (as opposed to allowing text with the HTML markup displayed. Still a bit hazy on how these two cases are distinguished.)

If these are all the bits that are needed, it shouldn't be too difficult, to write a macro to do that (except for the tables).
philip

davidrcalvert
Posts: 28
Joined: 2014-07-18 18:32:13

Re: Macro for RTF to Markfown

Post by davidrcalvert » 2014-07-25 22:41:25

Would you use a Find and Replace to change all the BOLD words to
**BOLD** for example and what would that look like .
Thanks.

User avatar
phspaelti
Posts: 912
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Macro for RTF to Markfown

Post by phspaelti » 2014-07-25 22:47:44

davidrcalvert wrote:Would you use a Find and Replace to change all the BOLD words to
**BOLD** for example and what would that look like .
Thanks.

Code: Select all

Find and Replace '.+', '**\0**', 'Eau-i'
Note: for this to work you need to have bold style applied to the '.+'

This is just the simplest way to do things. Expressions like this one can be constructed in the Find/Replace window and then "Macroized".
Last edited by phspaelti on 2014-07-26 06:23:54, edited 1 time in total.
philip

Emilio_Speciale
Posts: 27
Joined: 2013-11-04 06:16:07

Re: Macro for RTF to Markfown

Post by Emilio_Speciale » 2014-07-25 22:52:06

There is already a macro for converting table to markdown. Please do a search on this forum. It would be easy to do a conversion from rtf to a markdown text. I think that there are only five "styles" to convert:
1. headings
2. Paragraphs (from a single paragraph to two paragraphs)
3. italics
4. bold
5. lists

For tables see the forum.
Thanks

User avatar
phspaelti
Posts: 912
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Macro for RTF to Markfown

Post by phspaelti » 2014-07-25 23:11:45

Emilio_Speciale wrote:For tables see the forum.
Do you mean this one: http://www.nisus.com/forum/viewtopic.ph ... 619#p25587

Anyhow for headings and italic/bold here is a simple macro:
Styles_to_Markdown_1.nwm
(18.73 KiB) Downloaded 166 times
But even at this simple stage I foresee problems. If you have text with italic and bold, this macro will give you ***text***, which probably is no good. (I'm hazy on how markdown really works).

As for the returns on paragraphs as Emilio points out they all have to be doubled. Except only the ones on the text paragraphs have to be doubled. The ones on the headings presumably don't (in fact shouldn't, I think). Also if you are combining this with tables and lists you need to make sure to do things in the right order. Or really it would be better to adopt a different approach (single pass, rather than multiple Find/Replace statements). I don't really have the time in the near future to work on this.
philip

davidrcalvert
Posts: 28
Joined: 2014-07-18 18:32:13

Re: Macro for RTF to Markfown

Post by davidrcalvert » 2014-07-26 06:07:08

Phillip,
Thank You, This is good information . I am new to using Macros with Nisus and was using MMD in other apps and needed help with getting over a sticking point.
I now have something that I can experiment with.
Thanks again.

Post Reply