RTF to Markdown

Everything related to our flagship word processor.
Post Reply
tomoyuki-kosaka
Posts: 37
Joined: 2009-02-17 17:44:12

RTF to Markdown

Post by tomoyuki-kosaka » 2014-01-27 18:00:18

I'd like to convert RTF to Markdown format because when I write in NWP to move to blog converter (e.g., jekyll gem of Ruby).
Does someone know the most efficient way to do this?
Yes, I know the markdown not cover all of RTF functions.
I'm considering to make a macro for this purpose.

Kosaka

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

Re: RTF to Markdown

Post by phspaelti » 2014-01-27 20:58:19

Generally this is a macro that's fairly easy to write. Use the find window (with macroize) to create expressions like this:

Code: Select all

Find and Replace '.+', '<h1>\0</h1>', 'Eau'
Note that this is an attributed find, so you should apply the relevant style ("Heading 1" in this case) to the find expression.

Having said that, it can get a bit tricky depending on how complicated things get in your markup, and how 'good' of a result you want. Lou Lesko has written a pretty good basic macro for this purpose. You might be able to use that, at least as a starting point.
http://www.nisus.com/forum/viewtopic.ph ... 912#p24912
philip

tomoyuki-kosaka
Posts: 37
Joined: 2009-02-17 17:44:12

Re: RTF to Markdown

Post by tomoyuki-kosaka » 2014-01-28 15:56:24

Thanks Fillip.
I forgot to see the post about "Convert to HTML Macro for Writers".
I'll try to modify the script to adjust to Markdown format.

I have one more question.
I'm considering about converting table object in RTF to Markdown.
Other objects can be converted just "Find and Replace" as you mentioned.
But table needs some consideration.
Do you know the good example script for to use my purpose?

Kosaka

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

Re: RTF to Markdown

Post by phspaelti » 2014-01-28 17:29:55

Hi Kosaka,
yes, tables. This is where things get a bit trickier.
Here a basic macro that will turn tables into markup in a simple fashion.
Convert Tables to Markup.nwm
(17.29 KiB) Downloaded 163 times
Note: This macro does not seem to undo completely. Make sure to run this on a copy of your file.

Converting tables has some extra issues.
First: table headers
The macro above just converts all cells to <td>. Table headers could be handled either by using a style (e.g. "Table Header Cell") or simply by making the first row and column into header cells in all cases.

Second: in-cell formatting
Currently the macro just eliminates paragraphs in table cells using line breaks <br/>. But actually rtf would allow differently formatted paragraphs within a table. If that is desired, a more complex macro will be required. Similar issues come up for tabs within table cells, lists, etc. (Markup would even allow nested tables, but since (Nisus) rtf doesn't allow that, that is one problem less to worry about.)
Note that if you try the macro with formatting applied to different cells the formatting will be spread around, and partly lost. So one might need to first mark-up styles (or other info) in the table before using a macro like this. So for a more complete rtf-to-markup conversion macro I think I would get away from the simple Find/Replace approach and use a more structured approach using macro language object commands.
philip

tomoyuki-kosaka
Posts: 37
Joined: 2009-02-17 17:44:12

Re: RTF to Markdown

Post by tomoyuki-kosaka » 2014-02-07 17:05:29

Thank you Fillip.
I'm sorry for late my response.
I confirmed the macro can convert a table object to markup format.
I'll try to make markdown conversion macro based on these macros, if I can make a time.
Anyway, thanks again you always giving us the useful information about Nisus macro's.

Best,

Kosaka

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

Re: RTF to Markdown

Post by Emilio_Speciale » 2014-07-24 10:17:39

Any news on this macro? I am very interested!
Thanks

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

Re: RTF to Markdown

Post by davidrcalvert » 2014-07-25 15:38:57

Kosaka,

I would like to see if you came up with the RTF to MMD MACRO yet. It would be a great contribution.

tomoyuki-kosaka
Posts: 37
Joined: 2009-02-17 17:44:12

Re: RTF to Markdown

Post by tomoyuki-kosaka » 2014-07-25 22:36:40

Sorry. It's still a plan.
I'd like to do, but have not done yet.

Post Reply