Jump to content
vitor

MarkdownTransform — Convert Markdown to other formats

Recommended Posts

Headers were removing the line below, which in turn was messing up lists, which was causing your problem.

 

The new version fixes this, it should now work correctly for your case. I’ve also removed alleyoop support.

Share this post


Link to post

This workflow is fantastic! Thank you so much for putting it together.

 

There's one feature of Markdown (at least as it's implemented in FoldingText) for putting Comments inside {>> <<}. Usually, when Exporting, these comments are omitted. I really like leaving lots of notes for myself inside Comments while typing, but would like to be able to use this Workflow to copy the text without the Comments.

 

I'm not very well-informed about regexp. I thought maybe I could just replace any instance of {>> ... <<} with an empty ''. But I don't really know how to even do this. This was my attempted modification, which obviously doesn't work:

s = s.gsub /\{\<\<(\S.*?)\>\>\}/, ' '

Hopefully that shows what I'm aiming for? What did I get wrong here?

 

Thanks again!

Edited by Simolinic

Share this post


Link to post

Thank you for the kind words.

On to your problem. You’re escaping too much: you don’t actually need to escape any of the characters, as they’re not special (the ones that are need to be there unescaped, anyway). You’re also trying to substitute for a space (' '), when you should be substituting by nothing (''). When you say (\S.*?), what you’re saying is “capture one non-whitespace character, followed by any character zero or more times, until it finds your closing condition”. You don’t need capturing, or the non-whitespace definition. You were on the right track, just needed to remove the extra stuff.

You said it should take into account text between {>> and <<}, but your example is showing something different (between {<< and >>}. I’ll take your first reference as guide. The line should read

s = s.gsub /{>>.*?<<}/m, ''
The m means you can have multi-line comments.

Keep in mind this solution substitutes by nothing (meaning “something empty”, as opposed to deleting), so if you have a comment by itself on a line, it will still leave an empty line.

On a tangent note, I recommend rubular to test out ruby regular expressions in real time.

Edited by Vítor

Share this post


Link to post

Awesome! Thanks, Vitor.

 

Obviously I was silly to have flipped my << and my >>. I admit to a little bit of regexp dazzle, getting all turned around just trying to understand them at all.

 

Your new line is exactly what I needed! Thank you, my friend. :)

Share this post


Link to post

Update.

Added footnote support. Those aren’t really supported in BBCode, so there are some liberties with how they’re presented. You define them by setting something like [^1] in your text, and then again at the end of it (with a preceding blank line). The ones at the bottom should have no blank lines between them, as on conversion they’ll be added, as well as a line separating footnotes from the rest of the text.
 

If we have a text[^1] like this[^2].

With multiple lines and footnotes.

[^1] It will be converted.
[^2] To something a bit more readable.

If we have a text1 like this2.

With multiple lines and footnotes.

——————————
1 It will be converted.

2 To something a bit more readable.

Share this post


Link to post

Yes, it would be somewhat trivial, but also somewhat time consuming. I, for one, believe you’re an isolated case in this, so I don’t intend to add support for it (the reason I’ve built this in the first place is that I find BBCode awful to write). I’ll gladly give you some help with transforming it, though. You should be able to do it with no understanding of ruby and some understanding of regular expressions.
 
It might also not be as simple as it looks at first. I took some liberties in interpreting certain transformations — transformations that can translate well from markdown to BBCode, but not the reverse. For example, in setting up headers, since they don’t exist in BBCode, I’ve picked a few of the markdown header sizes (from the available 6) and while converting what I do is make the text bold and increase its size to a number I’ve picked (from the available theoretically infinite1). Right now, if you’re unhappy with the sizes I’ve picked (or even the bold, as you might prefer them in italic, for example) its relatively easy to simply open the substitutions file, and change them to end up like you want2.

Now, how would we do the reverse? How would we define which combination of styles and sizes correspond to each header? Sure, it can be done, but it would take an insane amount os personal opinion and styling preference. I make it easy for you to edit the substitutions, but I also try to make very good defaults so you don’t feel a need to. Thats exponentially hard with the reverse system, because there are so many variations, no set of assumptions should satisfy most cases without the need for tweaking.

Markdown → BBCode means what you’ve used somewhere else could be transformed (and easily tweaked) without modifying the original content. BBCode → Markdown means dictating how you need to structure your content to get the desired result. It works the way it is currently because markdown has structure where BBCode only has styling declarations. A markdown header (likely) means you want your text bigger, but defining bigger text in BBCode does not mean you want a header. Structure → styling makes sense, styling → structure not so much.

——————————
1 Is there a size limit? Even if there is, it’s definitely higher than 6.

2 That’s a design decision present from the start. the workflow’s structure itself is influenced by this idea of making it easy to modify the substitutions that were driven by my opinions.

Share this post


Link to post

Hi Vitor. Just discovered this workflow. Is there a way for you to show the different conversions supported inside alfred? Im not savvy with markdown so i have to have this workflow page open as docu lol. 

 

Thanks for this!

Share this post


Link to post

Update.

  • Ever noticed that stupid non-breaking whitespace forum software automatically adds to your empty lines? Gone! That space could sometimes confuse the other transformations (particularly quotes), so hopefully they’ll now work more reliably.
  • Footnotes are now separated by a full horizontal line instead of dashes.
  • Inline code now has a background color.

Don’t worry if you see some tags in your preview. The forum software may not interpret them in the preview, but it will display them after posting.

Edited by Vítor

Share this post


Link to post

Update.

 

By default, for inline code, use Courier instead of Courier New.

 

To update, download the latest version (same URL) or wait a few days (15 or less) and it’ll prompt you to on next usage, since it uses OneUpdater.

Share this post


Link to post

Speaking of OneUpdater, it is really awesome. I wish more workflows implemented it.

 

The only thing I am curious about though is why WebScreenshot updates so often? :D 

 

Share this post


Link to post
2 minutes ago, nikivi said:

Speaking of OneUpdater, it is really awesome. I wish more workflows implemented it.

 

Thank you for the kind words. I’m pretty confident OneUpdater isn’t that well known, so if you’d like to see it implemented more broadly (though it is meant to be versatile enough for you to implement it yourself in other people’s workflows), you should ask the developers to do so. If any has any questions, I’m available to answer.

 

2 minutes ago, nikivi said:

The only thing I am curious about though is why WebScreenshot updates so often? :D 

 

All updates are documented on the post. Long story short(er), it uses an external tool to upload the images to imgur. The original tool had a few issues, so I contributed upstream and worked with the author to fix them. As I found those issues with the tool and fixed them, WebScreenshot needed to be updated as well, naturally. Recently, however, as issues kept popping up for no discernible reason, I decided for various reasons the tool was just too broken and it wasn’t worth it to keep fixing it, so I changed it. With the change to a new tool, however, some implementation details changed, so I need to fix those as well. This new tool also as some minor issues I’m in the process of fixing. It’s better to have the workflow be made robuster regularly than just waiting and bottling up a lot of updates, especially since I have so many released workflows, sometimes they’re hard to keep track of.

Share this post


Link to post

Oh, this makes sense then. Thank you for the updates.

 

There is an issue though. It seems the urls I get, have a space at the end of it, so for example, I make a screenshot and try and paste it here : 

 

xwebnMl.png 

 

The above, after pasting, will become this : 

 

7X6hb4u.png 

 

I have to press delete every time after pasting. Can you help fix this issue? Thank you.

Edited by nikivi

Share this post


Link to post

Update.


Counter IPBoard's collapse of empty lines.


To update, download the latest version (same URL) or wait a few days (15 or less) and it’ll prompt you to on next usage, since it uses OneUpdater.

Share this post


Link to post

Update.

 

No longer use auto:0 in code blocks.


To update, download the latest version (same URL) or wait a few days (15 or less) and it’ll prompt you to on next usage, since it uses OneUpdater.

Edited by vitor

Share this post


Link to post

Update.


Don't start and end quotes with newlines.


To update, download the latest version (same URL) or wait a few days (15 or less) and it’ll prompt you to on next usage, since it uses OneUpdater.

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...