Permalink
Browse files

Add a CLI tool (mmmarkdown) that reads Markdown from stdin and writes…

… the corresponding HTML to stdout
  • Loading branch information...
1 parent ab17df8 commit 7de2eeeb75b683afceb98b396ef772875c7b73be @mdiep committed Feb 25, 2012
View
@@ -0,0 +1,62 @@
+//
+// main.m
+// mmmarkdown
+//
+// Copyright (c) 2012 Matt Diephouse.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#import <Foundation/Foundation.h>
+
+#import "MMMarkdown.h"
+
+int main(int argc, const char * argv[])
+{
+
+ @autoreleasepool
+ {
+ // Read the Markdown from STDIN
+ NSFileHandle *inHandle = [NSFileHandle fileHandleWithStandardInput];
+ NSData *inData = [inHandle readDataToEndOfFile];
+ NSString *markdown = [[NSString alloc] initWithData:inData encoding:NSUTF8StringEncoding];
+
+ // Convert to HTML
+ NSError *error;
+ NSString *HTML = [MMMarkdown HTMLStringWithMarkdown:markdown error:&error];
+
+ // Bail if there was an error
+ if (!HTML)
+ {
+ NSFileHandle *errHandle = [NSFileHandle fileHandleWithStandardError];
+ NSString *msg = [error localizedDescription];
+ NSData *errData = [msg dataUsingEncoding:NSUTF8StringEncoding];
+ [errHandle writeData:errData];
+ return EXIT_FAILURE;
+ }
+
+ // Write the HTML to STDOUT
+ NSFileHandle *outHandle = [NSFileHandle fileHandleWithStandardOutput];
+ NSData *outData = [HTML dataUsingEncoding:NSUTF8StringEncoding];
+ [outHandle writeData:outData];
+ }
+
+ return EXIT_SUCCESS;
+}
+
@@ -0,0 +1,7 @@
+//
+// Prefix header for all source files of the 'mmmarkdown' target in the 'mmmarkdown' project
+//
+
+#ifdef __OBJC__
+ #import <Foundation/Foundation.h>
+#endif
@@ -13,6 +13,9 @@
BE813DF614F893EB00EC9469 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BE813DF414F893EB00EC9469 /* InfoPlist.strings */; };
BE813DF914F893EB00EC9469 /* MMMarkdownTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BE813DF814F893EB00EC9469 /* MMMarkdownTests.m */; };
BE813E0814F8961D00EC9469 /* MMMarkdown.m in Sources */ = {isa = PBXBuildFile; fileRef = BE813DE314F893EB00EC9469 /* MMMarkdown.m */; };
+ BE813E1514F92B6100EC9469 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BE813DDE14F893EB00EC9469 /* Foundation.framework */; };
+ BE813E1814F92B6200EC9469 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = BE813E1714F92B6100EC9469 /* main.m */; };
+ BE813E2014F92BF600EC9469 /* libMMMarkdown-Mac.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BE813DD614F893EB00EC9469 /* libMMMarkdown-Mac.a */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -25,6 +28,18 @@
};
/* End PBXContainerItemProxy section */
+/* Begin PBXCopyFilesBuildPhase section */
+ BE813E1114F92B6100EC9469 /* CopyFiles */ = {
+ isa = PBXCopyFilesBuildPhase;
+ buildActionMask = 2147483647;
+ dstPath = /usr/share/man/man1/;
+ dstSubfolderSpec = 0;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 1;
+ };
+/* End PBXCopyFilesBuildPhase section */
+
/* Begin PBXFileReference section */
BE813DD614F893EB00EC9469 /* libMMMarkdown-Mac.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libMMMarkdown-Mac.a"; sourceTree = BUILT_PRODUCTS_DIR; };
BE813DDE14F893EB00EC9469 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@@ -38,6 +53,9 @@
BE813DF714F893EB00EC9469 /* MMMarkdownTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMMarkdownTests.h; sourceTree = "<group>"; };
BE813DF814F893EB00EC9469 /* MMMarkdownTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MMMarkdownTests.m; sourceTree = "<group>"; };
BE813E0E14F8961D00EC9469 /* libMMMarkdown-Mac copy.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libMMMarkdown-Mac copy.a"; sourceTree = BUILT_PRODUCTS_DIR; };
+ BE813E1314F92B6100EC9469 /* mmmarkdown */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = mmmarkdown; sourceTree = BUILT_PRODUCTS_DIR; };
+ BE813E1714F92B6100EC9469 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+ BE813E1A14F92B6200EC9469 /* mmmarkdown-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "mmmarkdown-Prefix.pch"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -64,13 +82,23 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
+ BE813E1014F92B6100EC9469 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ BE813E2014F92BF600EC9469 /* libMMMarkdown-Mac.a in Frameworks */,
+ BE813E1514F92B6100EC9469 /* Foundation.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
BE813DCB14F893EB00EC9469 = {
isa = PBXGroup;
children = (
BE813DDF14F893EB00EC9469 /* Source */,
+ BE813E1614F92B6100EC9469 /* CLI */,
BE813DF114F893EB00EC9469 /* Tests */,
BE813DD814F893EB00EC9469 /* Frameworks */,
BE813DD714F893EB00EC9469 /* Products */,
@@ -83,6 +111,7 @@
BE813DD614F893EB00EC9469 /* libMMMarkdown-Mac.a */,
BE813DEA14F893EB00EC9469 /* MMMarkdownTests.octest */,
BE813E0E14F8961D00EC9469 /* libMMMarkdown-Mac copy.a */,
+ BE813E1314F92B6100EC9469 /* mmmarkdown */,
);
name = Products;
sourceTree = "<group>";
@@ -117,6 +146,15 @@
path = Tests;
sourceTree = "<group>";
};
+ BE813E1614F92B6100EC9469 /* CLI */ = {
+ isa = PBXGroup;
+ children = (
+ BE813E1714F92B6100EC9469 /* main.m */,
+ BE813E1A14F92B6200EC9469 /* mmmarkdown-Prefix.pch */,
+ );
+ path = CLI;
+ sourceTree = "<group>";
+ };
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
@@ -190,6 +228,23 @@
productReference = BE813E0E14F8961D00EC9469 /* libMMMarkdown-Mac copy.a */;
productType = "com.apple.product-type.library.static";
};
+ BE813E1214F92B6100EC9469 /* mmmarkdown */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = BE813E1D14F92B6200EC9469 /* Build configuration list for PBXNativeTarget "mmmarkdown" */;
+ buildPhases = (
+ BE813E0F14F92B6100EC9469 /* Sources */,
+ BE813E1014F92B6100EC9469 /* Frameworks */,
+ BE813E1114F92B6100EC9469 /* CopyFiles */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = mmmarkdown;
+ productName = mmmarkdown;
+ productReference = BE813E1314F92B6100EC9469 /* mmmarkdown */;
+ productType = "com.apple.product-type.tool";
+ };
/* End PBXNativeTarget section */
/* Begin PBXProject section */
@@ -213,6 +268,7 @@
BE813DD514F893EB00EC9469 /* MMMarkdown-Mac */,
BE813E0614F8961D00EC9469 /* MMMarkdown-iOS */,
BE813DE914F893EB00EC9469 /* MMMarkdownTests */,
+ BE813E1214F92B6100EC9469 /* mmmarkdown */,
);
};
/* End PBXProject section */
@@ -269,6 +325,14 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
+ BE813E0F14F92B6100EC9469 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ BE813E1814F92B6200EC9469 /* main.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
@@ -403,6 +467,28 @@
};
name = Release;
};
+ BE813E1E14F92B6200EC9469 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "CLI/mmmarkdown-Prefix.pch";
+ MACOSX_DEPLOYMENT_TARGET = 10.7;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ SDKROOT = macosx;
+ };
+ name = Debug;
+ };
+ BE813E1F14F92B6200EC9469 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "CLI/mmmarkdown-Prefix.pch";
+ MACOSX_DEPLOYMENT_TARGET = 10.7;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ SDKROOT = macosx;
+ };
+ name = Release;
+ };
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
@@ -442,6 +528,14 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
+ BE813E1D14F92B6200EC9469 /* Build configuration list for PBXNativeTarget "mmmarkdown" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ BE813E1E14F92B6200EC9469 /* Debug */,
+ BE813E1F14F92B6200EC9469 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ };
/* End XCConfigurationList section */
};
rootObject = BE813DCD14F893EB00EC9469 /* Project object */;
@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+ version = "1.3">
+ <BuildAction
+ parallelizeBuildables = "NO"
+ buildImplicitDependencies = "NO">
+ <BuildActionEntries>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "BE813DD514F893EB00EC9469"
+ BuildableName = "libMMMarkdown-Mac.a"
+ BlueprintName = "MMMarkdown-Mac"
+ ReferencedContainer = "container:MMMarkdown.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "BE813E1214F92B6100EC9469"
+ BuildableName = "mmmarkdown"
+ BlueprintName = "mmmarkdown"
+ ReferencedContainer = "container:MMMarkdown.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ </BuildActionEntries>
+ </BuildAction>
+ <TestAction
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ buildConfiguration = "Debug">
+ <Testables>
+ </Testables>
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "BE813E1214F92B6100EC9469"
+ BuildableName = "mmmarkdown"
+ BlueprintName = "mmmarkdown"
+ ReferencedContainer = "container:MMMarkdown.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ </TestAction>
+ <LaunchAction
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ launchStyle = "0"
+ useCustomWorkingDirectory = "NO"
+ buildConfiguration = "Debug"
+ ignoresPersistentStateOnLaunch = "NO"
+ debugDocumentVersioning = "YES"
+ allowLocationSimulation = "YES">
+ <BuildableProductRunnable>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "BE813E1214F92B6100EC9469"
+ BuildableName = "mmmarkdown"
+ BlueprintName = "mmmarkdown"
+ ReferencedContainer = "container:MMMarkdown.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </LaunchAction>
+ <ProfileAction
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ savedToolIdentifier = ""
+ useCustomWorkingDirectory = "NO"
+ buildConfiguration = "Release"
+ debugDocumentVersioning = "YES">
+ <BuildableProductRunnable>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "BE813E1214F92B6100EC9469"
+ BuildableName = "mmmarkdown"
+ BlueprintName = "mmmarkdown"
+ ReferencedContainer = "container:MMMarkdown.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ </ProfileAction>
+ <AnalyzeAction
+ buildConfiguration = "Debug">
+ </AnalyzeAction>
+ <ArchiveAction
+ buildConfiguration = "Release"
+ revealArchiveInOrganizer = "YES">
+ </ArchiveAction>
+</Scheme>

0 comments on commit 7de2eee

Please sign in to comment.