Markdown, Syntax-Colored Source Code
In this post I want to see if I can use Markdown and Blog Text in order to have syntax colored source code.
Source Code
This is an inner Java Class:
private static class LogLevelConfig { private LogLevel mLogLevel; private Pattern mModelIdGlobPattern; private Pattern mModelTitleGlobPattern; public LogLevelConfig( String pModelIdGlob, String pModelTitleGlob, String pLogLevel ) { if( pLogLevel == null || pLogLevel.trim().length() == 0 ) { mLogLevel = LogLevel.debug; } else { try { mLogLevel = LogLevel.valueOf( pLogLevel ); LOG.info( "activate(), given log level found: {}", mLogLevel ); } catch( Exception e ) { throw new IllegalArgumentException( "no log level found for: '" + pLogLevel + "'" ); } } if( pModelIdGlob != null && pModelIdGlob.trim().length() > 0 ) { mModelIdGlobPattern = Pattern.compile( pModelIdGlob ); } if( pModelTitleGlob != null && pModelTitleGlob.trim().length() > 0 ) { mModelTitleGlobPattern = Pattern.compile( pModelTitleGlob ); } } public LogLevel getLogLevel() { return mLogLevel; } public boolean matchWorkflowModel( WorkflowModel pWorkflowModel ) { boolean lReturn = true; if( mModelIdGlobPattern != null ) { lReturn = mModelIdGlobPattern.matcher( pWorkflowModel.getId() ).matches(); } if( mModelTitleGlobPattern != null ) { lReturn &= mModelTitleGlobPattern.matcher( pWorkflowModel.getTitle() ).matches(); } return lReturn; } }
This is now the same code in Markdown:
private static class LogLevelConfig {
private LogLevel mLogLevel;
private Pattern mModelIdGlobPattern;
private Pattern mModelTitleGlobPattern;
public LogLevelConfig( String pModelIdGlob, String pModelTitleGlob, String pLogLevel ) {
if( pLogLevel == null || pLogLevel.trim().length() == 0 ) {
mLogLevel = LogLevel.debug;
} else {
try {
mLogLevel = LogLevel.valueOf( pLogLevel );
LOG.info( "activate(), given log level found: {}", mLogLevel );
} catch( Exception e ) {
throw new IllegalArgumentException( "no log level found for: '" + pLogLevel + "'" );
}
}
if( pModelIdGlob != null && pModelIdGlob.trim().length() > 0 ) {
mModelIdGlobPattern = Pattern.compile( pModelIdGlob );
}
if( pModelTitleGlob != null && pModelTitleGlob.trim().length() > 0 ) {
mModelTitleGlobPattern = Pattern.compile( pModelTitleGlob );
}
}
public LogLevel getLogLevel() {
return mLogLevel;
}
public boolean matchWorkflowModel( WorkflowModel pWorkflowModel ) {
boolean lReturn = true;
if( mModelIdGlobPattern != null ) {
lReturn = mModelIdGlobPattern.matcher( pWorkflowModel.getId() ).matches();
}
if( mModelTitleGlobPattern != null ) {
lReturn &= mModelTitleGlobPattern.matcher( pWorkflowModel.getTitle() ).matches();
}
return lReturn;
}
}
How I did it
First I must make sure that Markdown is ignoring my Blog Text Code snippet by enclosing the entire Code into a <div> block and then use the Blog Text syntax to define the code block which is are 3 cutely brackets together with the attribute lang defining the source code language for the Syntax Coloring. When I wanted to display the Markdown version of the Source Code I had to use the Blog Text No-Parse tags (two curly brackets followed by two exclamation marks). But if I use Blog Text then I will use only Blog Text for source code and not both.
The only downside of that all is that Markdown preview displays just a blob of text. Still the code is not infused with HTML making it impossible to read and without the additional work to convert the code every time to HTML.
— Andy
MarsEdit, WordPress and BlogText All In One
Today I wanted to see if I could use MarsEdit and BBEdit to post a Post or Page to this WordPress site using BlogText plugin for WordPress.
BlogText is a simple markup language so that I don’t have to write HTML in order to post a Blog. Now with the HTML editor of MarsEdit that maybe isn’t necessary but I am going to edit the posts / pages through the Web Interface or iOS App and then I want to make it as quickly as possible.
Initially I ran into a lot of issues because MarsEdit did create HTML around the BlogText effectively rendering BlogText mute. Then I tried to use the HTML view and voila it would send the content as is. So I changed the default editor back to the HTML editor and now I can edit my posts like this one with BBEdit using BlogText through MarsEdit.
BTW I like MarsEdit because it is faster to navigate and has a better overview than the Web interface of WordPress.
– Andy