Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial support for markdown generation completed

  • Loading branch information...
commit efccfa45f9e718cab2e6016d7ed69dc2395cbec4 1 parent 7b0df16
@mgalgs authored
View
1  .gitignore
@@ -0,0 +1 @@
+*~
View
0  README
No changes.
View
41 README.md
@@ -0,0 +1,41 @@
+Commentary
+==========
+
+Easily convert elisp file headers to markdown text. The file
+comment headers should be similar to this one.
+
+Installation
+============
+
+None
+
+Use
+===
+
+Invoke this elisp file with emacs --script like so:
+ `$ emacs --script make-readme-markdown.el < elisp-file-to-parse.el`
+
+(Note: you might have to redirect stderr to `/dev/null` to avoid
+some pesky "loading vc-git" messages and the like...)
+
+Output is written to stdout.
+
+You can also pass the -nospam switch to prevent the little
+"Generated by" text from showing up.
+
+Supported syntax
+================
+
+In order for this module to do you any good, you should write your
+file header comments in a way that make-readme-markdown.el
+understands. An attempt has been made to support the most common
+file header comment style:
+
+* ';;;' at the beginning of a line for a header.
+* ';;`' at the beginning of a line for a code line.
+* 'o' at the beginning of a line for a list item
+
+<div style="padding-top:15px;color: #d0d0d0;">
+Markdown README file generated by
+<a href="https://github.com/mgalgs/make-readme-markdown">make-readme-markdown.el</a>
+</div>
View
123 make-readme-markdown.el
@@ -0,0 +1,123 @@
+;;; make-readme-markdown.el --- Convert header section of elisp file
+;;; to markdown text, suitable for a github README.md file
+
+;; Copyright (C) 2011, Mitchel Humpherys
+
+;; Author: Mitchel Humpherys <mitch.special@gmail.com>
+;; Keywords: convenience
+;; Version: 0.1
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;;
+;; Easily convert elisp file headers to markdown text. The file
+;; comment headers should be similar to this one.
+;;
+;;; Installation:
+;;
+;; None
+;;
+;;; Use:
+;;
+;; Invoke this elisp file with emacs --script like so:
+;;` $ emacs --script make-readme-markdown.el < elisp-file-to-parse.el
+;;
+;; (Note: you might have to redirect stderr to `/dev/null` to avoid
+;; some pesky "loading vc-git" messages and the like...)
+;;
+;; Output is written to stdout.
+;;
+;; You can also pass the -nospam switch to prevent the little
+;; "Generated by" text from showing up.
+;;
+;;; Supported syntax:
+;;
+;; In order for this module to do you any good, you should write your
+;; file header comments in a way that make-readme-markdown.el
+;; understands. An attempt has been made to support the most common
+;; file header comment style:
+;;
+;; o ';;;' at the beginning of a line for a header.
+;; o ';;`' at the beginning of a line for a code line.
+;; o 'o' at the beginning of a line for a list item
+;;
+;;; Code
+
+
+(defun strip-comments (line)
+ "Stip elisp comments from line"
+ (trim-string (replace-regexp-in-string "^;+" "" line)))
+
+(defun trim-string (line)
+ "Trim spaces from beginning and end of string"
+ (replace-regexp-in-string " +$" ""
+ (replace-regexp-in-string "^ +" "" line)))
+
+(defun print-formatted-line (line)
+ "Prints a line formatted as markdown."
+ (let ((stripped-line (strip-comments line)))
+ (cond
+
+ ;; Header line (starts with ";;;")
+ ((string-match "^;;;" line)
+ (let ((line (car (split-string stripped-line ":"))))
+ (princ line)
+ (princ "\n")
+ (princ (make-string (length line) ?=))))
+
+ ;; list line (starts with " o ")
+ ((string-match "^ *o " stripped-line)
+ (let ((line (replace-regexp-in-string "^ *\o" "*" stripped-line)))
+ (princ line)))
+
+ ;; code line (starts with "`")
+ ((string-match "^`" stripped-line)
+ (let ((line (concat " `"
+ (trim-string (nth 1 (split-string stripped-line "`")))
+ "`")))
+ (princ line)))
+
+ ;; default (just print it)
+ (t
+ (princ stripped-line))))
+
+ ;; and a newline
+ (princ "\n"))
+;; eo print-formatted-line
+
+;; process the input:
+(let (line (started-output nil))
+ (catch 'break
+ (while (setq line (read-from-minibuffer ""))
+ ;; we've reached the end when we see "Code" all by itself:
+ (if (string= "Code" (strip-comments line)) (throw 'break nil))
+ (if (string= "Commentary:" (strip-comments line)) (setq started-output t))
+ (if started-output (print-formatted-line line)))))
+
+
+;; default command line options:
+;; (setq got-no-spam nil)
+
+;; custom command line options:
+;; (setq command-switch-alist
+;; '(("nospam" . (lambda (arg) (setq got-no-spam t)))))
+
+;; parse the commad line:
+;; (command-line)
+
+(princ "<div style=\"padding-top:15px;color: #d0d0d0;\">
+Markdown README file generated by
+<a href=\"https://github.com/mgalgs/make-readme-markdown\">make-readme-markdown.el</a>
+</div>\n")

0 comments on commit efccfa4

Please sign in to comment.
Something went wrong with that request. Please try again.