Jump to content
vitor

MarkdownTransform — Convert Markdown to other formats

Recommended Posts

Each Hotkey Trigger in the workflow corresponds to a different type of Markdown conversion:

  • Markdown → BBCode
  • Markdown → HTML
  • Markdown → RTF


Supported in conversion to RTF:

  • Italic
  • Bold
  • Italic and Bold
  • Strikethrough
  • Links
  • Unordered lists
  • Ordered lists
  • Superscript


Supported in conversion to BBCode:

  • Italic
  • Bold
  • Italic and Bold
  • Horizontal rule
  • Strikethrough
  • Images
  • Links
  • Quotes
  • Inline code
  • Code blocks
  • Headers
  • Unordered lists
  • Ordered lists
  • Footnotes
  • Superscript


Supported in conversion to HTML:

  • Italic
  • Bold
  • Italic and Bold
  • Horizontal rule
  • Strikethrough
  • Images
  • Links
  • Quotes
  • Inline code
  • Code blocks
  • Headers
  • Unordered lists
  • Ordered lists
  • Footnotes
  • Superscript
  • Tables
  • Highlights

 

Download | Source

Edited by vitor

Share this post


Link to post

Update.
 
It now has files for updating (if you use Alleyoop, or something similar), made a correction to the img substitution, and added an option for images that send to a url.

Share this post


Link to post

Hi Vitor,
 
When I use your workflow with my markdown file https://raw.github.com/vdesabou/alfred-spotify-mini-player/master/README.md, I get strange results.

 

For example with:

## Settings

* Configurable Search Scope: Only Starred playlist (by default) or All your playlists
* Set max number of results. 50 by default
* enable/disable Spotifious or Alfred Playlist
* enable/disable ***Lookup this artist online***
* Install/Update of the library (see next section for explanations)

## First time use

I get:

 

## Settings

  • Configurable Search Scope: Only Starred playlist (by default) or All your playlists
  • Set max number of results. 50 by default
  • enable/disable Spotifious or Alfred Playlist
  • enable/disable Lookup this artist online

*

  • Install/Update of the library (see next section for explanations)
  • ## First time use

 

Maybe I have something wrong in my md file, but the same file gives correct results with the workflow from Carlos-Sz (http://www.alfredforum.com/topic/1333-markdown-to-bbcode-17).

 

Any idea?

Thanks!!

Share this post


Link to post

Good catch, thank you. I’ve also fixed some other issues in the process.

This updates has fixes for bold together with italic, lists with bold and italic in them (your issue), and lists and code blocks that start at the beginning of the text.

Share this post


Link to post

Good catch, thank you. I’ve also fixed some other issues in the process.

This updates has fixes for bold together with italic, lists with bold and italic in them (your issue), and lists and code blocks that start at the beginning of the text.

 

Great!

But I think you forgot to check in the .alfredworkflow file, there is 404 error

Share this post


Link to post

But I think you forgot to check in the .alfredworkflow file, there is 404 error

It was on the wrong directory. Should be working now.

Share this post


Link to post

It was on the wrong directory. Should be working now.

 

Thanks!

 

I have two other suggestions:

 

- Handle # and ## titles

- When I select my markdown text in my text editor and activate your workflow, it transforms the original file, so I have to cancel modification. Wouldn't it be possible to just have the BB code in the clipboard only? Or if not possible to open a new text file with the results, instead of modifying original?

 

 

These are just ideas of improvement, your workflow is already very good :)

 

Cheers

Share this post


Link to post

These are just ideas of improvement, your workflow is already very good :)

 

Thank you.

 

- Handle # and ## titles

I’ve added three levels of headers, #, ##, and ###.

 

- When I select my markdown text in my text editor and activate your workflow, it transforms the original file, so I have to cancel modification. Wouldn't it be possible to just have the BB code in the clipboard only? Or if not possible to open a new text file with the results, instead of modifying original?

That’s easy to do, just dive into the workflow, double-click the Copy to Clipboard node, and deselect the Automatically paste to front most app option. I’m guessing most people only use it one way or another, for most of the time, although adding both options wouldn’t be that much trouble, if there’s demand for it.

Share this post


Link to post

 

That’s easy to do, just dive into the workflow, double-click the Copy to Clipboard node, and deselect the Automatically paste to front most app option. I’m guessing most people only use it one way or another, for most of the time, although adding both options wouldn’t be that much trouble, if there’s demand for it.

 

Of course, I should have thought about that!

Thanks for the headers, it is working perfectly for my use case now!

Share this post


Link to post

Brilliant idea this.

 

Unfortunately, this workflow doesn't work for me as I use Sublime Text and the Use OSX Selection feature only works with Cocoa apps.

 

For anyone else with the same issue, I've created a modified version of the workflow that takes its input from the clipboard. Get it here.

 

I've made a few other changes:

  • The output is copied to the clipboard only and not pasted into the active app.
  • A notification is shown to let you know the workflow has finished (seeing as it no longer pastes its results).
  • I changed the behaviour of inline code (backticks) to add tags instead of bold and underline. This makes much more sense for me, as I use backticks for code.
  • Trailing #'s are deleted from headers, so if, like me, you write # Heading # instead of just # Heading, the output will still be correct.
  • I changed the bundle ID and removed the JSON files for updating, so my alternate version won't overwrite the original and vice versa.
Edited by deanishe

Share this post


Link to post

I like some of your changes, so I’ve incorporated them in the original. I’ve also made some bug fixes that you might want to incorporate back to your version.

  • Inline code is now set to a monospaced font. I was never truly happy with the bold and underlined solution, so thank you, I agree it makes much more sense like that.
  • I’ve also adopted your change to headers, although in a slightly different way (I’ve changed the original lines to take into account those cases, instead of adding the new one).
  • There are two bug fixes related to the horizontal rule. It’s no longer confused with italics, and an empty line with three spaces will no longer convert to an horizontal rule (this one was very specific, but it could still lead to undesired results).
Edited by Vítor

Share this post


Link to post

I've noticed a problem with this workflow when I'm trying to convert text containing non-ASCII characters. It works perfectly on the command line, but Alfred's Copy To Clipboard action does nothing.

 

I'm afraid I don't know enough about text encoding in Ruby to be able to tell if there's a problem with the output (UTF-8, I'm assuming) or a bug in Alfred (I discovered the problem making a post about an Alfred text encoding bug).

 

Any thoughts?

Share this post


Link to post

Welp, I've had a prod at the Copy to Clipboard action with Python, and it works just fine with UTF-8 text, so I figure the problem lies with the output of the Ruby script.

Share this post


Link to post

Strange, since I’m actually taking that into account. I’ve encountered that encoding problem when building this workflow, and the first line of the ruby script is actually pointing that out and has a link to reference the used fix.

It works without a problem, with me (I’m portuguese, so I use non-ASCII characters in regular typing as well, making that also a concern for me). Which characters are you having trouble with? And does it happen in both our versions?

Share this post


Link to post

Yeah, I tested both versions. I figured you'd have tested it with non-ASCII as well.

The character in question was ö. As I said, the script worked perfectly in Terminal.

Weird.

Share this post


Link to post

Are you trying it in Sublime Text? What if you try it another editor? Doing it in this forum’s reply box works as it should; however, in Sublime it’s breaking `ö` into `o¨`.

Share this post


Link to post

From my tests it seems Alfred (OSX selection and copy to the clipboard) is kind of breaking ö.

 

Can you try to use a procedure to copy the result to the clipboard by yourself instead of letting Alfred doing that?

Edited by Carlos-Sz

Share this post


Link to post

I've tried it both ways (my modified Workflow grabs the clipboard contents with pbpaste because I use a keyword, not a hotkey).

I just tried it in TextEdit (both ways) with the same result: Alfred doesn't place the results on the clipboard.

For my part, I can't seem to get it to work with any non-ASCII characters. So far I've tried ü, ö, ñ and (em-dash).

By way of comparison, I used a Python script to print UTF-8 text to the Copy to Clipboard action and a bash script containing pbpaste -Prefer txt. Both worked perfectly.

So I suspect it's a Ruby-Alfred misunderstanding.

Edited by deanishe

Share this post


Link to post

I’ll look a bit more into it, but it seems like pbpaste is part of the problem, as it seems to be having some issues with it. For me it works well with the original version, but yours also fails. Odd issue.

Share this post


Link to post

I’ll look a bit more into it, but it seems like pbpaste is part of the problem, as it seems to be having some issues with it. For me it works well with the original version, but yours also fails. Odd issue.

Confirmed. The problem was that I have the LANG variable set in Terminal, which was causing pbpaste to use UTF-8, but it isn't set when Alfred runs a script, so pbpaste was using C encoding.

I changed pbpaste to LANG=en_GB.UTF-8 pbpaste and now it works.

I have no idea why your version wasn't working for me yesterday, but it's working just dandy today. More than likely, I'd messed up the code, which was fixed by the update.

Sorry for the erroneous bug report.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...