Converting (partially) MultiMarkdown Composer styles to Marked styles -- Solution

Glenn Hoetker's Avatar

Glenn Hoetker

19 Nov, 2014 05:41 PM

I may be the only person in the world who would find this this useful, but in case there are others....

The Challenge

MultiMarkdown Composer has some nice styles that don't have a counter-part in Marked (and vis-a-versa, but that's a different post). So, I was trying to figure out how to use MMC styles in Marked. This is particularly the case if I like how things look with the MMC style, but want to export from Marked, as it offers some additional options.

The Problem

Just copying MMC styles over to Marked's custom css folder and changing their extension to ".css" didn't seem to work. MMC styles are a combination of CSS and its own syntax. For most styles, the CSS reproducing the CSS will get you 80-100% of the way to what you want as a Marked style. But, I didn't want to manually copy that from 15+ different files!

The attached Applescript, written using Javascript for Automation, automates the process. You should be able to paste it into Script Editor, switch from "Applescript" to "Javascript" in the dropdown menu at the upper right corner of the editing area, change the mmcStyleFOlder and markedStyleFolder paths near the top of the program and then run it. It will automatically extract the CSS portion of each MMC style and create a correspondingly named Marked style. So, "My" becomes "MMC My Style.css" in the custom CSS folder for Marked. You'll have to manually add the style via Marked's preference pane to use it.

A few caveats:

  • Lightly tested at best with almost no error checking. It did what I wanted without destroying anything, but you assume ALL RISK in using it on your computer. Backups are a good idea.

  • Prepending "MMC" is meant to avoid overwriting existing Marked styles, but will overwrite any styles of the same name. So, be careful.

  • Some MMC styles rely heavily on their non-CSS code. They will obviously need more work to appear the same in Marked as they did in MMC.

  • The delimiters I used to isolate the CSS portion of the MMC styles worked in 95% of the cases. However, if things don't work, it might be worth checking if the CSS was properly captured.

  • Obviously, this little programette will be most useful to those comfortable tweaking CSS.

  • I've only been a serious Javascript user since JavaScript for Automation came out with OS X Yosemite. So, my code is doubtlessly a horror show to better coders. Please let me know if you spot potential catastrophic flaws, but otherwise laugh only quietly.

Best wishes to all and thanks to Brett and Fletcher for their wonderful programs.

Program to transfer MultiMarkdown styles to Marked styles.  
Imperfect at best, but perhaps a useful start.  

 var app = Application.currentApplication()
 app.includeStandardAdditions = true
 var system = Application('System Events')
 var Finder = Application('Finder')

// At a minimum, you'll have to change these to put in your username.
//  Depending whether you have a webstore or Mac AppStore 
// version of each program, the location of the styles may differ.
// From each program's preferences, there is an option 
// to reveal the styles folder, which is how to discover
// the right location

 mmcStyleFolder = Path('/Users/XXXXX/Library/Application Support/MultiMarkdown Composer/Styles/') 
 var markedStyleFolder = '/Users/XXXXX/Library/Containers/com.brettterpstra.marked2/Data/Library/Application Support/Marked 2/Custom CSS/'

 //Read files
 //var theFiles=app.chooseFile({multipleSelectionsAllowed: true})
 var theFiles = app.chooseFile({
     multipleSelectionsAllowed: true,
     withPrompt: 'Pick a folder',
     defaultLocation: mmcStyleFolder
 var documentPath = theFiles.toString()

 // Cycle through files

 for (var i = 0; i < theFiles.length; i++) {

     //Read in the content and extract the CSS related part
     var a = app.openForAccess(theFiles[i])
     var theContent =
     var cssIndex = theContent.indexOf("css =") + 7
     var cssHead = theContent.slice(cssIndex)
     var cssTail = cssHead.indexOf('";')
     var cssBody = cssHead.slice(0, cssTail)

     // Construct name for new file and write CSS to it
     var oldFileName = system.files.byName(theFiles[i].toString()).name()
     var newFileName = "MCC " + oldFileName.split("\.")[0] + ".css"
     var newPathName = markedStyleFolder + newFileName
     path = Path(newPathName)

     try {
     } catch (ex) {}

     newFile = app.openForAccess(path, {
         writePermission: true

     app.write(cssBody, {
         to: newFile


Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac