1 Commits

Author SHA1 Message Date
rentzsch 28cca588a4 [DEV] Replace discount Markdown-to-html engine with mayday. 2009-09-15 16:09:54 -05:00
99 changed files with 15 additions and 13296 deletions
+3
View File
@@ -0,0 +1,3 @@
[submodule "mayday"]
path = mayday
url = git://github.com/jemmons/mayday.git
+2 -2
View File
@@ -40,9 +40,9 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.5.1</string>
<string>1.6</string>
<key>CFBundleShortVersionString</key>
<string>1.5.1</string>
<string>1.6</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSMainNibFile</key>
+6 -60
View File
@@ -9,17 +9,9 @@
/* Begin PBXBuildFile section */
1DDD582C0DA1D0D100B32029 /* MyDocument.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD58280DA1D0D100B32029 /* MyDocument.xib */; };
1DDD582D0DA1D0D100B32029 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD582A0DA1D0D100B32029 /* MainMenu.xib */; };
795F6C4F105D6EC400D1F90A /* mkdio.c in Sources */ = {isa = PBXBuildFile; fileRef = 795F6C4E105D6EC400D1F90A /* mkdio.c */; };
795F6C51105D6ECE00D1F90A /* markdown.c in Sources */ = {isa = PBXBuildFile; fileRef = 795F6C50105D6ECE00D1F90A /* markdown.c */; };
795F6C53105D6ED800D1F90A /* generate.c in Sources */ = {isa = PBXBuildFile; fileRef = 795F6C52105D6ED800D1F90A /* generate.c */; };
795F6C55105D6EE100D1F90A /* resource.c in Sources */ = {isa = PBXBuildFile; fileRef = 795F6C54105D6EE100D1F90A /* resource.c */; };
795F6C62105D6F6E00D1F90A /* xml.c in Sources */ = {isa = PBXBuildFile; fileRef = 795F6C61105D6F6E00D1F90A /* xml.c */; };
795F6C66105D6F8500D1F90A /* Csio.c in Sources */ = {isa = PBXBuildFile; fileRef = 795F6C65105D6F8500D1F90A /* Csio.c */; };
795F6C87105D70A300D1F90A /* MarkdownLiveApp.icns in Resources */ = {isa = PBXBuildFile; fileRef = 795F6C86105D70A300D1F90A /* MarkdownLiveApp.icns */; };
795F6CCD105D741100D1F90A /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 795F6CCC105D741100D1F90A /* WebKit.framework */; };
795F6DBA105D75D300D1F90A /* discountWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 795F6DB5105D75D300D1F90A /* discountWrapper.m */; };
795F6DBB105D75D300D1F90A /* markdownWrapper.c in Sources */ = {isa = PBXBuildFile; fileRef = 795F6DB6105D75D300D1F90A /* markdownWrapper.c */; };
795F6DBC105D75D300D1F90A /* mkdioWrapper.c in Sources */ = {isa = PBXBuildFile; fileRef = 795F6DB8105D75D300D1F90A /* mkdioWrapper.c */; };
79B3D5441060376F00A8D174 /* MDMarkdownParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 79B3D5431060376F00A8D174 /* MDMarkdownParser.m */; };
8D15AC2C0486D014006FF6A4 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 2A37F4B9FDCFA73011CA2CEA /* Credits.rtf */; };
8D15AC2F0486D014006FF6A4 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165FFE840EACC02AAC07 /* InfoPlist.strings */; };
8D15AC310486D014006FF6A4 /* MyDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 2A37F4ACFDCFA73011CA2CEA /* MyDocument.m */; settings = {ATTRIBUTES = (); }; };
@@ -40,20 +32,10 @@
2A37F4BAFDCFA73011CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = English; path = English.lproj/Credits.rtf; sourceTree = "<group>"; };
2A37F4C4FDCFA73011CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
2A37F4C5FDCFA73011CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
795F6C4E105D6EC400D1F90A /* mkdio.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mkdio.c; sourceTree = "<group>"; };
795F6C50105D6ECE00D1F90A /* markdown.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = markdown.c; sourceTree = "<group>"; };
795F6C52105D6ED800D1F90A /* generate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = generate.c; sourceTree = "<group>"; };
795F6C54105D6EE100D1F90A /* resource.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = resource.c; sourceTree = "<group>"; };
795F6C61105D6F6E00D1F90A /* xml.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = xml.c; sourceTree = "<group>"; };
795F6C65105D6F8500D1F90A /* Csio.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Csio.c; sourceTree = "<group>"; };
795F6C86105D70A300D1F90A /* MarkdownLiveApp.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = MarkdownLiveApp.icns; sourceTree = "<group>"; };
795F6CCC105D741100D1F90A /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = /System/Library/Frameworks/WebKit.framework; sourceTree = "<absolute>"; };
795F6DB4105D75D300D1F90A /* discountWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = discountWrapper.h; sourceTree = "<group>"; };
795F6DB5105D75D300D1F90A /* discountWrapper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = discountWrapper.m; sourceTree = "<group>"; };
795F6DB6105D75D300D1F90A /* markdownWrapper.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = markdownWrapper.c; sourceTree = "<group>"; };
795F6DB7105D75D300D1F90A /* markdownWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = markdownWrapper.h; sourceTree = "<group>"; };
795F6DB8105D75D300D1F90A /* mkdioWrapper.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mkdioWrapper.c; sourceTree = "<group>"; };
795F6DB9105D75D300D1F90A /* mkdioWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mkdioWrapper.h; sourceTree = "<group>"; };
79B3D5421060376F00A8D174 /* MDMarkdownParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MDMarkdownParser.h; path = mayday/MDMarkdownParser.h; sourceTree = "<group>"; };
79B3D5431060376F00A8D174 /* MDMarkdownParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MDMarkdownParser.m; path = mayday/MDMarkdownParser.m; sourceTree = "<group>"; };
8D15AC360486D014006FF6A4 /* MarkdownLive-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "MarkdownLive-Info.plist"; sourceTree = "<group>"; };
8D15AC370486D014006FF6A4 /* MarkdownLive.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MarkdownLive.app; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
@@ -102,8 +84,6 @@
isa = PBXGroup;
children = (
2A37F4ABFDCFA73011CA2CEA /* Classes */,
795F6C4D105D6EA500D1F90A /* discount-1.5.4 */,
795F6DB3105D75D300D1F90A /* discount_wrappers */,
2A37F4AFFDCFA73011CA2CEA /* Other Sources */,
2A37F4B8FDCFA73011CA2CEA /* Resources */,
2A37F4C3FDCFA73011CA2CEA /* Frameworks */,
@@ -117,6 +97,8 @@
children = (
2A37F4AEFDCFA73011CA2CEA /* MyDocument.h */,
2A37F4ACFDCFA73011CA2CEA /* MyDocument.m */,
79B3D5421060376F00A8D174 /* MDMarkdownParser.h */,
79B3D5431060376F00A8D174 /* MDMarkdownParser.m */,
);
name = Classes;
sourceTree = "<group>";
@@ -152,32 +134,6 @@
name = Frameworks;
sourceTree = "<group>";
};
795F6C4D105D6EA500D1F90A /* discount-1.5.4 */ = {
isa = PBXGroup;
children = (
795F6C4E105D6EC400D1F90A /* mkdio.c */,
795F6C50105D6ECE00D1F90A /* markdown.c */,
795F6C52105D6ED800D1F90A /* generate.c */,
795F6C54105D6EE100D1F90A /* resource.c */,
795F6C61105D6F6E00D1F90A /* xml.c */,
795F6C65105D6F8500D1F90A /* Csio.c */,
);
path = "discount-1.5.4";
sourceTree = "<group>";
};
795F6DB3105D75D300D1F90A /* discount_wrappers */ = {
isa = PBXGroup;
children = (
795F6DB4105D75D300D1F90A /* discountWrapper.h */,
795F6DB5105D75D300D1F90A /* discountWrapper.m */,
795F6DB6105D75D300D1F90A /* markdownWrapper.c */,
795F6DB7105D75D300D1F90A /* markdownWrapper.h */,
795F6DB8105D75D300D1F90A /* mkdioWrapper.c */,
795F6DB9105D75D300D1F90A /* mkdioWrapper.h */,
);
path = discount_wrappers;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -238,15 +194,7 @@
files = (
8D15AC310486D014006FF6A4 /* MyDocument.m in Sources */,
8D15AC320486D014006FF6A4 /* main.m in Sources */,
795F6C4F105D6EC400D1F90A /* mkdio.c in Sources */,
795F6C51105D6ECE00D1F90A /* markdown.c in Sources */,
795F6C53105D6ED800D1F90A /* generate.c in Sources */,
795F6C55105D6EE100D1F90A /* resource.c in Sources */,
795F6C62105D6F6E00D1F90A /* xml.c in Sources */,
795F6C66105D6F8500D1F90A /* Csio.c in Sources */,
795F6DBA105D75D300D1F90A /* discountWrapper.m in Sources */,
795F6DBB105D75D300D1F90A /* markdownWrapper.c in Sources */,
795F6DBC105D75D300D1F90A /* mkdioWrapper.c in Sources */,
79B3D5441060376F00A8D174 /* MDMarkdownParser.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -330,7 +278,6 @@
ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
SDKROOT = macosx10.6;
USER_HEADER_SEARCH_PATHS = "\"$(SRCROOT)/discount-1.5.4\"";
};
name = Debug;
};
@@ -343,7 +290,6 @@
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
SDKROOT = macosx10.6;
USER_HEADER_SEARCH_PATHS = "\"$(SRCROOT)/discount-1.5.4\"";
};
name = Release;
};
+3 -23
View File
@@ -1,5 +1,5 @@
#import "MyDocument.h"
#include "discountWrapper.h"
#import "MDMarkdownParser.h"
NSString *kMarkdownDocumentType = @"MarkdownDocumentType";
@@ -13,28 +13,8 @@ NSString *kMarkdownDocumentType = @"MarkdownDocumentType";
if (!markdown_)
return @"";
#if 0
NSString *result = nil;
char *markdownUTF8 = (char*)[markdown_ UTF8String];
Document *document = mkd_string(markdownUTF8, strlen(markdownUTF8), 0);
if (document) {
if (mkd_compile(document, 0)) {
char *htmlUTF8;
int htmlUTF8Len = mkd_document(document, &htmlUTF8);
if (htmlUTF8Len != EOF) {
result = [[[NSString alloc] initWithBytes:htmlUTF8
length:htmlUTF8Len
encoding:NSUTF8StringEncoding] autorelease];
}
mkd_cleanup(document);
}
}
return result;
#else
return discountToHTML(markdown_);
#endif
MDMarkdownParser *parser = [[[MDMarkdownParser alloc] init] autorelease];
return [parser cleanWhitespaceOnlyLinesInString:[parser detabString:markdown_]];
}
- (id)init {
-47
View File
@@ -1,47 +0,0 @@
->Copyright (C) 2007 David Loren Parsons.
All rights reserved.<-
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, sublicence, 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:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution, and in the same place and form as other
copyright, license and disclaimer information.
3. The end-user documentation included with the redistribution, if
any, must include the following acknowledgment:
This product includes software developed by
David Loren Parsons <http://www.pell.portland.or.us/~orc>
in the same place and form as other third-party acknowledgments.
Alternately, this acknowledgment may appear in the software
itself, in the same form and location as other such third-party
acknowledgments.
4. Except as contained in this notice, the name of David Loren
Parsons shall not be used in advertising or otherwise to promote
the sale, use or other dealings in this Software without prior
written authorization from David Loren Parsons.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL DAVID LOREN PARSONS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
-33
View File
@@ -1,33 +0,0 @@
Discount is primarily my work, but it has only reached the point
where it is via contributions, critiques, and bug reports from a
host of other people, some of which are listed before. If your
name isn't on this list, please remind me
-david parsons (orc@pell.chi.il.us)
Josh Wood -- Plan9 support.
Mike Schiraldi -- Reddit style automatic links, MANY MANY MANY
bug reports about boundary conditions and
places where I didn't get it right.
Jjgod Jiang -- Table of contents support.
Petite Abeille -- Many bug reports about places where I didn't
get it right.
Tim Channon -- inspiration for the `mkd_xhtmlpage()` function
Christian Herenz-- Many bug reports regarding my implementation of
`[]()` and `![]()`
A.S.Bradbury -- Portability bug reports for 64 bit systems.
Joyent -- Loan of a solaris box so I could get discount
working under solaris.
Ryan Tomayko -- Portability requests (and the rdiscount ruby
binding.)
yidabu -- feedback on the documentation, bug reports
against utf-8 support.
Pierre Joye -- bug reports, php discount binding.
Masayoshi Sekimura- perl discount binding.
Jeremy Hinegardner- bug reports about list handling.
Andrew White -- bug reports about the format of generated urls.
Steve Huff -- bug reports about Makefile portability (for Fink)
Ignacio Burgue?o-- bug reports about `>%class%`
Henrik Nyh -- bug reports about embedded html handling.
-61
View File
@@ -1,61 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "cstring.h"
#include "markdown.h"
#include "amalloc.h"
/* putc() into a cstring
*/
void
Csputc(int c, Cstring *iot)
{
EXPAND(*iot) = c;
}
/* printf() into a cstring
*/
int
Csprintf(Cstring *iot, char *fmt, ...)
{
va_list ptr;
int siz=100;
do {
RESERVE(*iot, siz);
va_start(ptr, fmt);
siz = vsnprintf(T(*iot)+S(*iot), ALLOCATED(*iot)-S(*iot), fmt, ptr);
va_end(ptr);
} while ( siz > (ALLOCATED(*iot)-S(*iot)) );
S(*iot) += siz;
return siz;
}
/* write() into a cstring
*/
int
Cswrite(Cstring *iot, char *bfr, int size)
{
RESERVE(*iot, size);
memcpy(T(*iot)+S(*iot), bfr, size);
S(*iot) += size;
return size;
}
/* reparse() into a cstring
*/
void
Csreparse(Cstring *iot, char *buf, int size, int flags)
{
MMIOT f;
___mkd_initmmiot(&f, 0);
___mkd_reparse(buf, size, 0, &f);
___mkd_emblock(&f);
SUFFIX(*iot, T(f.out), S(f.out));
___mkd_freemmiot(&f, 0);
}
-41
View File
@@ -1,41 +0,0 @@
HOW TO BUILD AND INSTALL DISCOUNT
1) Unpacking the distribution
The DISCOUNT sources are distributed in tarballs. After extracting from
the tarball, you should end up with all the source and build files in the
directory
discount-(version)
2) Installing the distribution
DISCOUNT uses configure.sh to set itself up for compilation. To run
configure, just do ``./configure.sh'' and it will check your system for
build dependencies and build makefiles for you. If configure.sh finishes
without complaint, you can then do a ``make'' to compile everything and a
``make install'' to install the binaries.
Configure.sh has a few options that can be set:
--src=DIR where the source lives (.)
--prefix=DIR where to install the final product (/usr/local)
--execdir=DIR where to put executables (prefix/bin)
--sbindir=DIR where to put static executables (prefix/sbin)
--confdir=DIR where to put configuration information (/etc)
--libdir=DIR where to put libraries (prefix/lib)
--libexecdir=DIR where to put private executables
--mandir=DIR where to put manpages
--enable-dl-tag Use the DL tag extension
--enable-pandoc-header Use pandoc-style header blocks
--enable-superscript A^B expands to A<sup>B</sup>
--enable-amalloc Use a debugging memory allocator (to detect leaks)
--relaxed-emphasis Don't treat _ in the middle of a word as emphasis
--with-tabstops=N Set tabstops to N characters (default is 4)
3) Installing sample programs and manpages
The standard ``make install'' rule just installs the binaries. If you
want to install the sample programs, they are installed with
``make install.samples''; to install manpages, ``make install.man''.
A shortcut to install everything is ``make install.everything''
-96
View File
@@ -1,96 +0,0 @@
CC=cc -I. -L.
AR=/usr/bin/ar
RANLIB=/usr/bin/ranlib
BINDIR=/usr/local/bin
MANDIR=/usr/local/man
LIBDIR=/usr/local/lib
INCDIR=/usr/local/include
PGMS=markdown
SAMPLE_PGMS=mkd2html makepage
SAMPLE_PGMS+= theme
MKDLIB=libmarkdown.a
OBJS=mkdio.o markdown.o dumptree.o generate.o \
resource.o docheader.o version.o toc.o css.o \
xml.o Csio.o xmlpage.o
all: $(PGMS) $(SAMPLE_PGMS)
install: $(PGMS)
/usr/bin/install -s -m 755 $(PGMS) $(DESTDIR)/$(BINDIR)
/usr/bin/install -m 444 $(MKDLIB) $(DESTDIR)/$(LIBDIR)
/usr/bin/install -m 444 mkdio.h $(DESTDIR)/$(INCDIR)
install.everything: install install.samples install.man
install.samples: $(SAMPLE_PGMS) install
/usr/bin/install -s -m 755 $(SAMPLE_PGMS) $(DESTDIR)/$(BINDIR)
/Users/wolf/Downloads/discount-1.5.4/config.md $(DESTDIR)/$(MANDIR)/man1
/usr/bin/install -m 444 theme.1 $(DESTDIR)/$(MANDIR)/man1
install.man:
/Users/wolf/Downloads/discount-1.5.4/config.md $(DESTDIR)/$(MANDIR)/man3
/usr/bin/install -m 444 mkd-functions.3 markdown.3 mkd-line.3 $(DESTDIR)/$(MANDIR)/man3
for x in mkd_line mkd_generateline; do \
( echo '.\"' ; echo ".so man3/mkd-line.3" ) > $(DESTDIR)/$(MANDIR)/man3/$$x.3;\
done
for x in mkd_in mkd_string; do \
( echo '.\"' ; echo ".so man3/markdown.3" ) > $(DESTDIR)/$(MANDIR)/man3/$$x.3;\
done
for x in mkd_compile mkd_css mkd_generatecss mkd_generatehtml mkd_cleanup mkd_doc_title mkd_doc_author mkd_doc_date; do \
( echo '.\"' ; echo ".so man3/mkd-functions.3" ) > $(DESTDIR)/$(MANDIR)/man3/$$x.3; \
done
/Users/wolf/Downloads/discount-1.5.4/config.md $(DESTDIR)/$(MANDIR)/man7
/usr/bin/install -m 444 markdown.7 mkd-extensions.7 $(DESTDIR)/$(MANDIR)/man7
/Users/wolf/Downloads/discount-1.5.4/config.md $(DESTDIR)/$(MANDIR)/man1
/usr/bin/install -m 444 markdown.1 $(DESTDIR)/$(MANDIR)/man1
install.everything: install install.man
version.o: version.c VERSION
$(CC) -DVERSION=\"`cat VERSION`\" -c version.c
markdown: main.o $(MKDLIB)
$(CC) -o markdown main.o -lmarkdown
# example programs
theme: theme.o $(MKDLIB) mkdio.h
$(CC) -o theme theme.o -lmarkdown
mkd2html: mkd2html.o $(MKDLIB) mkdio.h
$(CC) -o mkd2html mkd2html.o -lmarkdown
makepage: makepage.c $(MKDLIB) mkdio.h
$(CC) -o makepage makepage.c -lmarkdown
main.o: main.c mkdio.h config.h
$(CC) -I. -c main.c
$(MKDLIB): $(OBJS)
$(AR) crv $(MKDLIB) $(OBJS)
$(RANLIB) $(MKDLIB)
test: $(PGMS) echo cols
@for x in tests/*.t; do \
sh $$x || exit 1; \
done
cols: tools/cols.c
$(CC) -o cols tools/cols.c
echo: tools/echo.c
$(CC) -o echo tools/echo.c
clean:
rm -f $(PGMS) $(SAMPLE_PGMS) *.o $(MKDLIB)
distclean spotless: clean
rm -f Makefile version.c markdown.1 config.cmd config.sub config.h config.mak config.log config.md
markdown.o: markdown.c config.h cstring.h markdown.h
generate.o: generate.c config.h cstring.h markdown.h
dumptree.o: dumptree.c cstring.h markdown.h
mkdio.o: mkdio.c mkdio.h cstring.h config.h
xmlpage.o: xmlpage.c mkdio.h cstring.h config.h
toc.o: toc.c mkdio.h cstring.h config.h
-96
View File
@@ -1,96 +0,0 @@
CC=@CC@ -I. -L.
AR=@AR@
RANLIB=@RANLIB@
BINDIR=@exedir@
MANDIR=@mandir@
LIBDIR=@libdir@
INCDIR=@prefix@/include
PGMS=markdown
SAMPLE_PGMS=mkd2html makepage
@THEME@SAMPLE_PGMS+= theme
MKDLIB=libmarkdown.a
OBJS=mkdio.o markdown.o dumptree.o generate.o \
resource.o docheader.o version.o toc.o css.o \
xml.o Csio.o xmlpage.o @AMALLOC@
all: $(PGMS) $(SAMPLE_PGMS)
install: $(PGMS)
@INSTALL_PROGRAM@ $(PGMS) $(DESTDIR)/$(BINDIR)
@INSTALL_DATA@ $(MKDLIB) $(DESTDIR)/$(LIBDIR)
@INSTALL_DATA@ mkdio.h $(DESTDIR)/$(INCDIR)
install.everything: install install.samples install.man
install.samples: $(SAMPLE_PGMS) install
@INSTALL_PROGRAM@ $(SAMPLE_PGMS) $(DESTDIR)/$(BINDIR)
@INSTALL_DIR@ $(DESTDIR)/$(MANDIR)/man1
@INSTALL_DATA@ theme.1 $(DESTDIR)/$(MANDIR)/man1
install.man:
@INSTALL_DIR@ $(DESTDIR)/$(MANDIR)/man3
@INSTALL_DATA@ mkd-functions.3 markdown.3 mkd-line.3 $(DESTDIR)/$(MANDIR)/man3
for x in mkd_line mkd_generateline; do \
( echo '.\"' ; echo ".so man3/mkd-line.3" ) > $(DESTDIR)/$(MANDIR)/man3/$$x.3;\
done
for x in mkd_in mkd_string; do \
( echo '.\"' ; echo ".so man3/markdown.3" ) > $(DESTDIR)/$(MANDIR)/man3/$$x.3;\
done
for x in mkd_compile mkd_css mkd_generatecss mkd_generatehtml mkd_cleanup mkd_doc_title mkd_doc_author mkd_doc_date; do \
( echo '.\"' ; echo ".so man3/mkd-functions.3" ) > $(DESTDIR)/$(MANDIR)/man3/$$x.3; \
done
@INSTALL_DIR@ $(DESTDIR)/$(MANDIR)/man7
@INSTALL_DATA@ markdown.7 mkd-extensions.7 $(DESTDIR)/$(MANDIR)/man7
@INSTALL_DIR@ $(DESTDIR)/$(MANDIR)/man1
@INSTALL_DATA@ markdown.1 $(DESTDIR)/$(MANDIR)/man1
install.everything: install install.man
version.o: version.c VERSION
$(CC) -DVERSION=\"`cat VERSION`\" -c version.c
markdown: main.o $(MKDLIB)
$(CC) -o markdown main.o -lmarkdown @LIBS@
# example programs
@THEME@theme: theme.o $(MKDLIB) mkdio.h
@THEME@ $(CC) -o theme theme.o -lmarkdown @LIBS@
mkd2html: mkd2html.o $(MKDLIB) mkdio.h
$(CC) -o mkd2html mkd2html.o -lmarkdown @LIBS@
makepage: makepage.c $(MKDLIB) mkdio.h
$(CC) -o makepage makepage.c -lmarkdown @LIBS@
main.o: main.c mkdio.h config.h
$(CC) -I. -c main.c
$(MKDLIB): $(OBJS)
$(AR) crv $(MKDLIB) $(OBJS)
$(RANLIB) $(MKDLIB)
test: $(PGMS) echo cols
@for x in tests/*.t; do \
sh $$x || exit 1; \
done
cols: tools/cols.c
$(CC) -o cols tools/cols.c
echo: tools/echo.c
$(CC) -o echo tools/echo.c
clean:
rm -f $(PGMS) $(SAMPLE_PGMS) *.o $(MKDLIB)
distclean spotless: clean
rm -f @GENERATED_FILES@ @CONFIGURE_FILES@
markdown.o: markdown.c config.h cstring.h markdown.h
generate.o: generate.c config.h cstring.h markdown.h
dumptree.o: dumptree.c cstring.h markdown.h
mkdio.o: mkdio.c mkdio.h cstring.h config.h
xmlpage.o: xmlpage.c mkdio.h cstring.h config.h
toc.o: toc.c mkdio.h cstring.h config.h
-40
View File
@@ -1,40 +0,0 @@
% Discount on Plan 9
% Josh Wood
% 2009-06-12
# *Discount* Markdown compiler on Plan 9
## Build
% CONFIG='--enable-all-features' mk config
% mk install
% markdown -V
markdown: discount X.Y.Z DL_TAG HEADER DEBUG SUPERSCRIPT RELAXED DIV
`--enable-all-features` may be replaced by zero or more of:
--enable-dl-tag Use the DL tag extension
--enable-pandoc-header Use pandoc-style header blocks
--enable-superscript A^B becomes A<sup>B</sup>
--enable-amalloc Enable memory allocation debugging
--relaxed-emphasis underscores aren't special in the middle of words
--with-tabstops=N Set tabstops to N characters (default is 4)
--enable-div Enable >%id% divisions
--enable-alpha-list Enable (a)/(b)/(c) lists
--enable-all-features Turn on all stable optional features
## Notes
The supplied mkfile merely drives Discount's own configure script and
then APE's *psh* environment to build the Discount source, then copies
the result(s) to locations appropriate for system-wide use on Plan 9.
There are a few other *mk*(1) targets:
`install.libs`: Discount includes a C library and header.
Installation is optional. Plan 9 binaries are statically linked.
`install.man`: Add manual pages for markdown(1) and (6).
`install.progs`: Extra programs. *makepage* writes complete XHTML
documents, rather than fragments. *mkd2html* is similar, but produces
HTML.
-169
View File
@@ -1,169 +0,0 @@
.TH MARKDOWN 1
.SH NAME
markdown \- convert Markdown text to HTML
.SH SYNOPSIS
.B markdown
[
.B -dTV
]
[
.BI -b " url-base
]
[
.BI -F " bitmap
]
[
.BI -f " flags
]
[
.BI -o " ofile
]
[
.BI -s " text
]
[
.BI -t " text
]
[
.I file
]
.SH DESCRIPTION
The
.I markdown
utility reads the
.IR Markdown (6)-formatted
.I file
(or standard input) and writes its
.SM HTML
fragment representation on standard output.
.PP
The options are:
.TF dfdoptions
.TP
.BI -b " url-base
Links in source begining with
.B /
will be prefixed with
.I url-base
in the output.
.TP
.B -d
Instead of printing an
.SM HTML
fragment, print a parse tree.
.TP
.BI -F " bitmap
Set translation flags.
.I Bitmap
is a bit map of the various configuration options described in
.IR markdown (2).
.TP
.BI -f " flags
Set or clear various translation
.IR flags ,
described below.
.I Flags
are in a comma-delimited list, with an optional
.B +
(set) prefix on each flag.
.TP
.BI -o " ofile
Write the generated
.SM HTML
to
.IR ofile .
.TP
.BI -s " text
Use the
.IR markdown (2)
function to format the
.I text
on standard input.
.TP
.B -T
Under
.B -f
.BR toc ,
print the table of contents as an unordered list before the usual
.SM HTML
output.
.TP
.BI -t " text
Use
.IR mkd_text
(in
.IR markdown (2))
to format
.I text
instead of processing standard input with
.IR markdown .
.TP
.B -V
Show version number and configuration. If the version includes the string
.BR DL_TAG ,
.I markdown
was configured with definition list support. If the version includes the string
.BR HEADER ,
.I markdown
was configured to support pandoc header blocks.
.PD
.SS TRANSLATION FLAGS
The translation flags understood by
.B -f
are:
.TF \ noheader
.TP
.B noimage
Don't allow image tags.
.TP
.B nolinks
Don't allow links.
.TP
.B nohtml
Don't allow any embedded HTML.
.TP
.B cdata
Generate valid XML output.
.TP
.B noheader
Do not process pandoc headers.
.TP
.B notables
Do not process the syntax extension for tables.
.TP
.B tabstops
Use Markdown-standard 4-space tabstops.
.TP
.B strict
Disable superscript and relaxed emphasis.
.TP
.B relax
Enable superscript and relaxed emphasis (the default).
.TP
.B toc
Enable table of contents support, generated from headings (in
.IR markdown (6))
in the source.
.TP
.B 1.0
Revert to Markdown 1.0 compatibility.
.PD
.PP
For example,
.B -f nolinks,quot
tells
.I markdown
not to allow
.B <a>
tags, and to expand double quotes.
.SH SOURCE
.B /sys/src/cmd/discount
.SH SEE ALSO
.IR markdown (2),
.IR markdown (6)
.PP
http://daringfireball.net/projects/markdown/,
``Markdown''.
.SH DIAGNOSTICS
.I Markdown
exits 0 on success and >0 if an error occurs.
-332
View File
@@ -1,332 +0,0 @@
.TH MARKDOWN 2
.SH NAME
mkd_in, mkd_string, markdown, mkd_compile, mkd_css, mkd_generatecss,
mkd_document, mkd_generatehtml, mkd_xhtmlpage, mkd_toc, mkd_generatetoc,
mkd_cleanup, mkd_doc_title, mkd_doc_author, mkd_doc_date, mkd_line,
mkd_generateline \- convert Markdown text to HTML
.SH SYNOPSIS
.ta \w'MMIOT* 'u
.B #include <mkdio.h>
.PP
.B
MMIOT* mkd_in(FILE *input)
.PP
.B
MMIOT* mkd_string(char *string, int size)
.PP
.B
int markdown(MMIOT *doc, FILE *output, int flags)
.PP
.B
int mkd_compile(MMIOT *document, int flags)
.PP
.B
int mkd_css(MMIOT *document, char **doc)
.PP
.B
int mkd_generatecss(MMIOT *document, FILE *output)
.PP
.B
int mkd_document(MMIOT *document, char **doc)
.PP
.B
int mkd_generatehtml(MMIOT *document, FILE *output)
.PP
.B
int mkd_xhtmlpage(MMIOT *document, int flags, FILE *output)
.PP
.B
int mkd_toc(MMIOT *document, char **doc)
.PP
.B
void mkd_generatetoc(MMIOT *document, FILE *output)
.PP
.B
void mkd_cleanup(MMIOT*);
.PP
.B
char* mkd_doc_title(MMIOT*)
.PP
.B
char* mkd_doc_author(MMIOT*)
.PP
.B
char* mkd_doc_date(MMIOT*)
.PP
.B
int mkd_line(char *string, int size, char **doc, int flags)
.PP
.B
int mkd_generateline(char *string, int size, FILE *output, int flags)
.PD
.PP
.SH DESCRIPTION
These functions convert
.IR Markdown (6)
text into
.SM HTML
markup.
.PP
.I Mkd_in
reads the text referenced by pointer to
.B FILE
.I input
and returns a pointer to an
.B MMIOT
structure of the form expected by
.I markdown
and the other converters.
.I Mkd_string
accepts one
.I string
and returns a pointer to
.BR MMIOT .
.PP
After such preparation,
.I markdown
converts
.I doc
and writes the result to
.IR output ,
while
.I mkd_compile
transforms
.I document
in-place.
.PP
One or more of the following
.I flags
(combined with
.BR OR )
control
.IR markdown 's
processing of
.IR doc :
.TF MKD_NOIMAGE
.TP
.B MKD_NOIMAGE
Do not process
.B ![]
and remove
.B <img>
tags from the output.
.TP
.B MKD_NOLINKS
Do not process
.B []
and remove
.B <a>
tags from the output.
.TP
.B MKD_NOPANTS
Suppress Smartypants-style replacement of quotes, dashes, or ellipses.
.TP
.B MKD_STRICT
Disable superscript and relaxed emphasis processing if configured; otherwise a no-op.
.TP
.B MKD_TAGTEXT
Process as inside an
.SM HTML
tag: no
.BR <em> ,
no
.BR <bold> ,
no
.SM HTML
or
.B []
expansion.
.TP
.B MKD_NO_EXT
Don't process pseudo-protocols (in
.IR markdown (6)).
.TP
.B MKD_CDATA
Generate code for
.SM XML
.B ![CDATA[...]]
element.
.TP
.B MKD_NOHEADER
Don't process Pandoc-style headers.
.TP
.B MKD_TABSTOP
When reading documents, expand tabs to 4 spaces, overriding any compile-time configuration.
.TP
.B MKD_TOC
Label headings for use with the
.I mkd_generatetoc
and
.I mkd_toc
functions.
.TP
.B MKD_1_COMPAT
MarkdownTest_1.0 compatibility. Trim trailing spaces from first line of code blocks and disable implicit reference links (in
.IR markdown (6)).
.TP
.B MKD_AUTOLINK
Greedy
.SM URL
generation. When set, any
.SM URL
is converted to a hyperlink, even those not encased in
.BR <> .
.TP
.B MKD_SAFELINK
Don't make hyperlinks from
.B [][]
links that have unknown
.SM URL
protocol types.
.TP
.B MKD_NOTABLES
Do not process the syntax extension for tables (in
.IR markdown (6)).
.TP
.B MKD_EMBED
All of
.BR MKD_NOLINKS ,
.BR MKD_NOIMAGE ,
and
.BR MKD_TAGTEXT .
.PD
.PP
This implementation supports
Pandoc-style
headers and inline
.SM CSS
.B <style>
blocks, but
.I markdown
does not access the data provided by these extensions.
The following functions do, and allow other manipulations.
.PP
Given a pointer to
.B MMIOT
prepared by
.I mkd_in
or
.IR mkd_string ,
.I mkd_compile
compiles the
.I document
into
.BR <style> ,
Pandoc, and
.SM HTML
sections. It accepts the
.I flags
described for
.IR markdown ,
above.
.PP
Once compiled, the document particulars can be read and written:
.PP
.I Mkd_css
allocates a string and populates it with any
.B <style>
sections from the document.
.I Mkd_generatecss
writes any
.B <style>
sections to
.IR output .
.PP
.I Mkd_document
points
.I doc
to the
.B MMIOT
.IR document ,
returning
.IR document 's
size.
.PP
.I Mkd_generatehtml
writes the rest of the
.I document
to the
.IR output .
.PP
.IR Mkd_doc_title ,
.IR mkd_doc_author ,
and
.I mkd_doc_date
read the contents of any Pandoc header.
.PP
.I Mkd_xhtmlpage
writes an
.SM XHTML
page representation of the document.
It accepts the
.I flags
described for
.IR markdown ,
above.
.PP
.I Mkd_toc
.IR malloc s
a buffer into which it writes an outline, in the form of a
.B <ul>
element populated with
.BR <li> s
each containing a link to successive headings in the
.IR document .
It returns the size of that string.
.I Mkd_generatetoc
is similar,
but writes the outline to the
.I output
referenced by a pointer to
.BR FILE .
.PP
.I Mkd_cleanup
deletes a processed
.BR MMIOT .
.PP
The last two functions convert a single line of markdown source, for example a page title or a signature.
.I Mkd_line
allocates a buffer into which it writes an
.SM HTML
fragment representation of the
.IR string .
.I Mkd_generateline
writes the result to
.IR output .
.SH SOURCE
.B /sys/src/cmd/discount
.SH SEE ALSO
.IR markdown (1),
.IR markdown (6)
.SH DIAGNOSTICS
The
.I mkd_in
and
.I mkd_string
functions return a pointer to
.B MMIOT
on success, null on failure.
.IR Markdown ,
.IR mkd_compile ,
.IR mkd_style ,
and
.I mkd_generatehtml
return
.B 0
on success,
.B -1
otherwise.
.SH BUGS
Error handling is minimal at best.
.PP
The
.B MMIOT
created by
.I mkd_string
is deleted by the
.I markdown
function.
.PP
This is an
.SM APE
library.
-543
View File
@@ -1,543 +0,0 @@
.TH MARKDOWN 6
.SH NAME
Markdown \- text formatting syntax
.SH DESCRIPTION
Markdown
is a text markup syntax for machine conversion to
the more complex
.SM HTML
or
.SM XHTML
markup languages.
It is intended to be easy to read and to write, with
emphasis on readability.
A Markdown-formatted document should be publishable as-is,
in plain text, without the formatting distracting the reader.
.PP
The biggest source of inspiration for Markdown's
syntax is the format of plain text email. The markup is comprised entirely
of punctuation characters, chosen so as to look like what they mean.
Asterisks around a word look like
.IR *emphasis* .
Markdown lists look like lists. Even
blockquotes look like quoted passages of text, assuming the reader has
used email.
.PP
.SS Block Elements
.TF W
.PD
.TP
Paragraphs and Line Breaks
A paragraph is one or more consecutive lines of text, separated
by one or more blank lines. (A blank line is any line that looks like a
blank line -- a line containing nothing but spaces or tabs is considered
blank.) Normal paragraphs should not be indented with spaces or tabs.
.IP
Lines may be freely broken for readability; Markdown
does not translate source line breaks to
.B <br />
tags. To request generation of
.B <br />
in the output, end a line with two or more spaces, then a newline.
.TP
Headings
Headings can be marked in two ways, called
.I setext
and
.IR atx .
.IP
Setext-style headings are
``underlined'' using equal signs (for first-level
headings) and dashes (for second-level headings).
.IP
Atx-style headings use 1-6 hash characters at the start of the line,
corresponding to
.SM HTML
.BR <h^(1-6)^> .
Optional closing hashes may follow
the heading text.
.TP
Blockquotes
Lines beginning with
.B >
are output in blockquotes.
Blockquotes can be nested
by multiple levels of
.BR >> .
Blockquotes can contain other Markdown elements, including
headings, lists, and code blocks.
.TP
Lists
Markdown supports ordered (numbered) and unordered (bulleted) lists.
List markers typically start at the left margin, but may be indented by
up to three spaces.
List markers must be followed by one or more spaces
or a tab, then the list item text.
A newline terminates each list item.
.IP
Unordered lists use asterisks, pluses, and hyphens interchangeably as
list markers.
.IP
Ordered lists use integers followed by periods as list markers.
The order of the integers is not interpreted,
but the list should begin with
.BR 1 .
.IP
If list items are separated by blank lines, Markdown will wrap each list
item in
.B <p>
tags in the
.SM HTML
output.
.IP
List items may consist of multiple paragraphs.
Each subsequent
paragraph within a list item must be indented by either 4 spaces
or one tab.
To put a blockquote within a list item, the blockquote's
.B >
marker needs to be indented.
To put a code block within a list item, the code block needs
to be indented
.I twice
-- 8 spaces or two tabs.
.TP
Code Blocks
To produce a code block, indent every line of the
block by at least 4 spaces or 1 tab.
A code block continues until it reaches a line that is not indented.
.IP
Rather than forming normal paragraphs, the lines
of a code block are interpreted literally.
Regular Markdown syntax is not processed within code blocks.
Markdown wraps a code block in both
.B <pre>
and
.B <code>
tags.
One level of indentation -- 4
spaces or 1 tab -- is removed from each line of the code block in
the output.
.TP
Horizontal Rules
Produce a horizontal rule tag
.RB ( <hr\ /> )
by placing three or
more hyphens, asterisks, or underscores on a line by themselves.
.SS Span Elements
.TF W
.PD
.TP
Links
Markdown supports two styles of links:
.I inline
and
.IR reference .
In both styles, the link text is delimited by square brackets
.RB ( [] ).
To create an inline link, use a set of regular parentheses immediately
after the link text's closing square bracket.
Inside the parentheses,
put the link URL, along with an optional
title for the link surrounded in double quotes.
For example:
.IP
.EX
An [example](http://example.com/ "Title") inline link.
.EE
.IP
Reference-style links use a second set of square brackets, inside
which you place a label of your choosing to identify the link:
.IP
.EX
An [example][id] reference-style link.
.EE
.IP
The label is then assigned a value on its own line, anywhere in the document:
.IP
.EX
[id]: http://example.com/ "Optional Title"
.EE
.IP
Link label names may consist of letters, numbers, spaces, and
punctuation.
Labels are not case sensitive.
An empty label bracket
set after a reference-style link implies the link label is equivalent to
the link text.
A URL value can then be assigned to the link by referencing
the link text as the label name.
.TP
Emphasis
Markdown treats asterisks
.RB ( * )
and underscores
.RB ( _ )
as indicators of emphasis.
Text surrounded with single asterisks or underscores
will be wrapped with an
.SM HTML
.B <em>
tag.
Double asterisks or underscores generate an
.SM HTML
.B <strong>
tag.
.TP
Code
To indicate a span of code, wrap it with backtick quotes
.RB ( ` ).
Unlike a code block, a code span indicates code within a
normal paragraph.
To include a literal backtick character within a code span, you can use
multiple backticks as the opening and closing delimiters:
.IP
.EX
``There is a literal backtick (`) here.``
.EE
.TP
Images
Markdown image syntax is intended to resemble that
for links, allowing for two styles, once again
.I inline
and
.IR reference .
The syntax is as for each respective style of link, described above, but
prefixed with an exclamation mark character
.RB ( ! ).
Inline image syntax looks like this:
.IP
.EX
![Alt text](/path/to/img.jpg "Optional title")
.EE
.IP
That is:
An exclamation mark;
followed by a set of square brackets containing the `alt'
attribute text for the image;
followed by a set of parentheses containing the URL or path to
the image, and an optional `title' attribute enclosed in double
or single quotes.
.IP
Reference-style image syntax looks like this:
.IP
.EX
![Alt text][id]
.EE
.IP
Where
.I id
is a label used as for reference-style URL links, described above.
.SS Convenience
.TF W
.PD
.TP
Automatic Links
There is a shortcut style for creating ``automatic''
links for URLs and email addresses.
Surround the URL
or address with angle brackets.
.TP
Backslash Escapes
Use backslash escapes to generate literal
characters which would otherwise have special meaning in Markdown's
formatting syntax.
.TP
Inline HTML
For markup that is not covered by Markdown's
syntax, simply use the
.SM HTML
directly.
The only restrictions are that block-level
.SM HTML
elements --
.BR <div> ,
.BR <table> ,
.BR <pre> ,
.BR <p> ,
etc. -- must be separated from surrounding
content by blank lines, and the start and end tags of the block should
not be indented with tabs or spaces. Markdown formatting syntax is
not processed within block-level
.SM HTML
tags.
.IP
Span-level
.SM HTML
tags -- e.g.
.BR <span> ,
.BR <cite> ,
or
.B <del>
-- can be
used anywhere in a Markdown
paragraph, list item, or heading.
It is permitted to use
.SM HTML
tags instead of Markdown formatting; e.g.
.SM HTML
.B <a>
or
.B <img>
tags instead of Markdown's
link or image syntax.
Unlike block-level
.SM HTML
tags, Markdown
syntax
.I is
processed within the elements of span-level tags.
.TP
Automatic Special Character Escapes
To be displayed literally in a user agent, the characters
.B <
and
.B &
must appear as escaped entities in
.SM HTML
source, e.g.
.B &lt;
and
.BR &amp; .
Markdown
allows natural use of these characters, taking care of
the necessary escaping.
The ampersand part of a directly-used
.SM HTML
entity remains unchanged; otherwise it will be translated
into
.BR &amp; .
Inside code spans and blocks, angle brackets and
ampersands are always encoded automatically.
This makes it easy to use Markdown to write about
.SM HTML
code.
.PP
.SS Smarty Pants
The
.IR markdown (1)
utility transforms a few plain text symbols into their typographically-fancier
.SM HTML
entity equivalents.
These are extensions to the standard Markdown syntax.
.TF W
.PD
.TP
Punctuation
Input single- and double-quotes are transformed
into ``curly'' quote entities in the output (e.g.,
.B 'text'
becomes
.BR &lsquo;text&rsquo; ).
Input double-dashes
.RB ( -- )
and triple-dashes become en- and em-dashes, respectively,
while a series of three dots
.RB ( ... )
in the input becomes an ellipsis entity
.RB ( &hellip; )
in the
.SM HTML
output.
.TP
Symbols
Three other transformations replace the common plain-text shorthands
.BR (c) ,
.BR (r) ,
and
.BR (tm)
from the input with their respective
.SM HTML
entities. (As in
.B (c)
becoming
.BR &copy; ,
the Copyright symbol entity.)
.TP
Fractions
A small set of plain-text shorthands for fractions is recognized.
.B 1/4
becomes
.BR &frac14; ,
for example. These fraction notations are replaced with their
.SM HTML
entity equivalents:
.BR 1/4 ,
.BR 1/2 ,
.BR 3/4 .
.B 1/4th
and
.B 3/4ths
are replaced with their entity and the indicated ordinal suffix letters.
.PP
Like the basic Markdown syntax, none of the ``Smarty Pants'' extensions are processed
inside code blocks or spans.
.PP
.SS Discount Extensions
.IR Markdown (1)
recognizes some extensions to the Markdown format,
many of them adopted or adapted from other Markdown
interpreters or document formatting systems.
.TF W
.PD
.TP
Pandoc Headers
If
.I markdown
was configured with
.BR --enable-pandoc-header ,
the markdown source can have a 3-line Pandoc header in the format of
.IP
.EX
% Title
% Author
% Date
.EE
.IP
whose data is available to the
.IR mkd_doc_title ,
.IR mkd_doc_author ,
and
.I mkd_doc_date
(in
.IR markdown (2))
functions.
.TP
Embedded Stylesheets
Stylesheets may be defined and modified in a
.B <style>
block. A style block is parsed like any other block-level
.SM HTML;
.B <style>
starting on column 1, raw
.SM HTML
(or, in this case,
.SM CSS \)
following it, and either ending with a
.B </style>
at the end of the line or at the beginning of a subsequent line.
.IP
Style blocks apply to the entire document regardless of where they are defined.
.TP
Image Dimensions
Image specification has been extended with an argument describing image dimensions:
.BI = height x width.
For an image 400 pixels high and 300 wide, the new syntax is:
.IP
.EX
![Alt text](/path/to/image.jpg =400x300 "Title")
.EE
.TP
Pseudo-Protocols
Pseudo-protocols that may replace the common
.B http:
or
.B mailto:
have been added to the link syntax described above.
.IP
.BR abbr :
Text following is used as the
.B title
attribute of an
.B abbr
tag wrapping the link text. So
.B [LT](abbr:Link Text)
gives
.B <abbr title="Link Text">LT</abbr>.
.IP
.BR id :
The link text is marked up and written to the output, wrapped with
.B <a id=text following>
and
.BR </a> .
.IP
.BR class :
The link text is marked up and written to the output, wrapped with
.B <span class=text following>
and
.BR </span> .
.IP
.BR raw :
Text following is written to the output with no further processing.
The link text is discarded.
.TP
Alphabetic Lists
If
.I markdown
was configured with
.BR --enable-alpha-list ,
.IP
.EX
a. this
b. is
c. an alphabetic
d. list
.EE
.IP
yields an
.SM HTML
.B ol
ordered list.
.TP
Definition Lists
If configured with
.BR --enable-dl-tag ,
markup for definition lists is enabled. A definition list item is defined as
.IP
.EX
=term=
definition
.EE
.TP
Tables
Tables are specified with a pipe
.RB ( | )
and dash
.RB ( - )
marking. The markdown text
.IP
.EX
header0|header1
-------|-------
textA|textB
textC|textD
.EE
.IP
will produce an
.SM HTML
.B table
of two columns and three rows.
A header row is designated by ``underlining'' with dashes.
Declare a column's alignment by affixing a colon
.RB ( : )
to the left or right end of the dashes underlining its header.
In the output, this
yields the corresponding value for the
.B align
attribute on each
.B td
cell in the column.
A colon at both ends of a column's header dashes indicates center alignment.
.TP
Relaxed Emphasis
If configured with
.BR --relaxed-emphasis ,
the rules for emphasis are changed so that a single
.B _
will not count as an emphasis character in the middle of a word.
This is useful for documenting some code where
.B _
appears frequently, and would normally require a backslash escape.
.PD
.SH SEE ALSO
.IR markdown (1),
.IR markdown (2)
.PP
http://daringfireball.net/projects/markdown/syntax/,
``Markdown: Syntax''.
.PP
http://daringfireball.net/projects/smartypants/,
``Smarty Pants''.
.PP
http://michelf.com/projects/php-markdown/extra/#table,
``PHP Markdown Extra: Tables''.
-37
View File
@@ -1,37 +0,0 @@
BIN=/$objtype/bin
CC='cc -D_BSD_EXTENSION'
markdown:
ape/psh -c 'cd .. && make'
none:V: markdown
test: markdown
ape/psh -c 'cd ..&& make test'
install: markdown
cp ../markdown $BIN/markdown
install.progs: install
cp ../makepage $BIN/makepage
cp ../mkd2html $BIN/mkd2html
install.libs: install
cp ../mkdio.h /sys/include/ape/mkdio.h
cp ../libmarkdown.a /$objtype/lib/ape/libmarkdown.a
install.man: install
cp markdown.1 /sys/man/1/markdown
cp markdown.2 /sys/man/2/markdown
cp markdown.6 /sys/man/6/markdown
installall:V: install.libs install.man install.progs
config:
ape/psh -c 'cd .. && ./configure.sh $CONFIG'
clean:
ape/psh -c 'cd .. && make clean'
nuke:
ape/psh -c 'cd .. && make distclean'
-16
View File
@@ -1,16 +0,0 @@
DISCOUNT is a implementation of John Gruber's Markdown markup
language. It implements, as far as I can tell, all of the
language as described in
<http://daringfireball.net/projects/markdown/syntax>
and passes the Markdown test suite at
<http://daringfireball.net/projects/downloads/MarkdownTest_1.0.zip>
DISCOUNT is free software written by David Parsons <orc@pell.chi.il.us>;
it is released under a BSD-style license that allows you to do
as you wish with it as long as you don't attempt to claim it as
your own work.
Most of the programs included in the DISCOUNT distribution have
manual pages describing how they work.
The file INSTALL describes how to build and install discount
-1
View File
@@ -1 +0,0 @@
1.5.4
-111
View File
@@ -1,111 +0,0 @@
/*
* debugging malloc()/realloc()/calloc()/free() that attempts
* to keep track of just what's been allocated today.
*/
#include <stdio.h>
#include <stdlib.h>
#define MAGIC 0x1f2e3d4c
struct alist { int magic, size; struct alist *next, *last; };
static struct alist list = { 0, 0, 0, 0 };
static int mallocs=0;
static int reallocs=0;
static int frees=0;
void *
acalloc(int size, int count)
{
struct alist *ret = calloc(size + sizeof(struct alist), count);
if ( ret ) {
ret->magic = MAGIC;
ret->size = size * count;
if ( list.next ) {
ret->next = list.next;
ret->last = &list;
ret->next->last = ret;
list.next = ret;
}
else {
ret->last = ret->next = &list;
list.next = list.last = ret;
}
++mallocs;
return ret+1;
}
return 0;
}
void*
amalloc(int size)
{
return acalloc(size,1);
}
void
afree(void *ptr)
{
struct alist *p2 = ((struct alist*)ptr)-1;
if ( p2->magic == MAGIC ) {
p2->last->next = p2->next;
p2->next->last = p2->last;
++frees;
free(p2);
}
else
free(ptr);
}
void *
arealloc(void *ptr, int size)
{
struct alist *p2 = ((struct alist*)ptr)-1;
struct alist save;
if ( p2->magic == MAGIC ) {
save.next = p2->next;
save.last = p2->last;
p2 = realloc(p2, sizeof(*p2) + size);
if ( p2 ) {
p2->size = size;
p2->next->last = p2;
p2->last->next = p2;
++reallocs;
return p2+1;
}
else {
save.next->last = save.last;
save.last->next = save.next;
return 0;
}
}
return realloc(ptr, size);
}
void
adump()
{
struct alist *p;
for ( p = list.next; p && (p != &list); p = p->next ) {
fprintf(stderr, "allocated: %d byte%s\n", p->size, (p->size==1) ? "" : "s");
fprintf(stderr, " [%.*s]\n", p->size, p+1);
}
if ( getenv("AMALLOC_STATISTICS") ) {
fprintf(stderr, "%d malloc%s\n", mallocs, (mallocs==1)?"":"s");
fprintf(stderr, "%d realloc%s\n", reallocs, (reallocs==1)?"":"s");
fprintf(stderr, "%d free%s\n", frees, (frees==1)?"":"s");
}
}
-29
View File
@@ -1,29 +0,0 @@
/*
* debugging malloc()/realloc()/calloc()/free() that attempts
* to keep track of just what's been allocated today.
*/
#ifndef AMALLOC_D
#define AMALLOC_D
#include "config.h"
#ifdef USE_AMALLOC
extern void *amalloc(int);
extern void *acalloc(int,int);
extern void *arealloc(void*,int);
extern void afree(void*);
extern void adump();
#define malloc amalloc
#define calloc acalloc
#define realloc arealloc
#define free afree
#else
#define adump() (void)1
#endif
#endif/*AMALLOC_D*/
-2
View File
@@ -1,2 +0,0 @@
#! /bin/sh
configure.sh
-25
View File
@@ -1,25 +0,0 @@
/*
* configuration for markdown, generated Sun Sep 13 13:13:06 CDT 2009
* by wolf@wolf-mbp.local
*/
#ifndef __AC_MARKDOWN_D
#define __AC_MARKDOWN_D 1
#define OS_DARWIN 1
#define DWORD unsigned int
#define WORD unsigned short
#define BYTE unsigned char
#define HAVE_PWD_H 1
#define HAVE_GETPWUID 1
#define HAVE_SRANDOM 1
#define INITRNG(x) srandom((unsigned int)x)
#define HAVE_RANDOM 1
#define COINTOSS() (random()&1)
#define HAVE_STRCASECMP 1
#define HAVE_STRNCASECMP 1
#define HAVE_FCHDIR 1
#define TABSTOP 4
#define PATH_SED "/usr/bin/sed"
#endif/* __AC_MARKDOWN_D */
-35
View File
@@ -1,35 +0,0 @@
[echo ...Configuring for [markdown]
Looking for cpp
CPP=[/usr/bin/cpp], CPPFLAGS=[]
looking for install
(/usr/bin/install)
checking out the C compiler
checking for "volatile" keyword
checking for "const" keyword
defining WORD & DWORD scalar types
/tmp/pd717.c: In function main:
/tmp/pd717.c:13: warning: incompatible implicit declaration of built-in function exit
/tmp/ngc717.c: In function main:
/tmp/ngc717.c:5: warning: initialization makes pointer from integer without a cast
/tmp/ngc717.c:6: warning: initialization makes pointer from integer without a cast
./configure.inc: line 1058: 857 Segmentation fault /tmp/ngc$$
looking for header pwd.h
looking for the getpwuid function
looking for the srandom function
looking for the random function
looking for the strcasecmp function
looking for the strncasecmp function
looking for the fchdir function
looking for header malloc.h
test failed: command was cc -c -o /tmp/doto717.o /tmp/ngc717.c
output:
/tmp/ngc717.c:2:20: error: malloc.h: No such file or directory
offending sources:
/tmp/ngc717.c:
/* AC_CHECK_HEADERS */
#include <malloc.h>
main() { }
sed is /usr/bin/sed
generating Makefile
generating version.c
generating markdown.1
-1
View File
@@ -1 +0,0 @@
HAVE_SED = 1
-5
View File
@@ -1,5 +0,0 @@
#! /bin/sh
# script generated Sun Sep 13 13:13:07 CDT 2009 by configure.sh
test -d "$1" || mkdir -p "$1"
exit 0
-27
View File
@@ -1,27 +0,0 @@
s;@CPP@;/usr/bin/cpp;g
s;@CPPFLAGS@;;g
s;@INSTALL@;/usr/bin/install;g
s;@INSTALL_PROGRAM@;/usr/bin/install -s -m 755;g
s;@INSTALL_DATA@;/usr/bin/install -m 444;g
s;@INSTALL_DIR@;/Users/wolf/Downloads/discount-1.5.4/config.md;g
s;@CC@;cc;g
s;@AR@;/usr/bin/ar;g
s;@RANLIB@;/usr/bin/ranlib;g
s;@THEME@;;g
s;@TABSTOP@;4;g
s;@AMALLOC@;;g
s;@STRICT@;.\";g
s;@LIBS@;;g
s;@CONFIGURE_FILES@;config.cmd config.sub config.h config.mak config.log config.md;g
s;@GENERATED_FILES@;Makefile version.c markdown.1;g
s;@CFLAGS@;-g;g
s;@LDFLAGS@;-g;g
s;@srcdir@;/Users/wolf/Downloads/discount-1.5.4;g
s;@prefix@;/usr/local;g
s;@exedir@;/usr/local/bin;g
s;@sbindir@;/usr/local/sbin;g
s;@libdir@;/usr/local/lib;g
s;@libexec@;/usr/local/lib;g
s;@confdir@;/etc;g
s;@mandir@;/usr/local/man;g
s;@SED@;/usr/bin/sed;g
File diff suppressed because it is too large Load Diff
-144
View File
@@ -1,144 +0,0 @@
#! /bin/sh
# local options: ac_help is the help message that describes them
# and LOCAL_AC_OPTIONS is the script that interprets them. LOCAL_AC_OPTIONS
# is a script that's processed with eval, so you need to be very careful to
# make certain that what you quote is what you want to quote.
# load in the configuration file
#
ac_help='--enable-dl-tag Use the DL tag extension
--enable-pandoc-header Use pandoc-style header blocks
--enable-superscript A^B becomes A<sup>B</sup>
--enable-amalloc Enable memory allocation debugging
--relaxed-emphasis underscores aren'\''t special in the middle of words
--with-tabstops=N Set tabstops to N characters (default is 4)
--enable-div Enable >%id% divisions
--enable-alpha-list Enable (a)/(b)/(c) lists
--enable-all-features Turn on all stable optional features'
LOCAL_AC_OPTIONS='
set=`locals $*`;
if [ "$set" ]; then
eval $set
shift 1
else
ac_error=T;
fi'
locals() {
K=`echo $1 | $AC_UPPERCASE`
case "$K" in
--RELAXED-EMPHAS*)
echo RELAXED_EMPHASIS=T
;;
--ENABLE-ALL|--ENABLE-ALL-FEATURES)
echo WITH_DL_TAG=T
echo RELAXED_EMPHASIS=T
echo WITH_PANDOC_HEADER=T
echo WITH_SUPERSCRIPT=T
echo WITH_AMALLOC=T
echo WITH_DIV=T
#echo WITH_ALPHA_LIST=T
;;
--ENABLE-*) enable=`echo $K | sed -e 's/--ENABLE-//' | tr '-' '_'`
echo WITH_${enable}=T ;;
esac
}
TARGET=markdown
. ./configure.inc
AC_INIT $TARGET
AC_PROG_CC
case "$AC_CC $AC_CFLAGS" in
*-Wall*) AC_DEFINE 'while(x)' 'while( (x) != 0 )'
AC_DEFINE 'if(x)' 'if( (x) != 0 )' ;;
esac
AC_PROG ar || AC_FAIL "$TARGET requires ar"
AC_PROG ranlib
AC_C_VOLATILE
AC_C_CONST
AC_SCALAR_TYPES
AC_CHECK_BASENAME
AC_CHECK_HEADERS sys/types.h pwd.h && AC_CHECK_FUNCS getpwuid
if AC_CHECK_FUNCS srandom; then
AC_DEFINE 'INITRNG(x)' 'srandom((unsigned int)x)'
elif AC_CHECK_FUNCS srand; then
AC_DEFINE 'INITRNG(x)' 'srand((unsigned int)x)'
else
AC_DEFINE 'INITRNG(x)' '(void)1'
fi
if AC_CHECK_FUNCS random; then
AC_DEFINE 'COINTOSS()' '(random()&1)'
elif AC_CHECK_FUNCS rand; then
AC_DEFINE 'COINTOSS()' '(rand()&1)'
else
AC_DEFINE 'COINTOSS()' '1'
fi
if AC_CHECK_FUNCS strcasecmp; then
:
elif AC_CHECK_FUNCS stricmp; then
AC_DEFINE strcasecmp stricmp
else
AC_FAIL "$TARGET requires either strcasecmp() or stricmp()"
fi
if AC_CHECK_FUNCS strncasecmp; then
:
elif AC_CHECK_FUNCS strnicmp; then
AC_DEFINE strncasecmp strnicmp
else
AC_FAIL "$TARGET requires either strncasecmp() or strnicmp()"
fi
if AC_CHECK_FUNCS fchdir || AC_CHECK_FUNCS getcwd ; then
AC_SUB 'THEME' ''
else
AC_SUB 'THEME' '#'
fi
if [ -z "$WITH_TABSTOPS" ]; then
TABSTOP=4
elif [ "$WITH_TABSTOPS" -eq 1 ]; then
TABSTOP=8
else
TABSTOP=$WITH_TABSTOPS
fi
AC_DEFINE 'TABSTOP' $TABSTOP
AC_SUB 'TABSTOP' $TABSTOP
test -z "$WITH_SUPERSCRIPT" || AC_DEFINE 'SUPERSCRIPT' 1
test -z "$RELAXED_EMPHASIS" || AC_DEFINE 'RELAXED_EMPHASIS' 1
test -z "$WITH_DIV" || AC_DEFINE 'DIV_QUOTE' 1
test -z "$WITH_ALPHA_LIST" || AC_DEFINE 'ALPHA_LIST' 1
if [ "$WITH_AMALLOC" ]; then
AC_DEFINE 'USE_AMALLOC' 1
AC_SUB 'AMALLOC' 'amalloc.o'
else
AC_SUB 'AMALLOC' ''
fi
if [ "$RELAXED_EMPHASIS" -o "$WITH_SUPERSCRIPT" ]; then
AC_SUB 'STRICT' ''
else
AC_SUB 'STRICT' '.\"'
fi
[ "$OS_FREEBSD" -o "$OS_DRAGONFLY" ] || AC_CHECK_HEADERS malloc.h
[ "$WITH_DL_TAG" ] && AC_DEFINE 'DL_TAG_EXTENSION' '1'
[ "$WITH_PANDOC_HEADER" ] && AC_DEFINE 'PANDOC_HEADER' '1'
AC_OUTPUT Makefile version.c markdown.1
-76
View File
@@ -1,76 +0,0 @@
/* markdown: a C implementation of John Gruber's Markdown markup language.
*
* Copyright (C) 2009 David L Parsons.
* The redistribution terms are provided in the COPYRIGHT file that must
* be distributed with this source code.
*/
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include "config.h"
#include "cstring.h"
#include "markdown.h"
#include "amalloc.h"
/*
* dump out stylesheet sections.
*/
static void
stylesheets(Paragraph *p, Cstring *f)
{
Line* q;
for ( ; p ; p = p->next ) {
if ( p->typ == STYLE ) {
for ( q = p->text; q ; q = q->next )
Cswrite(f, T(q->text), S(q->text));
Csputc('\n', f);
}
if ( p->down )
stylesheets(p->down, f);
}
}
/* dump any embedded styles to a string
*/
int
mkd_css(Document *d, char **res)
{
Cstring f;
if ( res && *res && d && d->compiled ) {
CREATE(f);
RESERVE(f, 100);
stylesheets(d->code, &f);
/* HACK ALERT! HACK ALERT! HACK ALERT! */
*res = T(f); /* we know that a T(Cstring) is a character pointer */
/* so we can simply pick it up and carry it away, */
return S(f); /* leaving the husk of the Ctring on the stack */
/* END HACK ALERT */
}
return EOF;
}
/* dump any embedded styles to a file
*/
int
mkd_generatecss(Document *d, FILE *f)
{
char *res;
int written = EOF, size = mkd_css(d, &res);
if ( size > 0 )
written = fwrite(res, size, 1, f);
if ( res )
free(res);
return (written == size) ? size : EOF;
}
-75
View File
@@ -1,75 +0,0 @@
/* two template types: STRING(t) which defines a pascal-style string
* of element (t) [STRING(char) is the closest to the pascal string],
* and ANCHOR(t) which defines a baseplate that a linked list can be
* built up from. [The linked list /must/ contain a ->next pointer
* for linking the list together with.]
*/
#ifndef _CSTRING_D
#define _CSTRING_D
#include <string.h>
#include <stdlib.h>
#include "amalloc.h"
/* expandable Pascal-style string.
*/
#define STRING(type) struct { type *text; int size, alloc; }
#define CREATE(x) T(x) = (void*)(S(x) = (x).alloc = 0)
#define EXPAND(x) (S(x)++)[(S(x) < (x).alloc) \
? (T(x)) \
: (T(x) = T(x) ? realloc(T(x), sizeof T(x)[0] * ((x).alloc += 100)) \
: malloc(sizeof T(x)[0] * ((x).alloc += 100)) )]
#define DELETE(x) ALLOCATED(x) ? (free(T(x)), S(x) = (x).alloc = 0) \
: ( S(x) = 0 )
#define CLIP(t,i,sz) \
( ((i) >= 0) && ((sz) > 0) && (((i)+(sz)) <= S(t)) ) ? \
(memmove(&T(t)[i], &T(t)[i+sz], (S(t)-(i+sz)+1)*sizeof(T(t)[0])), \
S(t) -= (sz)) : -1
#define RESERVE(x, sz) T(x) = ((x).alloc > S(x) + (sz) \
? T(x) \
: T(x) \
? realloc(T(x), sizeof T(x)[0] * ((x).alloc = 100+(sz)+S(x))) \
: malloc(sizeof T(x)[0] * ((x).alloc = 100+(sz)+S(x))))
#define SUFFIX(t,p,sz) \
memcpy(((S(t) += (sz)) - (sz)) + \
(T(t) = T(t) ? realloc(T(t), sizeof T(t)[0] * ((t).alloc += sz)) \
: malloc(sizeof T(t)[0] * ((t).alloc += sz))), \
(p), sizeof(T(t)[0])*(sz))
#define PREFIX(t,p,sz) \
RESERVE( (t), (sz) ); \
if ( S(t) ) { memmove(T(t)+(sz), T(t), S(t)); } \
memcpy( T(t), (p), (sz) ); \
S(t) += (sz)
/* reference-style links (and images) are stored in an array
*/
#define T(x) (x).text
#define S(x) (x).size
#define ALLOCATED(x) (x).alloc
/* abstract anchor type that defines a list base
* with a function that attaches an element to
* the end of the list.
*
* the list base field is named .text so that the T()
* macro will work with it.
*/
#define ANCHOR(t) struct { t *text, *end; }
#define E(t) ((t).end)
#define ATTACH(t, p) ( T(t) ? ( (E(t)->next = (p)), (E(t) = (p)) ) \
: ( (T(t) = E(t) = (p)) ) )
typedef STRING(char) Cstring;
extern void Csputc(int, Cstring *);
extern int Csprintf(Cstring *, char *, ...);
extern int Cswrite(Cstring *, char *, int);
extern void Csreparse(Cstring *, char *, int, int);
#endif/*_CSTRING_D*/
-43
View File
@@ -1,43 +0,0 @@
/*
* docheader -- get values from the document header
*
* Copyright (C) 2007 David L Parsons.
* The redistribution terms are provided in the COPYRIGHT file that must
* be distributed with this source code.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "cstring.h"
#include "markdown.h"
#include "amalloc.h"
#define afterdle(t) (T((t)->text) + (t)->dle)
char *
mkd_doc_title(Document *doc)
{
if ( doc && doc->headers )
return afterdle(doc->headers);
return 0;
}
char *
mkd_doc_author(Document *doc)
{
if ( doc && doc->headers && doc->headers->next )
return afterdle(doc->headers->next);
return 0;
}
char *
mkd_doc_date(Document *doc)
{
if ( doc && doc->headers && doc->headers->next && doc->headers->next->next )
return afterdle(doc->headers->next->next);
return 0;
}
-151
View File
@@ -1,151 +0,0 @@
/* markdown: a C implementation of John Gruber's Markdown markup language.
*
* Copyright (C) 2007 David L Parsons.
* The redistribution terms are provided in the COPYRIGHT file that must
* be distributed with this source code.
*/
#include <stdio.h>
#include "markdown.h"
#include "cstring.h"
#include "amalloc.h"
struct frame {
int indent;
char c;
};
typedef STRING(struct frame) Stack;
static char *
Pptype(int typ)
{
switch (typ) {
case WHITESPACE: return "whitespace";
case CODE : return "code";
case QUOTE : return "quote";
case MARKUP : return "markup";
case HTML : return "html";
case DL : return "dl";
case UL : return "ul";
case OL : return "ol";
case LISTITEM : return "item";
case HDR : return "header";
case HR : return "hr";
case TABLE : return "table";
case SOURCE : return "source";
default : return "mystery node!";
}
}
static void
pushpfx(int indent, char c, Stack *sp)
{
struct frame *q = &EXPAND(*sp);
q->indent = indent;
q->c = c;
}
static void
poppfx(Stack *sp)
{
S(*sp)--;
}
static void
changepfx(Stack *sp, char c)
{
char ch;
if ( !S(*sp) ) return;
ch = T(*sp)[S(*sp)-1].c;
if ( ch == '+' || ch == '|' )
T(*sp)[S(*sp)-1].c = c;
}
static void
printpfx(Stack *sp, FILE *f)
{
int i;
char c;
if ( !S(*sp) ) return;
c = T(*sp)[S(*sp)-1].c;
if ( c == '+' || c == '-' ) {
fprintf(f, "--%c", c);
T(*sp)[S(*sp)-1].c = (c == '-') ? ' ' : '|';
}
else
for ( i=0; i < S(*sp); i++ ) {
if ( i )
fprintf(f, " ");
fprintf(f, "%*s%c", T(*sp)[i].indent + 2, " ", T(*sp)[i].c);
if ( T(*sp)[i].c == '`' )
T(*sp)[i].c = ' ';
}
fprintf(f, "--");
}
static void
dumptree(Paragraph *pp, Stack *sp, FILE *f)
{
int count;
Line *p;
int d;
static char *Begin[] = { 0, "P", "center" };
while ( pp ) {
if ( !pp->next )
changepfx(sp, '`');
printpfx(sp, f);
d = fprintf(f, "[%s", Pptype(pp->typ));
if ( pp->ident )
d += fprintf(f, " %s", pp->ident);
if ( pp->align )
d += fprintf(f, ", <%s>", Begin[pp->align]);
for (count=0, p=pp->text; p; ++count, (p = p->next) )
;
if ( count )
d += fprintf(f, ", %d line%s", count, (count==1)?"":"s");
d += fprintf(f, "]");
if ( pp->down ) {
pushpfx(d, pp->down->next ? '+' : '-', sp);
dumptree(pp->down, sp, f);
poppfx(sp);
}
else fputc('\n', f);
pp = pp->next;
}
}
int
mkd_dump(Document *doc, FILE *out, int flags, char *title)
{
Stack stack;
if (mkd_compile(doc, flags) ) {
CREATE(stack);
pushpfx(fprintf(out, "%s", title), doc->code->next ? '+' : '-', &stack);
dumptree(doc->code, &stack, out);
DELETE(stack);
mkd_cleanup(doc);
return 0;
}
return -1;
}
File diff suppressed because it is too large Load Diff
-197
View File
@@ -1,197 +0,0 @@
/*
* markdown: convert a single markdown document into html
*/
/*
* Copyright (C) 2007 David L Parsons.
* The redistribution terms are provided in the COPYRIGHT file that must
* be distributed with this source code.
*/
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>
#include <mkdio.h>
#include <errno.h>
#include <string.h>
#include "config.h"
#include "amalloc.h"
#if HAVE_LIBGEN_H
#include <libgen.h>
#endif
#ifndef HAVE_BASENAME
#include <string.h>
char*
basename(char *p)
{
char *ret = strrchr(p, '/');
return ret ? (1+ret) : p;
}
#endif
char *pgm = "markdown";
static struct {
char *name;
int off;
int flag;
} opts[] = {
{ "tabstop", 0, MKD_TABSTOP },
{ "image", 1, MKD_NOIMAGE },
{ "links", 1, MKD_NOLINKS },
{ "relax", 1, MKD_STRICT },
{ "strict", 0, MKD_STRICT },
{ "tables", 1, MKD_NOTABLES },
{ "header", 1, MKD_NOHEADER },
{ "html", 1, MKD_NOHTML },
{ "ext", 1, MKD_NO_EXT },
{ "cdata", 0, MKD_CDATA },
{ "pants", 1, MKD_NOPANTS },
{ "smarty", 1, MKD_NOPANTS },
{ "toc", 0, MKD_TOC },
{ "autolink",0, MKD_AUTOLINK },
{ "safelink",0, MKD_SAFELINK },
{ "1.0", 0, MKD_1_COMPAT },
} ;
#define NR(x) (sizeof x / sizeof x[0])
void
set(int *flags, char *optionstring)
{
int i;
int enable;
char *arg;
for ( arg = strtok(optionstring, ","); arg; arg = strtok(NULL, ",") ) {
if ( *arg == '+' || *arg == '-' )
enable = (*arg++ == '+') ? 1 : 0;
else if ( strncasecmp(arg, "no", 2) == 0 ) {
arg += 2;
enable = 0;
}
else
enable = 1;
for ( i=0; i < NR(opts); i++ )
if ( strcasecmp(arg, opts[i].name) == 0 )
break;
if ( i < NR(opts) ) {
if ( opts[i].off )
enable = !enable;
if ( enable )
*flags |= opts[i].flag;
else
*flags &= ~opts[i].flag;
}
else
fprintf(stderr, "%s: unknown option <%s>\n", pgm, arg);
}
}
float
main(int argc, char **argv)
{
int opt;
int rc;
int flags = 0;
int debug = 0;
int toc = 0;
int use_mkd_line = 0;
char *text = 0;
char *ofile = 0;
char *urlbase = 0;
char *q;
MMIOT *doc;
if ( q = getenv("MARKDOWN_FLAGS") )
flags = strtol(q, 0, 0);
pgm = basename(argv[0]);
opterr = 1;
while ( (opt=getopt(argc, argv, "b:df:F:o:s:t:TV")) != EOF ) {
switch (opt) {
case 'b': urlbase = optarg;
break;
case 'd': debug = 1;
break;
case 'V': printf("%s: discount %s\n", pgm, markdown_version);
exit(0);
case 'F': flags = strtol(optarg, 0, 0);
break;
case 'f': set(&flags, optarg);
break;
case 't': text = optarg;
use_mkd_line = 1;
break;
case 'T': toc = 1;
break;
case 's': text = optarg;
break;
case 'o': if ( ofile ) {
fprintf(stderr, "Too many -o options\n");
exit(1);
}
if ( !freopen(ofile = optarg, "w", stdout) ) {
perror(ofile);
exit(1);
}
break;
default: fprintf(stderr, "usage: %s [-dTV] [-b url-base]"
" [-F bitmap] [-f {+-}flags]"
" [-o ofile] [-s text]"
" [-t text] [file]\n", pgm);
exit(1);
}
}
argc -= optind;
argv += optind;
if ( use_mkd_line )
rc = mkd_generateline( text, strlen(text), stdout, flags);
else {
if ( text ) {
if ( (doc = mkd_string(text, strlen(text), flags)) == 0 ) {
perror(text);
exit(1);
}
}
else {
if ( argc && !freopen(argv[0], "r", stdin) ) {
perror(argv[0]);
exit(1);
}
if ( (doc = mkd_in(stdin,flags)) == 0 ) {
perror(argc ? argv[0] : "stdin");
exit(1);
}
}
if ( urlbase )
mkd_basename(doc, urlbase);
if ( debug )
rc = mkd_dump(doc, stdout, 0, argc ? basename(argv[0]) : "stdin");
else {
rc = 1;
if ( mkd_compile(doc, flags) ) {
rc = 0;
if ( toc )
mkd_generatetoc(doc, stdout);
mkd_generatehtml(doc, stdout);
mkd_cleanup(doc);
}
}
}
adump();
exit( (rc == 0) ? 0 : errno );
}
-27
View File
@@ -1,27 +0,0 @@
/*
* makepage: Use mkd_xhtmlpage() to convert markdown input to a
* fully-formed xhtml page.
*/
#include <stdio.h>
#include <stdlib.h>
#include <mkdio.h>
float
main(argc, argv)
int argc;
char **argv;
{
MMIOT *doc;
if ( (argc > 1) && !freopen(argv[1], "r", stdin) ) {
perror(argv[1]);
exit(1);
}
if ( (doc = mkd_in(stdin, 0)) == 0 ) {
perror( (argc > 1) ? argv[1] : "stdin" );
exit(1);
}
exit(mkd_xhtmlpage(doc, 0, stdout));
}
-128
View File
@@ -1,128 +0,0 @@
.\" %A%
.\"
.Dd January 7, 2008
.Dt MARKDOWN 1
.Os MASTODON
.Sh NAME
.Nm markdown
.Nd text to html conversion tool
.Sh SYNOPSIS
.Nm
.Op Fl d
.Op Fl T
.Op Fl V
.Op Fl b Ar url-base
.Op Fl F Pa bitmap
.Op Fl f Ar flags
.Op Fl o Pa file
.Op Fl s Pa text
.Op Fl t Pa text
.Op Pa textfile
.Sh DESCRIPTION
The
.Nm
utility reads the
.Xr markdown 7 Ns -formatted
.Pa textfile
.Pq or stdin if not specified,
compiles it, and writes the html output
to stdout.
.Pp
The options are as follows:
.Bl -tag -width "-o file"
.It Fl b Ar url-base
Links in source begining with / will be prefixed with
.Ar url-base
in the output.
.It Fl d
Instead of writing the html file, dump a parse
tree to stdout.
.It Fl f Ar flags
Set or clear various translation flags. The flags
are in a comma-delimited list, with an optional
.Ar +
(set) prefix on each flag.
.Bl -tag -width "NOHEADER"
.It Ar noimage
Don't allow image tags.
.It Ar nolinks
Don't allow links.
.It Ar nohtml
Don't allow
.B any
embedded html.
.It Ar cdata
Generate valid XML output.
.It Ar noheader
Do not process pandoc headers.
.It Ar notables
Do not process Markdown Extra-style tables.
.It Ar tabstops
Use markdown-standard 4-space tabstops.
.".It Ar strict
."Disable superscript and relaxed emphasis.
.".It Ar relax
."Enable superscript and relaxed emphasis (this is the default.)
.It Ar toc
Enable table-of-contents support
.It Ar 1.0
Revert to Markdown 1.0 compatability.
.El
.Pp
As an example, the option
.Fl f Ar nolinks,quot
tells
.Nm
to not allow \<a tags, and to expand
double-quotes.
.It Fl F Ar bitmap
Set translation flags.
.Ar Bitmap
is a bit map of the various configuration options
described in
.Xr markdown 3
(the flag values are defined in
.Pa mkdio.h )
.It Fl V
Show the version# and configuration data.
.Pp
If the version includes the string
.Em DL_TAG ,
.Nm
was configured with definition list support.
.Pp
If the version includes the string
.Em HEADER ,
.Nm
was configured to support pandoc header blocks.
.It Fl o Pa file
Write the generated html to
.Pa file .
.It Fl t Ar text
Use
.Xr mkd_text 3
to format
.Ar text
instead of processing stdin with the
.Xr markdown 3
function.
.It Fl T
If run with the table-of-content flag on, dump the
table of contents before the formatted text.
.It Fl s Ar text
Use the
.Xr markdown 3
function to format
.Ar text .
.El
.Sh RETURN VALUES
The
.Nm
utility exits 0 on success, and >0 if an error occurs.
.Sh SEE ALSO
.Xr markdown 3 ,
.Xr markdown 7 ,
.Xr mkd-extensions 7 .
.Sh AUTHOR
.An David Parsons
.Pq Li orc@pell.chi.il.us
-128
View File
@@ -1,128 +0,0 @@
.\" %A%
.\"
.Dd January 7, 2008
.Dt MARKDOWN 1
.Os MASTODON
.Sh NAME
.Nm markdown
.Nd text to html conversion tool
.Sh SYNOPSIS
.Nm
.Op Fl d
.Op Fl T
.Op Fl V
.Op Fl b Ar url-base
.Op Fl F Pa bitmap
.Op Fl f Ar flags
.Op Fl o Pa file
.Op Fl s Pa text
.Op Fl t Pa text
.Op Pa textfile
.Sh DESCRIPTION
The
.Nm
utility reads the
.Xr markdown 7 Ns -formatted
.Pa textfile
.Pq or stdin if not specified,
compiles it, and writes the html output
to stdout.
.Pp
The options are as follows:
.Bl -tag -width "-o file"
.It Fl b Ar url-base
Links in source begining with / will be prefixed with
.Ar url-base
in the output.
.It Fl d
Instead of writing the html file, dump a parse
tree to stdout.
.It Fl f Ar flags
Set or clear various translation flags. The flags
are in a comma-delimited list, with an optional
.Ar +
(set) prefix on each flag.
.Bl -tag -width "NOHEADER"
.It Ar noimage
Don't allow image tags.
.It Ar nolinks
Don't allow links.
.It Ar nohtml
Don't allow
.B any
embedded html.
.It Ar cdata
Generate valid XML output.
.It Ar noheader
Do not process pandoc headers.
.It Ar notables
Do not process Markdown Extra-style tables.
.It Ar tabstops
Use markdown-standard 4-space tabstops.
@STRICT@.It Ar strict
@STRICT@Disable superscript and relaxed emphasis.
@STRICT@.It Ar relax
@STRICT@Enable superscript and relaxed emphasis (this is the default.)
.It Ar toc
Enable table-of-contents support
.It Ar 1.0
Revert to Markdown 1.0 compatability.
.El
.Pp
As an example, the option
.Fl f Ar nolinks,quot
tells
.Nm
to not allow \<a tags, and to expand
double-quotes.
.It Fl F Ar bitmap
Set translation flags.
.Ar Bitmap
is a bit map of the various configuration options
described in
.Xr markdown 3
(the flag values are defined in
.Pa mkdio.h )
.It Fl V
Show the version# and configuration data.
.Pp
If the version includes the string
.Em DL_TAG ,
.Nm
was configured with definition list support.
.Pp
If the version includes the string
.Em HEADER ,
.Nm
was configured to support pandoc header blocks.
.It Fl o Pa file
Write the generated html to
.Pa file .
.It Fl t Ar text
Use
.Xr mkd_text 3
to format
.Ar text
instead of processing stdin with the
.Xr markdown 3
function.
.It Fl T
If run with the table-of-content flag on, dump the
table of contents before the formatted text.
.It Fl s Ar text
Use the
.Xr markdown 3
function to format
.Ar text .
.El
.Sh RETURN VALUES
The
.Nm
utility exits 0 on success, and >0 if an error occurs.
.Sh SEE ALSO
.Xr markdown 3 ,
.Xr markdown 7 ,
.Xr mkd-extensions 7 .
.Sh AUTHOR
.An David Parsons
.Pq Li orc@pell.chi.il.us
-123
View File
@@ -1,123 +0,0 @@
.\"
.Dd December 20, 2007
.Dt MARKDOWN 3
.Os Mastodon
.Sh NAME
.Nm markdown
.Nd process Markdown documents
.Sh LIBRARY
Markdown
.Pq libmarkdown , -lmarkdown
.Sh SYNOPSIS
.Fd #include <mkdio.h>
.Ft MMIOT
.Fn *mkd_in "FILE *input"
.Ft MMIOT
.Fn *mkd_string "char *string" "int size"
.Ft int
.Fn markdown "MMIOT *doc" "FILE *output" "int flags"
.Sh DESCRIPTION
These functions
convert
.Em Markdown
documents and strings into HTML.
.Fn markdown
processes an entire document, while
.Fn mkd_text
processes a single string.
.Pp
To process a file, you pass a FILE* to
.Fn mkd_in ,
and if it returns a nonzero value you pass that in to
.Fn markdown ,
which then writes the converted document to the specified
.Em FILE* .
If your input has already been written into a string (generated
input or a file opened
with
.Xr mmap 2 )
you can feed that string to
.Fn mkd_string
and pass its return value to
.Fn markdown.
.Pp
.Fn Markdown
accepts the following flag values (or-ed together if needed)
to restrict how it processes input:
.Bl -tag -width MKD_SAFELINK -compact
.It Ar MKD_NOIMAGE
Do not process `![]' and
remove
.Em \<img\>
tags from the output.
.It Ar MKD_NOLINKS
Do not process `[]' and remove
.Em \<a\>
tags from the output.
.It Ar MKD_NOPANTS
Do not do Smartypants-style mangling of quotes, dashes, or ellipses.
.It Ar MKD_STRICT
Disable superscript and relaxed emphasis processing (if they are configured;
otherwise it's a no-op.)
.\" .It Ar MKD_QUOT
.\" Expand
.\" .Ar \&"
.\" to \&&quot;.
.It Ar MKD_NOHEADER
Do not attempt to parse any Pandoc-style headers.
.It Ar MKD_TABSTOP
When reading documents, expand tabs to
.Em 4
spaces instead of whatever
.Nm
was originally configured for.
.It Ar MKD_TOC
Label all headers for use with the
.Fn mkd_generatetoc
and
.Fn mkd_toc
functions.
.It Ar MKD_1_COMPAT
MarkdownTest_1.0 compatability flag; trim trailing spaces from the
first line of code blocks and disable implicit reference links.
.It Ar MKD_AUTOLINK
Greedily urlify links -- if
.Em MKD_AUTOLINK
is set, urls will be converted into hyperlinks even if they
aren't encased in
.Em <> .
.It Ar MKD_SAFELINK
Don't make hyperlinks from
.Em [][]
links that have unknown url types.
.It Ar MKD_NOTABLES
Don't process tables.
.El
.Sh RETURN VALUES
.Fn markdown
returns 0 on success, 1 on failure.
The
.Fn mkd_in
and
.Fn mkd_string
functions return a MMIOT* on success, null on failure.
.Sh SEE ALSO
.Xr markdown 1 ,
.Xr mkd-functions 3 ,
.Xr mkd-line 3 ,
.Xr markdown 7 ,
.Xr mkd-extensions 7 ,
.Xr mmap 2 .
.Pp
http://daringfireball.net/projects/markdown/syntax
.Sh BUGS
Error handling is minimal at best.
.Pp
The
.Ar MMIOT
created by
.Fn mkd_string
is deleted by the
.Nm
function.
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
-146
View File
@@ -1,146 +0,0 @@
#ifndef _MARKDOWN_D
#define _MARKDOWN_D
#include "cstring.h"
/* reference-style links (and images) are stored in an array
* of footnotes.
*/
typedef struct footnote {
Cstring tag; /* the tag for the reference link */
Cstring link; /* what this footnote points to */
Cstring title; /* what it's called (TITLE= attribute) */
int height, width; /* dimensions (for image link) */
int dealloc; /* deallocation needed? */
} Footnote;
/* each input line is read into a Line, which contains the line,
* the offset of the first non-space character [this assumes
* that all tabs will be expanded to spaces!], and a pointer to
* the next line.
*/
typedef struct line {
Cstring text;
struct line *next;
int dle;
} Line;
/* a paragraph is a collection of Lines, with links to the next paragraph
* and (if it's a QUOTE, UL, or OL) to the reparsed contents of this
* paragraph.
*/
typedef struct paragraph {
struct paragraph *next; /* next paragraph */
struct paragraph *down; /* recompiled contents of this paragraph */
struct line *text; /* all the text in this paragraph */
char *ident; /* %id% tag for QUOTE */
enum { WHITESPACE=0, CODE, QUOTE, MARKUP,
HTML, STYLE, DL, UL, OL, AL, LISTITEM,
HDR, HR, TABLE, SOURCE } typ;
enum { IMPLICIT=0, PARA, CENTER} align;
int hnumber; /* <Hn> for typ == HDR */
} Paragraph;
enum { ETX, SETEXT }; /* header types */
typedef struct block {
enum { bTEXT, bSTAR, bUNDER } b_type;
int b_count;
char b_char;
Cstring b_text;
Cstring b_post;
} block;
typedef STRING(block) Qblock;
/* a magic markdown io thing holds all the data structures needed to
* do the backend processing of a markdown document
*/
typedef struct mmiot {
Cstring out;
Cstring in;
Qblock Q;
int isp;
STRING(Footnote) *footnotes;
int flags;
#define DENY_A 0x0001
#define DENY_IMG 0x0002
#define DENY_SMARTY 0x0004
#define DENY_HTML 0x0008
#define STRICT 0x0010
#define INSIDE_TAG 0x0020
#define NO_PSEUDO_PROTO 0x0040
#define CDATA_OUTPUT 0x0080
#define NOTABLES 0x0400
#define TOC 0x1000
#define MKD_1_COMPAT 0x2000
#define AUTOLINK 0x4000
#define SAFELINK 0x8000
#define USER_FLAGS 0xFCFF
#define EMBEDDED DENY_A|DENY_IMG|NO_PSEUDO_PROTO|CDATA_OUTPUT
char *base;
} MMIOT;
/*
* the mkdio text input functions return a document structure,
* which contains a header (retrieved from the document if
* markdown was configured * with the * --enable-pandoc-header
* and the document begins with a pandoc-style header) and the
* root of the linked list of Lines.
*/
typedef struct document {
Line *headers; /* title -> author(s) -> date */
ANCHOR(Line) content; /* uncompiled text, not valid after compile() */
Paragraph *code; /* intermediate code generated by compile() */
int compiled; /* set after mkd_compile() */
int html; /* set after (internal) htmlify() */
int tabstop; /* for properly expanding tabs (ick) */
MMIOT *ctx; /* backend buffers, flags, and structures */
char *base; /* url basename for url fragments */
} Document;
extern int mkd_firstnonblank(Line *);
extern int mkd_compile(Document *, int);
extern int mkd_document(Document *, char **);
extern int mkd_generatehtml(Document *, FILE *);
extern int mkd_css(Document *, char **);
extern int mkd_generatecss(Document *, FILE *);
#define mkd_style mkd_generatecss
extern int mkd_xml(char *, int , char **);
extern int mkd_generatexml(char *, int, FILE *);
extern void mkd_cleanup(Document *);
extern int mkd_line(char *, int, char **, int);
extern int mkd_generateline(char *, int, FILE*, int);
#define mkd_text mkd_generateline
extern void mkd_basename(Document*, char *);
extern void mkd_string_to_anchor(char*,int, void(*)(int,void*), void*);
extern Document *mkd_in(FILE *, int);
extern Document *mkd_string(char*,int, int);
#define NO_HEADER 0x0100
#define STD_TABSTOP 0x0200
#define INPUT_MASK (NO_HEADER|STD_TABSTOP)
/* internal resource handling functions.
*/
extern void ___mkd_freeLine(Line *);
extern void ___mkd_freeLines(Line *);
extern void ___mkd_freeParagraph(Paragraph *);
extern void ___mkd_freefootnote(Footnote *);
extern void ___mkd_freefootnotes(MMIOT *);
extern void ___mkd_initmmiot(MMIOT *, void *);
extern void ___mkd_freemmiot(MMIOT *, void *);
extern void ___mkd_freeLineRange(Line *, Line *);
extern void ___mkd_xml(char *, int, FILE *);
extern void ___mkd_reparse(char *, int, int, MMIOT*);
extern void ___mkd_emblock(MMIOT*);
extern void ___mkd_tidy(Cstring *);
#endif/*_MARKDOWN_D*/
-178
View File
@@ -1,178 +0,0 @@
.\"
.Dd Dec 22, 2007
.Dt MKD-EXTENSIONS 7
.Os MASTODON
.Sh NAME
.Nm mkd-extensions
.Nd Extensions to the Markdown text formatting syntax
.Sh DESCRIPTION
This version of markdown has been extended in a few ways by
extending existing markup, creating new markup from scratch,
and borrowing markup from other markup languages.
.Ss Image dimensions
Markdown embedded images have been extended to allow specifying
the dimensions of the image by adding a new argument
.Em =/height/x/width/
to the link description.
.Pp
The new image syntax is
.nf
![alt text](image =/height/x/width/ "title")
.fi
.Ss pseudo-protocols
Three pseudo-protocols have been added to links
.Bl -tag -width XXXXX
.It Ar id:
The
.Ar "alt text"
is marked up and written to the output, wrapped with
.Em "<a id=id>"
and
.Em "</a>" .
.It Ar class:
The
.Ar "alt text"
is marked up and written to the output, wrapped with
.Em "<span class=class>"
and
.Em "</span>" .
.It Ar raw:
The
.Ar title
is written
.Em -- with no further processing --
to the output. The
.Ar "alt text"
is discarded.
.It Ar abbr:
The
.Ar "alt text"
is marked up and written to the output, wrapped with
.Em "<abbr title="abbr">
and
.Em "</abbr>" .
.El
.Ss Pandoc headers
If markdown was configured with
.Ar --enable-pandoc-header ,
the markdown source document can have a 3-line
.Xr Pandoc
header in the format of
.nf
% title
% author(s)
% date
.fi
which will be made available to the
.Fn mkd_doc_title ,
.Fn mkd_doc_author ,
and
.Fn mkd_doc_date
functions.
.Ss Definition lists
If markdown was configured with
.Ar --enable-dl-tag ,
markup for definition lists is enabled. A definition list item
is defined as
.nf
=tag=
description
.fi
(that is a
.Ar = ,
followed by text, another
.Ar = ,
a newline, 4 spaces of intent, and then more text.)
.Pp
.Ss embedded stylesheets
Stylesheets may be defined and modified in a
.Em <style>
block. A style block is parsed like any other
block level html;
.Em <style>
starting on column 1, raw html (or, in this case, css) following
it, and either ending with a
.Em </style>
at the end of the line or a
.Em </style>
at the beginning of a subsequent line.
.Pp
Be warned that style blocks work like footnote links -- no matter
where you define them they are valid for the entire document.
.Ss relaxed emphasis
If markdown was configured with
.Ar --relaxed-emphasis ,
the rules for emphasis are changed so that a single
.Ar _
will
.Em not
count as a emphasis character if it's in the middle of a word.
This is primarily for documenting code, if you don't wish to
have to backquote all code references.
.Ss alpha lists
If markdown was configured with
.Ar --enable-alpha-list ,
alphabetic lists (like regular numeric lists, but with alphabetic
items) are supported. So:
.nf
a. this
b. is
c. an alphabetic
d. list
.fi
will produce:
.nf
<ol type=a>
<li>this</li>
<li>is</li>
<li>an alphabetic</li>
<li>list</li>
</ol>
.fi
.Ss tables
.Ar PHP Markdown Extra -style
tables are supported; input of the form
.nf
header|header
------|------
text | text
.fi
will produce:
.nf
<table>
<thead>
<tr>
<th>header</th>
<th>header</th>
</tr>
</thead>
<tbody>
<tr>
<td>text</td>
<td>text</td>
</tr>
</tbody>
</table>
.fi
The dashed line can also contain
.Em :
characters for formatting; if a
.Em :
is at the start of a column, it tells
.Nm discount
to align the cell contents to the left; if it's at the end, it
aligns right, and if there's one at the start and at the
end, it centers.
.Sh AUTHOR
David Parsons
.%T http://www.pell.portland.or.us/~orc/
.Sh SEE ALSO
.Xr markdown 1 ,
.Xr markdown 3 ,
.Xr mkd-functions 3 ,
.Xr mkd-line 3 ,
.Xr mkd-extensions 7 .
.Pp
.%T http://daringfireball.net/projects/markdown
.Pp
.%T http://michelf.com/projects/php-markdown
-180
View File
@@ -1,180 +0,0 @@
.\"
.Dd January 18, 2008
.Dt MKD_FUNCTIONS 3
.Os Mastodon
.Sh NAME
.Nm mkd_functions
.Nd access and process Markdown documents.
.Sh LIBRARY
Markdown
.Pq libmarkdown , -lmarkdown
.Sh SYNOPSIS
.Fd #include <mkdio.h>
.Ft int
.Fn mkd_compile "MMIOT *document" "int flags"
.Ft int
.Fn mkd_css "MMIOT *document" "char **doc"
.Ft int
.Fn mkd_generatecss "MMIOT *document" "FILE *output"
.Ft int
.Fn mkd_document "MMIOT *document" "char **doc"
.Ft int
.Fn mkd_generatehtml "MMIOT *document" "FILE *output"
.Ft int
.Fn mkd_xhtmlpage "MMIOT *document" "int flags" "FILE *output"
.Ft int
.Fn mkd_toc "MMIOT *document" "char **doc"
.Ft void
.Fn mkd_generatetoc "MMIOT *document" "FILE *output"
.Ft void
.Fn mkd_cleanup "MMIOT*"
.Ft char*
.Fn mkd_doc_title "MMIOT*"
.Ft char*
.Fn mkd_doc_author "MMIOT*"
.Ft char*
.Fn mkd_doc_date "MMIOT*"
.Sh DESCRIPTION
.Pp
The
.Nm markdown
format supported in this implementation includes
Pandoc-style header and inline
.Ar \<style\>
blocks, and the standard
.Xr markdown 3
functions do not provide access to
the data provided by either of those extensions.
These functions give you access to that data, plus
they provide a finer-grained way of converting
.Em Markdown
documents into HTML.
.Pp
Given a
.Ar MMIOT*
generated by
.Fn mkd_in
or
.Fn mkd_string ,
.Fn mkd_compile
compiles the document into
.Em \<style\> ,
.Em Pandoc ,
and
.Em html
sections.
.Pp
Once compiled, the document can be examined and written
by the
.Fn mkd_css ,
.Fn mkd_document ,
.Fn mkd_generatecss ,
.Fn mkd_generatehtml ,
.Fn mkd_generatetoc ,
.Fn mkd_toc ,
.Fn mkd_xhtmlpage ,
.Fn mkd_doc_title ,
.Fn mkd_doc_author ,
and
.Fn mkd_doc_date
functions.
.Pp
.Fn mkd_css
allocates a string and populates it with any \<style\> sections
provided in the document,
.Fn mkd_generatecss
writes any \<style\> sections to the output,
.Fn mkd_document
points
.Ar text
to the text of the document and returns the
size of the document,
.Fn mkd_generatehtml
writes the rest of the document to the output,
and
.Fn mkd_doc_title ,
.Fn mkd_doc_author ,
.Fn mkd_doc_date
are used to read the contents of a Pandoc header,
if any.
.Pp
.Fn mkd_xhtmlpage
writes a xhtml page containing the document. The regular set of
flags can be passed.
.Pp
.Fn mkd_toc
writes a document outline, in the form of a collection of nested
lists with links to each header in the document, into a string
allocated with
.Fn malloc ,
and returns the size.
.Pp
.Fn mkd_generatetoc
is like
.Fn mkd_toc ,
except that it writes the document outline to the given
.Pa FILE*
argument.
.Pp
.Fn mkd_cleanup
deletes a
.Ar MMIOT*
after processing is done.
.Pp
.Fn mkd_compile
accepts the same flags that
.Fn markdown
and
.Fn mkd_string
do;
.Bl -tag -width MKD_NOIMAGE -compact
.It Ar MKD_NOIMAGE
Do not process `![]' and
remove
.Em \<img\>
tags from the output.
.It Ar MKD_NOLINKS
Do not process `[]' and remove
.Em \<a\>
tags from the output.
.It Ar MKD_NOPANTS
Do not do Smartypants-style mangling of quotes, dashes, or ellipses.
.It Ar MKD_TAGTEXT
Process the input as if you were inside a html tag. This means that
no html tags will be generated, and
.Fn mkd_compile
will attempt to escape anything that might terribly confuse a
web browser.
.It Ar MKD_NO_EXT
Do not process any markdown pseudo-protocols when
handing
.Ar [][]
links.
.It Ar MKD_NOHEADER
Do not attempt to parse any Pandoc-style headers.
.It Ar MKD_TOC
Label all headers for use with the
.Fn mkd_generatetoc
function.
.It Ar MKD_1_COMPAT
MarkdownTest_1.0 compatability flag; trim trailing spaces from the
first line of code blocks and disable implicit reference links.
.El
.Sh RETURN VALUES
The functions
.Fn mkd_compile ,
.Fn mkd_style ,
and
.Fn mkd_generatehtml
return 0 on success, -1 on failure.
.Sh SEE ALSO
.Xr markdown 1 ,
.Xr markdown 3 ,
.Xr mkd-line 3 ,
.Xr markdown 7 ,
.Xr mkd-extensions 7 ,
.Xr mmap 2 .
.Pp
http://daringfireball.net/projects/markdown/syntax
.Sh BUGS
Error handling is minimal at best.
-41
View File
@@ -1,41 +0,0 @@
.\"
.Dd January 18, 2008
.Dt MKD_LINE 3
.Os Mastodon
.Sh NAME
.Nm mkd_line
.Nd do Markdown translation of small items
.Sh LIBRARY
Markdown
.Pq libmarkdown , -lmarkdown
.Sh SYNOPSIS
.Fd #include <mkdio.h>
.Ft int
.Fn mkd_line "char *string" "int size" "char **doc" "int flags"
.Ft int
.Fn mkd_generateline "char *string" "int size" "FILE *output" "int flags"
.Sh DESCRIPTION
.Pp
Occasionally one might want to do markdown translations on fragments of
data, like the title of an weblog article, a date, or a simple signature
line.
.Nm mkd_line
and
.Nm mkd_generateline
allow you to do markdown translations on small blocks of text.
.Nm mkd_line
allocates a buffer, then writes the translated text into that buffer,
and
.Nm mkd_generateline
writes the output to the specified
.Ar FILE* .
.Sh SEE ALSO
.Xr markdown 1 ,
.Xr markdown 3 ,
.Xr markdown 7 ,
.Xr mkd-extensions 7 ,
.Xr mmap 2 .
.Pp
http://daringfireball.net/projects/markdown/syntax
.Sh BUGS
Error handling is minimal at best.
-185
View File
@@ -1,185 +0,0 @@
/*
* mkd2html: parse a markdown input file and generate a web page.
*
* usage: mkd2html [options] filename
* or mkd2html [options] < markdown > html
*
* options
* -css css-file
* -header line-to-add-to-<HEADER>
* -footer line-to-add-before-</BODY>
*
* example:
*
* mkd2html -cs /~orc/pages.css syntax
* ( read syntax OR syntax.text, write syntax.html )
*/
/*
* Copyright (C) 2007 David L Parsons.
* The redistribution terms are provided in the COPYRIGHT file that must
* be distributed with this source code.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_BASENAME
# ifdef HAVE_LIBGEN_H
# include <libgen.h>
# else
# include <unistd.h>
# endif
#endif
#include <stdarg.h>
#include "mkdio.h"
#include "cstring.h"
#include "amalloc.h"
char *pgm = "mkd2html";
#ifndef HAVE_BASENAME
char *
basename(char *path)
{
char *p;
if (( p = strrchr(path, '/') ))
return 1+p;
return path;
}
#endif
void
fail(char *why, ...)
{
va_list ptr;
va_start(ptr,why);
fprintf(stderr, "%s: ", pgm);
vfprintf(stderr, why, ptr);
fputc('\n', stderr);
va_end(ptr);
exit(1);
}
void
main(argc, argv)
char **argv;
{
char *h;
char *source = 0, *dest = 0;
MMIOT *mmiot;
int i;
FILE *input, *output;
STRING(char*) css, headers, footers;
CREATE(css);
CREATE(headers);
CREATE(footers);
pgm = basename(argv[0]);
while ( argc > 2 ) {
if ( strcmp(argv[1], "-css") == 0 ) {
EXPAND(css) = argv[2];
argc -= 2;
argv += 2;
}
else if ( strcmp(argv[1], "-header") == 0 ) {
EXPAND(headers) = argv[2];
argc -= 2;
argv += 2;
}
else if ( strcmp(argv[1], "-footer") == 0 ) {
EXPAND(footers) = argv[2];
argc -= 2;
argv += 2;
}
}
if ( argc > 1 ) {
char *p, *dot;
source = malloc(strlen(argv[1]) + 6);
dest = malloc(strlen(argv[1]) + 6);
if ( !(source && dest) )
fail("out of memory allocating name buffers");
strcpy(source, argv[1]);
if (( p = strrchr(source, '/') ))
p = source;
else
++p;
if ( (input = fopen(source, "r")) == 0 ) {
strcat(source, ".text");
if ( (input = fopen(source, "r")) == 0 )
fail("can't open either %s or %s", argv[1], source);
}
strcpy(dest, source);
if (( dot = strrchr(dest, '.') ))
*dot = 0;
strcat(dest, ".html");
if ( (output = fopen(dest, "w")) == 0 )
fail("can't write to %s", dest);
}
else {
input = stdin;
output = stdout;
}
if ( (mmiot = mkd_in(input, 0)) == 0 )
fail("can't read %s", source ? source : "stdin");
if ( !mkd_compile(mmiot, 0) )
fail("couldn't compile input");
h = mkd_doc_title(mmiot);
/* print a header */
fprintf(output,
"<!doctype html public \"-//W3C//DTD HTML 4.0 Transitional //EN\">\n"
"<html>\n"
"<head>\n"
" <meta name=\"GENERATOR\" content=\"mkd2html %s\">\n", markdown_version);
fprintf(output," <meta http-equiv=\"Content-Type\"\n"
" content=\"text/html; charset-us-ascii\">");
for ( i=0; i < S(css); i++ )
fprintf(output, " <link rel=\"stylesheet\"\n"
" type=\"text/css\"\n"
" href=\"%s\" />\n", T(css)[i]);
if ( h ) {
fprintf(output," <title>");
mkd_generateline(h, strlen(h), output, 0);
fprintf(output, "</title>\n");
}
for ( i=0; i < S(headers); i++ )
fprintf(output, " %s\n", T(headers)[i]);
fprintf(output, "</head>\n"
"<body>\n");
/* print the compiled body */
mkd_generatehtml(mmiot, output);
for ( i=0; i < S(footers); i++ )
fprintf(output, "%s\n", T(footers)[i]);
fprintf(output, "</body>\n"
"</html>\n");
mkd_cleanup(mmiot);
exit(0);
}
-303
View File
@@ -1,303 +0,0 @@
/*
* mkdio -- markdown front end input functions
*
* Copyright (C) 2007 David L Parsons.
* The redistribution terms are provided in the COPYRIGHT file that must
* be distributed with this source code.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "cstring.h"
#include "markdown.h"
#include "amalloc.h"
typedef ANCHOR(Line) LineAnchor;
/* create a new blank Document
*/
static Document*
new_Document()
{
Document *ret = calloc(sizeof(Document), 1);
if ( ret ) {
if (( ret->ctx = calloc(sizeof(MMIOT), 1) ))
return ret;
free(ret);
}
return 0;
}
/* add a line to the markdown input chain
*/
static void
queue(Document* a, Cstring *line)
{
Line *p = calloc(sizeof *p, 1);
unsigned char c;
int xp = 0;
int size = S(*line);
unsigned char *str = (unsigned char*)T(*line);
CREATE(p->text);
ATTACH(a->content, p);
while ( size-- ) {
if ( (c = *str++) == '\t' ) {
/* expand tabs into ->tabstop spaces. We use ->tabstop
* because the ENTIRE FREAKING COMPUTER WORLD uses editors
* that don't do ^T/^D, but instead use tabs for indentation,
* and, of course, set their tabs down to 4 spaces
*/
do {
EXPAND(p->text) = ' ';
} while ( ++xp % a->tabstop );
}
else if ( c >= ' ' ) {
EXPAND(p->text) = c;
++xp;
}
}
EXPAND(p->text) = 0;
S(p->text)--;
p->dle = mkd_firstnonblank(p);
}
#ifdef PANDOC_HEADER
/* trim leading blanks from a header line
*/
static void
snip(Line *p)
{
CLIP(p->text, 0, 1);
p->dle = mkd_firstnonblank(p);
}
#endif
/* build a Document from any old input.
*/
typedef int (*getc_func)(void*);
Document *
populate(getc_func getc, void* ctx, int flags)
{
Cstring line;
Document *a = new_Document();
int c;
#ifdef PANDOC_HEADER
int pandoc = 0;
#endif
if ( !a ) return 0;
a->tabstop = (flags & STD_TABSTOP) ? 4 : TABSTOP;
CREATE(line);
while ( (c = (*getc)(ctx)) != EOF ) {
if ( c == '\n' ) {
#ifdef PANDOC_HEADER
if ( pandoc != EOF && pandoc < 3 ) {
if ( S(line) && (T(line)[0] == '%') )
pandoc++;
else
pandoc = EOF;
}
#endif
queue(a, &line);
S(line) = 0;
}
else if ( isprint(c) || isspace(c) || (c & 0x80) )
EXPAND(line) = c;
}
if ( S(line) )
queue(a, &line);
DELETE(line);
#ifdef PANDOC_HEADER
if ( (pandoc == 3) && !(flags & NO_HEADER) ) {
/* the first three lines started with %, so we have a header.
* clip the first three lines out of content and hang them
* off header.
*/
a->headers = T(a->content);
T(a->content) = a->headers->next->next->next;
a->headers->next->next->next = 0;
snip(a->headers);
snip(a->headers->next);
snip(a->headers->next->next);
}
#endif
return a;
}
/* convert a file into a linked list
*/
Document *
mkd_in(FILE *f, int flags)
{
return populate((getc_func)fgetc, f, flags & INPUT_MASK);
}
/* return a single character out of a buffer
*/
struct string_ctx {
char *data; /* the unread data */
int size; /* and how much is there? */
} ;
static int
strget(struct string_ctx *in)
{
if ( !in->size ) return EOF;
--(in->size);
return *(in->data)++;
}
/* convert a block of text into a linked list
*/
Document *
mkd_string(char *buf, int len, int flags)
{
struct string_ctx about;
about.data = buf;
about.size = len;
return populate((getc_func)strget, &about, flags & INPUT_MASK);
}
/* write the html to a file (xmlified if necessary)
*/
int
mkd_generatehtml(Document *p, FILE *output)
{
char *doc;
int szdoc;
if ( (szdoc = mkd_document(p, &doc)) != EOF ) {
if ( p->ctx->flags & CDATA_OUTPUT )
mkd_generatexml(doc, szdoc, output);
else
fwrite(doc, szdoc, 1, output);
putc('\n', output);
return 0;
}
return -1;
}
/* convert some markdown text to html
*/
int
markdown(Document *document, FILE *out, int flags)
{
if ( mkd_compile(document, flags) ) {
mkd_generatehtml(document, out);
mkd_cleanup(document);
return 0;
}
return -1;
}
void
mkd_basename(Document *document, char *base)
{
if ( document )
document->base = base;
}
/* write out a Cstring, mangled into a form suitable for `<a href=` or `<a id=`
*/
void
mkd_string_to_anchor(char *s, int len, void(*outchar)(int,void*), void *out)
{
unsigned char c;
for ( ; len-- > 0; ) {
c = *s++;
if ( c == ' ' || c == '&' || c == '<' || c == '"' )
(*outchar)('+', out);
else if ( isalnum(c) || ispunct(c) || (c & 0x80) )
(*outchar)(c, out);
else
(*outchar)('~',out);
}
}
/* ___mkd_reparse() a line
*/
static void
mkd_parse_line(char *bfr, int size, MMIOT *f, int flags)
{
___mkd_initmmiot(f, 0);
f->flags = flags & USER_FLAGS;
___mkd_reparse(bfr, size, 0, f);
___mkd_emblock(f);
}
/* ___mkd_reparse() a line, returning it in malloc()ed memory
*/
int
mkd_line(char *bfr, int size, char **res, int flags)
{
MMIOT f;
int len;
mkd_parse_line(bfr, size, &f, flags);
if ( len = S(f.out) ) {
/* kludge alert; we know that T(f.out) is malloced memory,
* so we can just steal it away. This is awful -- there
* should be an opaque method that transparently moves
* the pointer out of the embedded Cstring.
*/
*res = T(f.out);
T(f.out) = 0;
S(f.out) = 0;
}
else {
*res = 0;
len = EOF;
}
___mkd_freemmiot(&f, 0);
return len;
}
/* ___mkd_reparse() a line, writing it to a FILE
*/
int
mkd_generateline(char *bfr, int size, FILE *output, int flags)
{
MMIOT f;
mkd_parse_line(bfr, size, &f, flags);
if ( flags & CDATA_OUTPUT )
mkd_generatexml(T(f.out), S(f.out), output);
else
fwrite(T(f.out), S(f.out), 1, output);
___mkd_freemmiot(&f, 0);
return 0;
}
-79
View File
@@ -1,79 +0,0 @@
#ifndef _MKDIO_D
#define _MKDIO_D
#include <stdio.h>
typedef void MMIOT;
/* line builder for markdown()
*/
MMIOT *mkd_in(FILE*,int); /* assemble input from a file */
MMIOT *mkd_string(char*,int,int); /* assemble input from a buffer */
void mkd_basename(MMIOT*,char*);
/* compilation, debugging, cleanup
*/
int mkd_compile(MMIOT*, int);
int mkd_cleanup(MMIOT*);
/* markup functions
*/
int mkd_dump(MMIOT*, FILE*, int, char*);
int markdown(MMIOT*, FILE*, int);
int mkd_line(char *, int, char **, int);
void mkd_string_to_anchor(char *, int, int (*)(int,void*), void*);
int mkd_xhtmlpage(MMIOT*,int,FILE*);
/* header block access
*/
char* mkd_doc_title(MMIOT*);
char* mkd_doc_author(MMIOT*);
char* mkd_doc_date(MMIOT*);
/* compiled data access
*/
int mkd_document(MMIOT*, char**);
int mkd_toc(MMIOT*, char**);
int mkd_css(MMIOT*, char **);
int mkd_xml(char *, int, char **);
/* write-to-file functions
*/
int mkd_generatehtml(MMIOT*,FILE*);
int mkd_generatetoc(MMIOT*,FILE*);
int mkd_generatexml(char *, int,FILE*);
int mkd_generatecss(MMIOT*,FILE*);
#define mkd_style mkd_generatecss
int mkd_generateline(char *, int, FILE*, int);
#define mkd_text mkd_generateline
/* version#.
*/
extern char markdown_version[];
/* special flags for markdown() and mkd_text()
*/
#define MKD_NOLINKS 0x0001 /* don't do link processing, block <a> tags */
#define MKD_NOIMAGE 0x0002 /* don't do image processing, block <img> */
#define MKD_NOPANTS 0x0004 /* don't run smartypants() */
#define MKD_NOHTML 0x0008 /* don't allow raw html through AT ALL */
#define MKD_STRICT 0x0010 /* disable SUPERSCRIPT, RELAXED_EMPHASIS */
#define MKD_TAGTEXT 0x0020 /* process text inside an html tag; no
* <em>, no <bold>, no html or [] expansion */
#define MKD_NO_EXT 0x0040 /* don't allow pseudo-protocols */
#define MKD_CDATA 0x0080 /* generate code for xml ![CDATA[...]] */
#define MKD_NOTABLES 0x0400 /* disallow tables */
#define MKD_TOC 0x1000 /* do table-of-contents processing */
#define MKD_1_COMPAT 0x2000 /* compatability with MarkdownTest_1.0 */
#define MKD_AUTOLINK 0x4000 /* make http://foo.com link even without <>s */
#define MKD_SAFELINK 0x8000 /* paranoid check for link protocol */
#define MKD_EMBED MKD_NOLINKS|MKD_NOIMAGE|MKD_TAGTEXT
/* special flags for mkd_in() and mkd_string()
*/
#define MKD_NOHEADER 0x0100 /* don't process header blocks */
#define MKD_TABSTOP 0x0200 /* expand tabs to 4 spaces */
#endif/*_MKDIO_D*/
-155
View File
@@ -1,155 +0,0 @@
/* markdown: a C implementation of John Gruber's Markdown markup language.
*
* Copyright (C) 2007 David L Parsons.
* The redistribution terms are provided in the COPYRIGHT file that must
* be distributed with this source code.
*/
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include "config.h"
#include "cstring.h"
#include "markdown.h"
#include "amalloc.h"
/* free a (single) line
*/
void
___mkd_freeLine(Line *ptr)
{
DELETE(ptr->text);
free(ptr);
}
/* free a list of lines
*/
void
___mkd_freeLines(Line *p)
{
if (p->next)
___mkd_freeLines(p->next);
___mkd_freeLine(p);
}
/* bye bye paragraph.
*/
void
___mkd_freeParagraph(Paragraph *p)
{
if (p->next)
___mkd_freeParagraph(p->next);
if (p->down)
___mkd_freeParagraph(p->down);
if (p->text)
___mkd_freeLines(p->text);
if (p->ident)
free(p->ident);
free(p);
}
/* bye bye footnote.
*/
void
___mkd_freefootnote(Footnote *f)
{
DELETE(f->tag);
DELETE(f->link);
DELETE(f->title);
}
/* bye bye footnotes.
*/
void
___mkd_freefootnotes(MMIOT *f)
{
int i;
if ( f->footnotes ) {
for (i=0; i < S(*f->footnotes); i++)
___mkd_freefootnote( &T(*f->footnotes)[i] );
DELETE(*f->footnotes);
free(f->footnotes);
}
}
/* initialize a new MMIOT
*/
void
___mkd_initmmiot(MMIOT *f, void *footnotes)
{
if ( f ) {
memset(f, 0, sizeof *f);
CREATE(f->in);
CREATE(f->out);
CREATE(f->Q);
if ( footnotes )
f->footnotes = footnotes;
else {
f->footnotes = malloc(sizeof f->footnotes[0]);
CREATE(*f->footnotes);
}
}
}
/* free the contents of a MMIOT, but leave the object alone.
*/
void
___mkd_freemmiot(MMIOT *f, void *footnotes)
{
if ( f ) {
DELETE(f->in);
DELETE(f->out);
DELETE(f->Q);
if ( f->footnotes != footnotes )
___mkd_freefootnotes(f);
memset(f, 0, sizeof *f);
}
}
/* free lines up to an barrier.
*/
void
___mkd_freeLineRange(Line *anchor, Line *stop)
{
Line *r = anchor->next;
if ( r != stop ) {
while ( r && (r->next != stop) )
r = r->next;
if ( r ) r->next = 0;
___mkd_freeLines(anchor->next);
}
anchor->next = 0;
}
/* clean up everything allocated in __mkd_compile()
*/
void
mkd_cleanup(Document *doc)
{
if ( doc ) {
if ( doc->ctx ) {
___mkd_freemmiot(doc->ctx, 0);
free(doc->ctx);
}
if ( doc->code) ___mkd_freeParagraph(doc->code);
if ( doc->headers ) ___mkd_freeLines(doc->headers);
if ( T(doc->content) ) ___mkd_freeLines(T(doc->content));
memset(doc, 0, sizeof doc[0]);
free(doc);
}
}
-42
View File
@@ -1,42 +0,0 @@
./echo 'Reddit-style automatic links'
rc=0
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try -fautolink 'single link' \
'http://www.pell.portland.or.us/~orc/Code/discount' \
'<p><a href="http://www.pell.portland.or.us/~orc/Code/discount">http://www.pell.portland.or.us/~orc/Code/discount</a></p>'
try -fautolink 'link surrounded by text' \
'here http://it is?' \
'<p>here <a href="http://it">http://it</a> is?</p>'
try -fautolink 'naked @' '@' '<p>@</p>'
try -fautolink 'parenthesised (url)' \
'(http://here)' \
'<p>(<a href="http://here">http://here</a>)</p>'
try -fautolink 'token with trailing @' 'orc@' '<p>orc@</p>'
exit $rc
-53
View File
@@ -1,53 +0,0 @@
./echo "automatic links"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
match() {
./echo -n " $1" '..................................' | ./cols 36
if ./echo "$2" | ./markdown | grep "$3" >/dev/null; then
./echo " ok"
else
./echo " FAILED"
rc=1
fi
}
try 'http url' '<http://here>' '<p><a href="http://here">http://here</a></p>'
try 'ftp url' '<ftp://here>' '<p><a href="ftp://here">ftp://here</a></p>'
match '<orc@pell.portland.or.us>' '<orc@pell.portland.or.us>' '<a href='
match '<orc@pell.com.>' '<orc@pell.com.>' '<a href='
try 'invalid <orc@>' '<orc@>' '<p>&lt;orc@></p>'
try 'invalid <@pell>' '<@pell>' '<p>&lt;@pell></p>'
try 'invalid <orc@pell>' '<orc@pell>' '<p>&lt;orc@pell></p>'
try 'invalid <orc@.pell>' '<orc@.pell>' '<p>&lt;orc@.pell></p>'
try 'invalid <orc@pell.>' '<orc@pell.>' '<p>&lt;orc@pell.></p>'
match '<mailto:orc@pell>' '<mailto:orc@pell>' '<a href='
match '<mailto:orc@pell.com>' '<mailto:orc@pell.com>' '<a href='
match '<mailto:orc@>' '<mailto:orc@>' '<a href='
match '<mailto:@pell>' '<mailto:@pell>' '<a href='
exit $rc
-35
View File
@@ -1,35 +0,0 @@
./echo "backslash escapes"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got: $Q"
rc=1
fi
}
try 'backslashes in []()' '[foo](http://\this\is\.a\test\(here\))' \
'<p><a href="http://\this\is.a\test(here)">foo</a></p>'
try -fautolink 'autolink url with trailing \' \
'http://a.com/\' \
'<p><a href="http://a.com/\">http://a.com/\</a></p>'
exit $rc
-13
View File
@@ -1,13 +0,0 @@
->###chrome with my markdown###<-
1. `(c)` -> `&copy;` (c)
2. `(r)` -> `&reg;` (r)
3. `(tm)` -> `&trade;` (tm)
4. `...` -> `&hellip;` ...
5. `--` -> `&emdash;` --
6. `-` -> `&ndash;` - (but not if it's between-words)
7. "fancy quoting"
8. 'fancy quoting (#2)'
9. don't do it unless it's a real quote.
10. `` (`) ``
-39
View File
@@ -1,39 +0,0 @@
./echo "code blocks"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try 'format for code block html' \
' this is
code' \
'<pre><code>this is
code
</code></pre>'
try 'unclosed single backtick' '`hi there' '<p>`hi there</p>'
try 'unclosed double backtick' '``hi there' '<p>``hi there</p>'
try 'remove space around code' '`` hi there ``' '<p><code>hi there</code></p>'
exit $rc
-47
View File
@@ -1,47 +0,0 @@
./echo "markdown 1.0 compatability"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
LINKY='[this] is a test
[this]: /this'
try 'implicit reference links' "$LINKY" '<p><a href="/this">this</a> is a test</p>'
try -f1.0 'implicit reference links (-f1.0)' "$LINKY" '<p>[this] is a test</p>'
WSP=' '
WHITESPACE="
white space$WSP
and more"
try 'trailing whitespace' "$WHITESPACE" '<pre><code>white space ''
and more
</code></pre>'
try -f1.0 'trailing whitespace (-f1.0)' "$WHITESPACE" '<pre><code>white space''
and more
</code></pre>'
exit $rc
-48
View File
@@ -1,48 +0,0 @@
./echo "crashes"
rc=0
MARKDOWN_FLAGS=
./echo -n ' zero-length input ................ '
if ./markdown < /dev/null >/dev/null; then
./echo "ok"
else
./echo "FAILED"
rc=1
fi
./echo -n ' hanging quote in list ............ '
./markdown >/dev/null 2>/dev/null << EOF
* > this should not die
no.
EOF
if [ "$?" -eq 0 ]; then
./echo "ok"
else
./echo "FAILED"
rc=1
fi
./echo -n ' dangling list item ............... '
if ./echo ' - ' | ./markdown >/dev/null 2>/dev/null; then
./echo "ok"
else
./echo "FAILED"
rc=1
fi
./echo -n ' empty []() with baseurl .......... '
if ./markdown -bHOHO -s '[]()' >/dev/null 2>/dev/null; then
./echo "ok"
else
./echo "FAILED"
rc=1
fi
exit $rc
-67
View File
@@ -1,67 +0,0 @@
./markdown -V | grep DIV >/dev/null || exit 0
./echo "%div% blocks"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try 'simple >%div% block' \
'>%this%
this this' \
'<div class="this"><p>this this</p></div>'
try 'two >%div% blocks in a row' \
'>%this%
this this
>%that%
that that' \
'<div class="this"><p>this this</p></div>
<div class="that"><p>that that</p></div>'
try '>%class:div%' \
'>%class:this%
this this' \
'<div class="this"><p>this this</p></div>'
try '>%id:div%' \
'>%id:this%
this this' \
'<div id="this"><p>this this</p></div>'
try 'nested >%div%' \
'>%this%
>>%that%
>>that
>%more%
more' \
'<div class="this"><div class="that"><p>that</p></div></div>
<div class="more"><p>more</p></div>'
exit $rc
-69
View File
@@ -1,69 +0,0 @@
./echo "definition lists"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
SRC='
=this=
is an ugly
=test=
eh?'
RSLT='<dl>
<dt>this</dt>
<dd>is an ugly</dd>
<dt>test</dt>
<dd>eh?</dd>
</dl>'
if ./markdown -V | grep DL_TAG >/dev/null; then
try '=tag= generates definition lists' "$SRC" "$RSLT"
try 'one item with two =tags=' \
'=this=
=is=
A test, eh?' \
'<dl>
<dt>this</dt>
<dt>is</dt>
<dd>A test, eh?</dd>
</dl>'
else
try '=tag= does nothing' "$SRC" \
'<p>=this=</p>
<pre><code>is an ugly
</code></pre>
<p>=test=</p>
<pre><code>eh?
</code></pre>'
fi
exit $rc
-9
View File
@@ -1,9 +0,0 @@
* [![an image](http://dustmite.org/mite.jpg =50x50)] (http://dustmite.org)
* [[an embedded link](http://wontwork.org)](http://willwork.org)
* [![dustmite][]] (http:/dustmite.org)
* ![dustmite][]
* ![dustmite][dustmite]
* [<a href="http://cheating.us">cheat me</a>](http://I.am.cheating)
[dustmite]: http://dustmite.org/mite.jpg =25x25 "here I am!"
-40
View File
@@ -1,40 +0,0 @@
./echo "emphasis"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try '*hi* -> <em>hi</em>' '*hi*' '<p><em>hi</em></p>'
try '* -> *' 'A * A' '<p>A * A</p>'
try -fstrict '***A**B*' '***A**B*' '<p><em><strong>A</strong>B</em></p>'
try -fstrict '***A*B**' '***A*B**' '<p><strong><em>A</em>B</strong></p>'
try -fstrict '**A*B***' '**A*B***' '<p><strong>A<em>B</em></strong></p>'
try -fstrict '*A**B***' '*A**B***' '<p><em>A<strong>B</strong></em></p>'
if ./markdown -V | grep RELAXED >/dev/null; then
try -frelax '_A_B with -frelax' '_A_B' '<p>_A_B</p>'
try -fstrict '_A_B with -fstrict' '_A_B' '<p><em>A</em>B</p>'
fi
exit $rc
-52
View File
@@ -1,52 +0,0 @@
./echo "paragraph flow"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try 'header followed by paragraph' \
'###Hello, sailor###
And how are you today?' \
'<h3>Hello, sailor</h3>
<p>And how are you today?</p>'
try 'two lists punctuated with a HR' \
'* A
* * *
* B
* C' \
'<ul>
<li>A</li>
</ul>
<hr />
<ul>
<li>B</li>
<li>C</li>
</ul>'
exit $rc
-34
View File
@@ -1,34 +0,0 @@
./echo "footnotes"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try 'a line with multiple []s' '[a][] [b][]:' '<p>[a][] [b][]:</p>'
try 'a valid footnote' \
'[alink][]
[alink]: link_me' \
'<p><a href="link_me">alink</a></p>'
exit $rc
-42
View File
@@ -1,42 +0,0 @@
./echo "headers"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
S=`./echo -n "$1" '..................................' | ./cols 34`
./echo -n " $S "
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo "ok"
else
./echo "FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try 'single #' '#' '<p>#</p>'
try 'empty ETX' '##' '<h1>#</h1>'
try 'single-char ETX (##W)' '##W' '<h2>W</h2>'
try 'single-char ETX (##W )' '##W ' '<h2>W</h2>'
try 'single-char ETX (## W)' '## W' '<h2>W</h2>'
try 'single-char ETX (## W )' '## W ' '<h2>W</h2>'
try 'single-char ETX (##W##)' '##W##' '<h2>W</h2>'
try 'single-char ETX (##W ##)' '##W ##' '<h2>W</h2>'
try 'single-char ETX (## W##)' '## W##' '<h2>W</h2>'
try 'single-char ETX (## W ##)' '## W ##' '<h2>W</h2>'
try 'multiple-char ETX (##Hello##)' '##Hello##' '<h2>Hello</h2>'
exit $rc
-109
View File
@@ -1,109 +0,0 @@
./echo "html blocks"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try 'self-closing block tags (hr)' \
'<hr>
text' \
'<hr>
<p>text</p>'
try 'self-closing block tags (hr/)' \
'<hr/>
text' \
'<hr/>
<p>text</p>'
try 'self-closing block tags (br)' \
'<br>
text' \
'<br>
<p>text</p>'
try 'html comments' \
'<!--
**hi**
-->' \
'<!--
**hi**
-->'
try 'no smartypants inside tags (#1)' \
'<img src="linky">' \
'<p><img src="linky"></p>'
try 'no smartypants inside tags (#2)' \
'<img src="linky" alt=":)" />' \
'<p><img src="linky" alt=":)" /></p>'
try -fnohtml 'block html with -fnohtml' '<b>hi!</b>' '<p>&lt;b>hi!&lt;/b></p>'
try -fhtml 'allow html with -fhtml' '<b>hi!</b>' '<p><b>hi!</b></p>'
# check that nested raw html blocks terminate properly.
#
BLOCK1SRC='Markdown works fine *here*.
*And* here.
<div><pre>
</pre></div>
Markdown here is *not* parsed by RDiscount.
Nor in *this* paragraph, and there are no paragraph breaks.'
BLOCK1OUT='<p>Markdown works fine <em>here</em>.</p>
<p><em>And</em> here.</p>
<div><pre>
</pre></div>
<p>Markdown here is <em>not</em> parsed by RDiscount.</p>
<p>Nor in <em>this</em> paragraph, and there are no paragraph breaks.</p>'
try 'nested html blocks (1)' "$BLOCK1SRC" "$BLOCK1OUT"
try 'nested html blocks (2)' \
'<div>This is inside a html block
<div>This is, too</div>and
so is this</div>' \
'<div>This is inside a html block
<div>This is, too</div>and
so is this</div>'
exit $rc
-14
View File
@@ -1,14 +0,0 @@
1. <http://automatic>
2. [automatic] (http://automatic "automatic link")
3. [automatic](http://automatic "automatic link")
4. [automatic](http://automatic)
5. [automatic] (http://automatic)
6. [automatic] []
7. [automatic][]
8. [my][automatic]
9. [my] [automatic]
[automatic]: http://automatic "footnote"
[automatic] [
-124
View File
@@ -1,124 +0,0 @@
./echo "embedded links"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try 'url contains &' '[hehehe](u&rl)' '<p><a href="u&amp;rl">hehehe</a></p>'
try 'url contains +' '[hehehe](u+rl)' '<p><a href="u+rl">hehehe</a></p>'
try 'url contains "' '[hehehe](u"rl)' '<p><a href="u%22rl">hehehe</a></p>'
try 'url contains <' '[hehehe](u<rl)' '<p><a href="u&lt;rl">hehehe</a></p>'
try 'url contains whitespace' '[ha](r u)' '<p><a href="r%20u">ha</a></p>'
try 'url contains whitespace & title' \
'[hehehe](r u "there")' \
'<p><a href="r%20u" title="there">hehehe</a></p>'
try 'url contains escaped )' \
'[hehehe](u\))' \
'<p><a href="u)">hehehe</a></p>'
try 'image label contains <' \
'![he<he<he](url)' \
'<p><img src="url" alt="he&lt;he&lt;he" /></p>'
try 'image label contains >' \
'![he>he>he](url)' \
'<p><img src="url" alt="he&gt;he&gt;he" /></p>'
try 'sloppy context link' \
'[heh]( url "how about it?" )' \
'<p><a href="url" title="how about it?">heh</a></p>'
try 'footnote urls formed properly' \
'[hehehe]: hohoho "ha ha"
[hehehe][]' \
'<p><a href="hohoho" title="ha ha">hehehe</a></p>'
try 'linky-like []s work' \
'[foo]' \
'<p>[foo]</p>'
try 'pseudo-protocol "id:"'\
'[foo](id:bar)' \
'<p><a id="bar">foo</a></p>'
try 'pseudo-protocol "class:"' \
'[foo](class:bar)' \
'<p><span class="bar">foo</span></p>'
try 'pseudo-protocol "abbr:"'\
'[foo](abbr:bar)' \
'<p><abbr title="bar">foo</abbr></p>'
try 'nested [][]s' \
'[[z](y)](x)' \
'<p><a href="x">[z](y)</a></p>'
try 'empty [][] tags' \
'[![][1]][2]
[1]: image1
[2]: image2' \
'<p><a href="image2"><img src="image1" alt="" /></a></p>'
try 'footnote cuddled up to text' \
'foo
[bar]:bar' \
'<p>foo</p>'
try 'mid-paragraph footnote' \
'talk talk talk talk
[bar]: bar
talk talk talk talk' \
'<p>talk talk talk talk
talk talk talk talk</p>'
try 'mid-blockquote footnote' \
'>blockquote!
[footnote]: here!
>blockquote!' \
'<blockquote><p>blockquote!
blockquote!</p></blockquote>'
try 'end-blockquote footnote' \
'>blockquote!
>blockquote!
[footnote]: here!' \
'<blockquote><p>blockquote!
blockquote!</p></blockquote>'
try 'start-blockquote footnote' \
'[footnote]: here!
>blockquote!
>blockquote!' \
'<blockquote><p>blockquote!
blockquote!</p></blockquote>'
try '[text] (text) not a link' \
'[test] (me)' \
'<p>[test] (me)</p>'
exit $rc
-31
View File
@@ -1,31 +0,0 @@
./echo "embedded images"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try 'image with size extension' \
'![picture](pic =200x200)' \
'<p><img src="pic" height="200" width="200" alt="picture" /></p>'
exit $rc
-168
View File
@@ -1,168 +0,0 @@
./echo "lists"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try 'two separated items' \
' * A
* B' \
'<ul>
<li><p>A</p></li>
<li><p>B</p></li>
</ul>'
try 'two adjacent items' \
' * A
* B' \
'<ul>
<li>A</li>
<li>B</li>
</ul>'
try 'two adjacent items, then space' \
' * A
* B
space, the final frontier' \
'<ul>
<li>A</li>
<li>B</li>
</ul>
<p>space, the final frontier</p>'
try 'nested lists (1)' \
' * 1. Sub (list)
2. Two (items)
3. Here' \
'<ul>
<li><ol>
<li>Sub (list)</li>
<li>Two (items)</li>
<li>Here</li>
</ol>
</li>
</ul>'
try 'nested lists (2)' \
' * A (list)
1. Sub (list)
2. Two (items)
3. Here
Here
* B (list)' \
'<ul>
<li><p>A (list)</p>
<ol>
<li>Sub (list)</li>
<li>Two (items)</li>
<li>Here</li>
</ol>
<p> Here</p></li>
<li>B (list)</li>
</ul>'
try 'list inside blockquote' \
'>A (list)
>
>1. Sub (list)
>2. Two (items)
>3. Here' \
'<blockquote><p>A (list)</p>
<ol>
<li>Sub (list)</li>
<li>Two (items)</li>
<li>Here</li>
</ol>
</blockquote>'
try 'blockquote inside list' \
' * A (list)
> quote
> me
dont quote me' \
'<ul>
<li><p>A (list)</p>
<blockquote><p>quote
me</p></blockquote>
<p>dont quote me</p></li>
</ul>'
try 'empty list' \
'
-
-
' \
'<ul>
<li></li>
<li></li>
</ul>'
if ./markdown -V | grep DL_TAG >/dev/null; then
try 'dl followed by non-dl' \
'=a=
test
2. here' \
'<dl>
<dt>a</dt>
<dd>test</dd>
</dl>
<ol>
<li>here</li>
</ol>'
try 'non-dl followed by dl' \
'1. hello
=sailor=
hi!' \
'<ol>
<li>hello</li>
</ol>
<dl>
<dt>sailor</dt>
<dd>hi!</dd>
</dl>'
fi
exit $rc
-57
View File
@@ -1,57 +0,0 @@
./echo "deeply nested lists"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
LIST='
* top-level list ( list 1)
+ second-level list (list 2)
* first item third-level list (list 3)
+ * second item, third-level list, first item. (list 4)
* second item, third-level list, second item.
* top-level list again.'
RSLT='<ul>
<li>top-level list ( list 1)
<ul>
<li>second-level list (list 2)
<ul>
<li>first item third-level list (list 3)</li>
</ul>
</li>
<li><ul>
<li>second item, third-level list, first item. (list 4)</li>
<li>second item, third-level list, second item.</li>
</ul>
</li>
</ul>
</li>
<li>top-level list again.</li>
</ul>'
try 'thrice-nested lists' "$LIST" "$RSLT"
exit $rc
-33
View File
@@ -1,33 +0,0 @@
./echo "misc"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try 'single paragraph' 'AAA' '<p>AAA</p>'
try '< -> &lt;' '<' '<p>&lt;</p>'
try '`>` -> <code>&gt;</code>' '`>`' '<p><code>&gt;</code></p>'
try '`` ` `` -> <code>`</code>' '`` ` ``' '<p><code>`</code></p>'
exit $rc
-74
View File
@@ -1,74 +0,0 @@
./echo "pandoc headers"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
HEADER='% title
% author(s)
% date'
if ./markdown -V | grep HEADER > /dev/null; then
try 'valid header' "$HEADER" ''
try -F0x0100 'valid header with -F0x0100' "$HEADER" '<p>% title
% author(s)
% date</p>'
try 'invalid header' \
'% title
% author(s)
a pony!' \
'<p>% title
% author(s)
a pony!</p>'
try 'offset header' \
'
% title
% author(s)
% date' \
'<p>% title
% author(s)
% date</p>'
try 'indented header' \
' % title
% author(s)
% date' \
'<p> % title
% author(s)
% date</p>'
else
try 'ignore headers' "$HEADER" '<p>% title
% author(s)
% date</p>'
fi
exit $rc
-38
View File
@@ -1,38 +0,0 @@
./echo "paragraph blocking"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try 'paragraph followed by code' \
'a
b' \
'<p>a</p>
<pre><code>b
</code></pre>'
try 'single-line paragraph' 'a' '<p>a</p>'
exit $rc
-31
View File
@@ -1,31 +0,0 @@
./echo "paranoia"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try -fsafelink 'bogus url (-fsafelink)' '[test](bad:protocol)' '<p>[test](bad:protocol)</p>'
try -fnosafelink 'bogus url (-fnosafelink)' '[test](bad:protocol)' '<p><a href="bad:protocol">test</a></p>'
exit $rc
-64
View File
@@ -1,64 +0,0 @@
./echo "markup peculiarities"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try 'list followed by header .......... ' \
"
- AAA
- BBB
-" \
'<ul>
<li>AAA
<h2>&ndash; BBB</h2></li>
</ul>'
try 'ul with mixed item prefixes' \
'
- A
1. B' \
'<ul>
<li>A</li>
<li>B</li>
</ul>'
try 'ol with mixed item prefixes' \
'
1. A
- B
' \
'<ol>
<li>A</li>
<li>B</li>
</ol>'
try 'forcing a <br/>' 'this ' '<p>this<br/>
</p>'
try 'trimming single spaces' 'this ' '<p>this</p>'
try -fnohtml 'markdown <br/> with -fnohtml' 'foo ' '<p>foo<br/>
</p>'
exit $rc
-35
View File
@@ -1,35 +0,0 @@
./echo "pseudo-protocols"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try '[](id:) links' '[foo](id:bar)' '<p><a id="bar">foo</a></p>'
try -fnoext '[](id:) links with -fnoext' '[foo](id:bar)' '<p>[foo](id:bar)</p>'
try '[](class:) links' '[foo](class:bar)' '<p><span class="bar">foo</span></p>'
try -fnoext '[](class:) links with -fnoext' '[foo](class:bar)' '<p>[foo](class:bar)</p>'
try '[](raw:) links' '[foo](raw:bar)' '<p>bar</p>'
try -fnoext '[](raw:) links with -fnoext' '[foo](raw:bar)' '<p>[foo](raw:bar)</p>'
exit $rc
-34
View File
@@ -1,34 +0,0 @@
./echo "footnotes inside reparse sections"
rc=0
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try 'footnote inside [] section' \
'[![foo][]](bar)
[foo]: bar2' \
'<p><a href="bar"><img src="bar2" alt="foo" /></a></p>'
exit $rc
-97
View File
@@ -1,97 +0,0 @@
./echo "Bugs & misfeatures reported by Mike Schiraldi"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
S=`./echo -n "$1" '..................................' | ./cols 34`
./echo -n " $S "
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo "ok"
else
./echo "FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try -fnohtml 'breaks with -fnohtml' 'foo ' '<p>foo<br/>
</p>'
try 'links with trailing \)' \
'[foo](http://en.wikipedia.org/wiki/Link_(film\))' \
'<p><a href="http://en.wikipedia.org/wiki/Link_(film)">foo</a></p>'
try -fautolink '(url) with -fautolink' \
'(http://tsfr.org)' \
'<p>(<a href="http://tsfr.org">http://tsfr.org</a>)</p>'
try 'single #' \
'#' \
'<p>#</p>'
try -frelax '* processing with -frelax' \
'2*4 = 8 * 1 = 2**3' \
'<p>2*4 = 8 * 1 = 2**3</p>'
try -fnopants '[]() with a single quote mark' \
'[Poe'"'"'s law](http://rationalwiki.com/wiki/Poe'"'"'s_Law)' \
'<p><a href="http://rationalwiki.com/wiki/Poe'"'"'s_Law">Poe'"'"'s law</a></p>'
try -fautolink 'autolink url with escaped spaces' \
'http://\(here\ I\ am\)' \
'<p><a href="http://(here%20I%20am)">http://(here I am)</a></p>'
try -fautolink 'autolink café_racer' \
'http://en.wikipedia.org/wiki/café_racer' \
'<p><a href="http://en.wikipedia.org/wiki/caf%C3%A9_racer">http://en.wikipedia.org/wiki/caf%C3%A9_racer</a></p>'
try -fautolink 'autolink url with arguments' \
'http://foo.bar?a&b=c' \
'<p><a href="http://foo.bar?a&amp;b=c">http://foo.bar?a&amp;b=c</a></p>'
try '\( escapes in []()' \
'[foo](http://a.com/\(foo\))' \
'<p><a href="http://a.com/(foo)">foo</a></p>'
try -fautolink 'autolink url with escaped ()' \
'http://a.com/\(foo\)' \
'<p><a href="http://a.com/(foo)">http://a.com/(foo)</a></p>'
try -fautolink 'autolink url with escaped \' \
'http://a.com/\\\)' \
'<p><a href="http://a.com/\)">http://a.com/\)</a></p>'
try -fautolink 'autolink url with -' \
'http://experts-exchange.com' \
'<p><a href="http://experts-exchange.com">http://experts-exchange.com</a></p>'
try -fautolink 'autolink url with +' \
'http://www67.wolframalpha.com/input/?i=how+old+was+jfk+jr+when+jfk+died' \
'<p><a href="http://www67.wolframalpha.com/input/?i=how+old+was+jfk+jr+when+jfk+died">http://www67.wolframalpha.com/input/?i=how+old+was+jfk+jr+when+jfk+died</a></p>'
try -fautolink 'autolink url with &' \
'http://foo.bar?a&b=c' \
'<p><a href="http://foo.bar?a&amp;b=c">http://foo.bar?a&amp;b=c</a></p>'
try -fautolink 'autolink url with ,' \
'http://www.spiegel.de/international/europe/0,1518,626171,00.html' \
'<p><a href="http://www.spiegel.de/international/europe/0,1518,626171,00.html">http://www.spiegel.de/international/europe/0,1518,626171,00.html</a></p>'
try -fautolink 'autolink url with : & ;' \
'http://www.biblegateway.com/passage/?search=Matthew%205:29-30;&version=31;' \
'<p><a href="http://www.biblegateway.com/passage/?search=Matthew%205:29-30;&amp;version=31;">http://www.biblegateway.com/passage/?search=Matthew%205:29-30;&amp;version=31;</a></p>'
exit $rc
-50
View File
@@ -1,50 +0,0 @@
./echo "smarty pants"
rc=0
MARKDOWN_FLAGS=0x0; export MARKDOWN_FLAGS
try() {
unset FLAGS
case "$1" in
-*) FLAGS="$1"
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try '(c) -> &copy;' '(c)' '<p>&copy;</p>'
try '(r) -> &reg;' '(r)' '<p>&reg;</p>'
try '(tm) -> &trade;' '(tm)' '<p>&trade;</p>'
try '... -> &hellip;' '...' '<p>&hellip;</p>'
try '"--" -> &mdash;' '--' '<p>&mdash;</p>'
try '"-" -> &ndash;' 'regular -' '<p>regular &ndash;</p>'
try 'A-B -> A-B' 'A-B' '<p>A-B</p>'
try '"fancy" -> &ldquo;fancy&rdquo;' '"fancy"' '<p>&ldquo;fancy&rdquo;</p>'
try "'fancy'" "'fancy'" '<p>&lsquo;fancy&rsquo;</p>'
try "don<b>'t -> don<b>&rsquo;t" "don<b>'t" '<p>don<b>&rsquo;t</p>'
try "don't -> don&rsquo;t" "don't" '<p>don&rsquo;t</p>'
try "it's -> it&rsquo;s" "it's" '<p>it&rsquo;s</p>'
if ./markdown -V | grep SUPERSCRIPT >/dev/null; then
try -frelax 'A^B -> A<sup>B</sup> (-frelax)' 'A^B' '<p>A<sup>B</sup></p>'
try -fstrict 'A^B != A<sup>B</sup> (-fstrict)' 'A^B' '<p>A^B</p>'
try -frelax 'A^B in link title' '[link](here "A^B")' '<p><a href="here" title="A^B">link</a></p>'
fi
exit $rc
-34
View File
@@ -1,34 +0,0 @@
./echo "The snakepit of Markdown.pl compatability"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try '[](single quote) text (quote)' \
"[foo](http://Poe's law) will make this fail ('no, it won't!') here."\
'<p><a href="http://Poe" title="s law) will make this fail ('"'no, it won't!"'">foo</a> here.</p>'
try '[](unclosed <url)' '[foo](<http://no trailing gt)' \
'<p><a href="http://no%20trailing%20gt">foo</a></p>'
exit $rc
-32
View File
@@ -1,32 +0,0 @@
./echo "styles"
rc=0
MARKDOWN_FLAGS=
./echo -n ' <style> blocks -- one line ....... '
count=`./echo '<style> ul {display:none;} </style>' | ./markdown|wc -c`
if [ $count -eq 1 ]; then
./echo "ok"
else
./echo "FAILED"
rc=1
fi
./echo -n ' <style> blocks -- multiline ...... '
ASK='<style>
ul {display:none;}
</style>'
count=`./echo "$ASK" | ./markdown | wc -c`
if [ $count -eq 1 ]; then
./echo "ok"
else
./echo "FAILED"
rc=1
fi
exit $rc
-897
View File
@@ -1,897 +0,0 @@
Markdown: Syntax
================
<ul id="ProjectSubmenu">
<li><a href="/projects/markdown/" title="Markdown Project Page">Main</a></li>
<li><a href="/projects/markdown/basics" title="Markdown Basics">Basics</a></li>
<li><a class="selected" title="Markdown Syntax Documentation">Syntax</a></li>
<li><a href="/projects/markdown/license" title="Pricing and License Information">License</a></li>
<li><a href="/projects/markdown/dingus" title="Online Markdown Web Form">Dingus</a></li>
</ul>
* [Overview](#overview)
* [Philosophy](#philosophy)
* [Inline HTML](#html)
* [Automatic Escaping for Special Characters](#autoescape)
* [Block Elements](#block)
* [Paragraphs and Line Breaks](#p)
* [Headers](#header)
* [Blockquotes](#blockquote)
* [Lists](#list)
* [Code Blocks](#precode)
* [Horizontal Rules](#hr)
* [Span Elements](#span)
* [Links](#link)
* [Emphasis](#em)
* [Code](#code)
* [Images](#img)
* [Miscellaneous](#misc)
* [Backslash Escapes](#backslash)
* [Automatic Links](#autolink)
**Note:** This document is itself written using Markdown; you
can [see the source for it by adding '.text' to the URL][src].
[src]: /projects/markdown/syntax.text
* * *
<h2 id="overview">Overview</h2>
<h3 id="philosophy">Philosophy</h3>
Markdown is intended to be as easy-to-read and easy-to-write as is feasible.
Readability, however, is emphasized above all else. A Markdown-formatted
document should be publishable as-is, as plain text, without looking
like it's been marked up with tags or formatting instructions. While
Markdown's syntax has been influenced by several existing text-to-HTML
filters -- including [Setext] [1], [atx] [2], [Textile] [3], [reStructuredText] [4],
[Grutatext] [5], and [EtText] [6] -- the single biggest source of
inspiration for Markdown's syntax is the format of plain text email.
[1]: http://docutils.sourceforge.net/mirror/setext.html
[2]: http://www.aaronsw.com/2002/atx/
[3]: http://textism.com/tools/textile/
[4]: http://docutils.sourceforge.net/rst.html
[5]: http://www.triptico.com/software/grutatxt.html
[6]: http://ettext.taint.org/doc/
To this end, Markdown's syntax is comprised entirely of punctuation
characters, which punctuation characters have been carefully chosen so
as to look like what they mean. E.g., asterisks around a word actually
look like \*emphasis\*. Markdown lists look like, well, lists. Even
blockquotes look like quoted passages of text, assuming you've ever
used email.
<h3 id="html">Inline HTML</h3>
Markdown's syntax is intended for one purpose: to be used as a
format for *writing* for the web.
Markdown is not a replacement for HTML, or even close to it. Its
syntax is very small, corresponding only to a very small subset of
HTML tags. The idea is *not* to create a syntax that makes it easier
to insert HTML tags. In my opinion, HTML tags are already easy to
insert. The idea for Markdown is to make it easy to read, write, and
edit prose. HTML is a *publishing* format; Markdown is a *writing*
format. Thus, Markdown's formatting syntax only addresses issues that
can be conveyed in plain text.
For any markup that is not covered by Markdown's syntax, you simply
use HTML itself. There's no need to preface it or delimit it to
indicate that you're switching from Markdown to HTML; you just use
the tags.
The only restrictions are that block-level HTML elements -- e.g. `<div>`,
`<table>`, `<pre>`, `<p>`, etc. -- must be separated from surrounding
content by blank lines, and the start and end tags of the block should
not be indented with tabs or spaces. Markdown is smart enough not
to add extra (unwanted) `<p>` tags around HTML block-level tags.
For example, to add an HTML table to a Markdown article:
This is a regular paragraph.
<table>
<tr>
<td>Foo</td>
</tr>
</table>
This is another regular paragraph.
Note that Markdown formatting syntax is not processed within block-level
HTML tags. E.g., you can't use Markdown-style `*emphasis*` inside an
HTML block.
Span-level HTML tags -- e.g. `<span>`, `<cite>`, or `<del>` -- can be
used anywhere in a Markdown paragraph, list item, or header. If you
want, you can even use HTML tags instead of Markdown formatting; e.g. if
you'd prefer to use HTML `<a>` or `<img>` tags instead of Markdown's
link or image syntax, go right ahead.
Unlike block-level HTML tags, Markdown syntax *is* processed within
span-level tags.
<h3 id="autoescape">Automatic Escaping for Special Characters</h3>
In HTML, there are two characters that demand special treatment: `<`
and `&`. Left angle brackets are used to start tags; ampersands are
used to denote HTML entities. If you want to use them as literal
characters, you must escape them as entities, e.g. `&lt;`, and
`&amp;`.
Ampersands in particular are bedeviling for web writers. If you want to
write about 'AT&T', you need to write '`AT&amp;T`'. You even need to
escape ampersands within URLs. Thus, if you want to link to:
http://images.google.com/images?num=30&q=larry+bird
you need to encode the URL as:
http://images.google.com/images?num=30&amp;q=larry+bird
in your anchor tag `href` attribute. Needless to say, this is easy to
forget, and is probably the single most common source of HTML validation
errors in otherwise well-marked-up web sites.
Markdown allows you to use these characters naturally, taking care of
all the necessary escaping for you. If you use an ampersand as part of
an HTML entity, it remains unchanged; otherwise it will be translated
into `&amp;`.
So, if you want to include a copyright symbol in your article, you can write:
&copy;
and Markdown will leave it alone. But if you write:
AT&T
Markdown will translate it to:
AT&amp;T
Similarly, because Markdown supports [inline HTML](#html), if you use
angle brackets as delimiters for HTML tags, Markdown will treat them as
such. But if you write:
4 < 5
Markdown will translate it to:
4 &lt; 5
However, inside Markdown code spans and blocks, angle brackets and
ampersands are *always* encoded automatically. This makes it easy to use
Markdown to write about HTML code. (As opposed to raw HTML, which is a
terrible format for writing about HTML syntax, because every single `<`
and `&` in your example code needs to be escaped.)
* * *
<h2 id="block">Block Elements</h2>
<h3 id="p">Paragraphs and Line Breaks</h3>
A paragraph is simply one or more consecutive lines of text, separated
by one or more blank lines. (A blank line is any line that looks like a
blank line -- a line containing nothing but spaces or tabs is considered
blank.) Normal paragraphs should not be indented with spaces or tabs.
The implication of the "one or more consecutive lines of text" rule is
that Markdown supports "hard-wrapped" text paragraphs. This differs
significantly from most other text-to-HTML formatters (including Movable
Type's "Convert Line Breaks" option) which translate every line break
character in a paragraph into a `<br />` tag.
When you *do* want to insert a `<br />` break tag using Markdown, you
end a line with two or more spaces, then type return.
Yes, this takes a tad more effort to create a `<br />`, but a simplistic
"every line break is a `<br />`" rule wouldn't work for Markdown.
Markdown's email-style [blockquoting][bq] and multi-paragraph [list items][l]
work best -- and look better -- when you format them with hard breaks.
[bq]: #blockquote
[l]: #list
<h3 id="header">Headers</h3>
Markdown supports two styles of headers, [Setext] [1] and [atx] [2].
Setext-style headers are "underlined" using equal signs (for first-level
headers) and dashes (for second-level headers). For example:
This is an H1
=============
This is an H2
-------------
Any number of underlining `=`'s or `-`'s will work.
Atx-style headers use 1-6 hash characters at the start of the line,
corresponding to header levels 1-6. For example:
# This is an H1
## This is an H2
###### This is an H6
Optionally, you may "close" atx-style headers. This is purely
cosmetic -- you can use this if you think it looks better. The
closing hashes don't even need to match the number of hashes
used to open the header. (The number of opening hashes
determines the header level.) :
# This is an H1 #
## This is an H2 ##
### This is an H3 ######
<h3 id="blockquote">Blockquotes</h3>
Markdown uses email-style `>` characters for blockquoting. If you're
familiar with quoting passages of text in an email message, then you
know how to create a blockquote in Markdown. It looks best if you hard
wrap the text and put a `>` before every line:
> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
> consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
> Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
>
> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
> id sem consectetuer libero luctus adipiscing.
Markdown allows you to be lazy and only put the `>` before the first
line of a hard-wrapped paragraph:
> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
id sem consectetuer libero luctus adipiscing.
Blockquotes can be nested (i.e. a blockquote-in-a-blockquote) by
adding additional levels of `>`:
> This is the first level of quoting.
>
> > This is nested blockquote.
>
> Back to the first level.
Blockquotes can contain other Markdown elements, including headers, lists,
and code blocks:
> ## This is a header.
>
> 1. This is the first list item.
> 2. This is the second list item.
>
> Here's some example code:
>
> return shell_exec("echo $input | $markdown_script");
Any decent text editor should make email-style quoting easy. For
example, with BBEdit, you can make a selection and choose Increase
Quote Level from the Text menu.
<h3 id="list">Lists</h3>
Markdown supports ordered (numbered) and unordered (bulleted) lists.
Unordered lists use asterisks, pluses, and hyphens -- interchangably
-- as list markers:
* Red
* Green
* Blue
is equivalent to:
+ Red
+ Green
+ Blue
and:
- Red
- Green
- Blue
Ordered lists use numbers followed by periods:
1. Bird
2. McHale
3. Parish
It's important to note that the actual numbers you use to mark the
list have no effect on the HTML output Markdown produces. The HTML
Markdown produces from the above list is:
<ol>
<li>Bird</li>
<li>McHale</li>
<li>Parish</li>
</ol>
If you instead wrote the list in Markdown like this:
1. Bird
1. McHale
1. Parish
or even:
3. Bird
1. McHale
8. Parish
you'd get the exact same HTML output. The point is, if you want to,
you can use ordinal numbers in your ordered Markdown lists, so that
the numbers in your source match the numbers in your published HTML.
But if you want to be lazy, you don't have to.
If you do use lazy list numbering, however, you should still start the
list with the number 1. At some point in the future, Markdown may support
starting ordered lists at an arbitrary number.
List markers typically start at the left margin, but may be indented by
up to three spaces. List markers must be followed by one or more spaces
or a tab.
To make lists look nice, you can wrap items with hanging indents:
* Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
viverra nec, fringilla in, laoreet vitae, risus.
* Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
Suspendisse id sem consectetuer libero luctus adipiscing.
But if you want to be lazy, you don't have to:
* Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
viverra nec, fringilla in, laoreet vitae, risus.
* Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
Suspendisse id sem consectetuer libero luctus adipiscing.
If list items are separated by blank lines, Markdown will wrap the
items in `<p>` tags in the HTML output. For example, this input:
* Bird
* Magic
will turn into:
<ul>
<li>Bird</li>
<li>Magic</li>
</ul>
But this:
* Bird
* Magic
will turn into:
<ul>
<li><p>Bird</p></li>
<li><p>Magic</p></li>
</ul>
List items may consist of multiple paragraphs. Each subsequent
paragraph in a list item must be intended by either 4 spaces
or one tab:
1. This is a list item with two paragraphs. Lorem ipsum dolor
sit amet, consectetuer adipiscing elit. Aliquam hendrerit
mi posuere lectus.
Vestibulum enim wisi, viverra nec, fringilla in, laoreet
vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
sit amet velit.
2. Suspendisse id sem consectetuer libero luctus adipiscing.
It looks nice if you indent every line of the subsequent
paragraphs, but here again, Markdown will allow you to be
lazy:
* This is a list item with two paragraphs.
This is the second paragraph in the list item. You're
only required to indent the first line. Lorem ipsum dolor
sit amet, consectetuer adipiscing elit.
* Another item in the same list.
To put a blockquote within a list item, the blockquote's `>`
delimiters need to be indented:
* A list item with a blockquote:
> This is a blockquote
> inside a list item.
To put a code block within a list item, the code block needs
to be indented *twice* -- 8 spaces or two tabs:
* A list item with a code block:
<code goes here>
It's worth noting that it's possible to trigger an ordered list by
accident, by writing something like this:
1986. What a great season.
In other words, a *number-period-space* sequence at the beginning of a
line. To avoid this, you can backslash-escape the period:
1986\. What a great season.
<h3 id="precode">Code Blocks</h3>
Pre-formatted code blocks are used for writing about programming or
markup source code. Rather than forming normal paragraphs, the lines
of a code block are interpreted literally. Markdown wraps a code block
in both `<pre>` and `<code>` tags.
To produce a code block in Markdown, simply indent every line of the
block by at least 4 spaces or 1 tab. For example, given this input:
This is a normal paragraph:
This is a code block.
Markdown will generate:
<p>This is a normal paragraph:</p>
<pre><code>This is a code block.
</code></pre>
One level of indentation -- 4 spaces or 1 tab -- is removed from each
line of the code block. For example, this:
Here is an example of AppleScript:
tell application "Foo"
beep
end tell
will turn into:
<p>Here is an example of AppleScript:</p>
<pre><code>tell application "Foo"
beep
end tell
</code></pre>
A code block continues until it reaches a line that is not indented
(or the end of the article).
Within a code block, ampersands (`&`) and angle brackets (`<` and `>`)
are automatically converted into HTML entities. This makes it very
easy to include example HTML source code using Markdown -- just paste
it and indent it, and Markdown will handle the hassle of encoding the
ampersands and angle brackets. For example, this:
<div class="footer">
&copy; 2004 Foo Corporation
</div>
will turn into:
<pre><code>&lt;div class="footer"&gt;
&amp;copy; 2004 Foo Corporation
&lt;/div&gt;
</code></pre>
Regular Markdown syntax is not processed within code blocks. E.g.,
asterisks are just literal asterisks within a code block. This means
it's also easy to use Markdown to write about Markdown's own syntax.
<h3 id="hr">Horizontal Rules</h3>
You can produce a horizontal rule tag (`<hr />`) by placing three or
more hyphens, asterisks, or underscores on a line by themselves. If you
wish, you may use spaces between the hyphens or asterisks. Each of the
following lines will produce a horizontal rule:
* * *
***
*****
- - -
---------------------------------------
* * *
<h2 id="span">Span Elements</h2>
<h3 id="link">Links</h3>
Markdown supports two style of links: *inline* and *reference*.
In both styles, the link text is delimited by [square brackets].
To create an inline link, use a set of regular parentheses immediately
after the link text's closing square bracket. Inside the parentheses,
put the URL where you want the link to point, along with an *optional*
title for the link, surrounded in quotes. For example:
This is [an example](http://example.com/ "Title") inline link.
[This link](http://example.net/) has no title attribute.
Will produce:
<p>This is <a href="http://example.com/" title="Title">
an example</a> inline link.</p>
<p><a href="http://example.net/">This link</a> has no
title attribute.</p>
If you're referring to a local resource on the same server, you can
use relative paths:
See my [About](/about/) page for details.
Reference-style links use a second set of square brackets, inside
which you place a label of your choosing to identify the link:
This is [an example][id] reference-style link.
You can optionally use a space to separate the sets of brackets:
This is [an example] [id] reference-style link.
Then, anywhere in the document, you define your link label like this,
on a line by itself:
[id]: http://example.com/ "Optional Title Here"
That is:
* Square brackets containing the link identifier (optionally
indented from the left margin using up to three spaces);
* followed by a colon;
* followed by one or more spaces (or tabs);
* followed by the URL for the link;
* optionally followed by a title attribute for the link, enclosed
in double or single quotes, or enclosed in parentheses.
The following three link definitions are equivalent:
[foo]: http://example.com/ "Optional Title Here"
[foo]: http://example.com/ 'Optional Title Here'
[foo]: http://example.com/ (Optional Title Here)
**Note:** There is a known bug in Markdown.pl 1.0.1 which prevents
single quotes from being used to delimit link titles.
The link URL may, optionally, be surrounded by angle brackets:
[id]: <http://example.com/> "Optional Title Here"
You can put the title attribute on the next line and use extra spaces
or tabs for padding, which tends to look better with longer URLs:
[id]: http://example.com/longish/path/to/resource/here
"Optional Title Here"
Link definitions are only used for creating links during Markdown
processing, and are stripped from your document in the HTML output.
Link definition names may constist of letters, numbers, spaces, and
punctuation -- but they are *not* case sensitive. E.g. these two
links:
[link text][a]
[link text][A]
are equivalent.
The *implicit link name* shortcut allows you to omit the name of the
link, in which case the link text itself is used as the name.
Just use an empty set of square brackets -- e.g., to link the word
"Google" to the google.com web site, you could simply write:
[Google][]
And then define the link:
[Google]: http://google.com/
Because link names may contain spaces, this shortcut even works for
multiple words in the link text:
Visit [Daring Fireball][] for more information.
And then define the link:
[Daring Fireball]: http://daringfireball.net/
Link definitions can be placed anywhere in your Markdown document. I
tend to put them immediately after each paragraph in which they're
used, but if you want, you can put them all at the end of your
document, sort of like footnotes.
Here's an example of reference links in action:
I get 10 times more traffic from [Google] [1] than from
[Yahoo] [2] or [MSN] [3].
[1]: http://google.com/ "Google"
[2]: http://search.yahoo.com/ "Yahoo Search"
[3]: http://search.msn.com/ "MSN Search"
Using the implicit link name shortcut, you could instead write:
I get 10 times more traffic from [Google][] than from
[Yahoo][] or [MSN][].
[google]: http://google.com/ "Google"
[yahoo]: http://search.yahoo.com/ "Yahoo Search"
[msn]: http://search.msn.com/ "MSN Search"
Both of the above examples will produce the following HTML output:
<p>I get 10 times more traffic from <a href="http://google.com/"
title="Google">Google</a> than from
<a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a>
or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>
For comparison, here is the same paragraph written using
Markdown's inline link style:
I get 10 times more traffic from [Google](http://google.com/ "Google")
than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or
[MSN](http://search.msn.com/ "MSN Search").
The point of reference-style links is not that they're easier to
write. The point is that with reference-style links, your document
source is vastly more readable. Compare the above examples: using
reference-style links, the paragraph itself is only 81 characters
long; with inline-style links, it's 176 characters; and as raw HTML,
it's 234 characters. In the raw HTML, there's more markup than there
is text.
With Markdown's reference-style links, a source document much more
closely resembles the final output, as rendered in a browser. By
allowing you to move the markup-related metadata out of the paragraph,
you can add links without interrupting the narrative flow of your
prose.
<h3 id="em">Emphasis</h3>
Markdown treats asterisks (`*`) and underscores (`_`) as indicators of
emphasis. Text wrapped with one `*` or `_` will be wrapped with an
HTML `<em>` tag; double `*`'s or `_`'s will be wrapped with an HTML
`<strong>` tag. E.g., this input:
*single asterisks*
_single underscores_
**double asterisks**
__double underscores__
will produce:
<em>single asterisks</em>
<em>single underscores</em>
<strong>double asterisks</strong>
<strong>double underscores</strong>
You can use whichever style you prefer; the lone restriction is that
the same character must be used to open and close an emphasis span.
Emphasis can be used in the middle of a word:
un*fucking*believable
But if you surround an `*` or `_` with spaces, it'll be treated as a
literal asterisk or underscore.
To produce a literal asterisk or underscore at a position where it
would otherwise be used as an emphasis delimiter, you can backslash
escape it:
\*this text is surrounded by literal asterisks\*
<h3 id="code">Code</h3>
To indicate a span of code, wrap it with backtick quotes (`` ` ``).
Unlike a pre-formatted code block, a code span indicates code within a
normal paragraph. For example:
Use the `printf()` function.
will produce:
<p>Use the <code>printf()</code> function.</p>
To include a literal backtick character within a code span, you can use
multiple backticks as the opening and closing delimiters:
``There is a literal backtick (`) here.``
which will produce this:
<p><code>There is a literal backtick (`) here.</code></p>
The backtick delimiters surrounding a code span may include spaces --
one after the opening, one before the closing. This allows you to place
literal backtick characters at the beginning or end of a code span:
A single backtick in a code span: `` ` ``
A backtick-delimited string in a code span: `` `foo` ``
will produce:
<p>A single backtick in a code span: <code>`</code></p>
<p>A backtick-delimited string in a code span: <code>`foo`</code></p>
With a code span, ampersands and angle brackets are encoded as HTML
entities automatically, which makes it easy to include example HTML
tags. Markdown will turn this:
Please don't use any `<blink>` tags.
into:
<p>Please don't use any <code>&lt;blink&gt;</code> tags.</p>
You can write this:
`&#8212;` is the decimal-encoded equivalent of `&mdash;`.
to produce:
<p><code>&amp;#8212;</code> is the decimal-encoded
equivalent of <code>&amp;mdash;</code>.</p>
<h3 id="img">Images</h3>
Admittedly, it's fairly difficult to devise a "natural" syntax for
placing images into a plain text document format.
Markdown uses an image syntax that is intended to resemble the syntax
for links, allowing for two styles: *inline* and *reference*.
Inline image syntax looks like this:
![Alt text](/path/to/img.jpg)
![Alt text](/path/to/img.jpg "Optional title")
That is:
* An exclamation mark: `!`;
* followed by a set of square brackets, containing the `alt`
attribute text for the image;
* followed by a set of parentheses, containing the URL or path to
the image, and an optional `title` attribute enclosed in double
or single quotes.
Reference-style image syntax looks like this:
![Alt text][id]
Where "id" is the name of a defined image reference. Image references
are defined using syntax identical to link references:
[id]: url/to/image "Optional title attribute"
As of this writing, Markdown has no syntax for specifying the
dimensions of an image; if this is important to you, you can simply
use regular HTML `<img>` tags.
* * *
<h2 id="misc">Miscellaneous</h2>
<h3 id="autolink">Automatic Links</h3>
Markdown supports a shortcut style for creating "automatic" links for URLs and email addresses: simply surround the URL or email address with angle brackets. What this means is that if you want to show the actual text of a URL or email address, and also have it be a clickable link, you can do this:
<http://example.com/>
Markdown will turn this into:
<a href="http://example.com/">http://example.com/</a>
Automatic links for email addresses work similarly, except that
Markdown will also perform a bit of randomized decimal and hex
entity-encoding to help obscure your address from address-harvesting
spambots. For example, Markdown will turn this:
<address@example.com>
into something like this:
<a href="&#x6D;&#x61;i&#x6C;&#x74;&#x6F;:&#x61;&#x64;&#x64;&#x72;&#x65;
&#115;&#115;&#64;&#101;&#120;&#x61;&#109;&#x70;&#x6C;e&#x2E;&#99;&#111;
&#109;">&#x61;&#x64;&#x64;&#x72;&#x65;&#115;&#115;&#64;&#101;&#120;&#x61;
&#109;&#x70;&#x6C;e&#x2E;&#99;&#111;&#109;</a>
which will render in a browser as a clickable link to "address@example.com".
(This sort of entity-encoding trick will indeed fool many, if not
most, address-harvesting bots, but it definitely won't fool all of
them. It's better than nothing, but an address published in this way
will probably eventually start receiving spam.)
<h3 id="backslash">Backslash Escapes</h3>
Markdown allows you to use backslash escapes to generate literal
characters which would otherwise have special meaning in Markdown's
formatting syntax. For example, if you wanted to surround a word with
literal asterisks (instead of an HTML `<em>` tag), you can backslashes
before the asterisks, like this:
\*literal asterisks\*
Markdown provides backslash escapes for the following characters:
\ backslash
` backtick
* asterisk
_ underscore
{} curly braces
[] square brackets
() parentheses
# hash mark
+ plus sign
- minus sign (hyphen)
. dot
! exclamation mark
-164
View File
@@ -1,164 +0,0 @@
./echo "tables"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try 'single-column table' \
'|hello
|-----
|sailor' \
'<table>
<thead>
<tr>
<th></th>
<th>hello</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td>sailor</td>
</tr>
</tbody>
</table>'
try 'two-column table' \
'
a | b
-----|------
hello|sailor' \
'<table>
<thead>
<tr>
<th> a </th>
<th> b</th>
</tr>
</thead>
<tbody>
<tr>
<td>hello</td>
<td>sailor</td>
</tr>
</tbody>
</table>'
try 'three-column table' \
'a|b|c
-|-|-
hello||sailor'\
'<table>
<thead>
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
</tr>
</thead>
<tbody>
<tr>
<td>hello</td>
<td></td>
<td>sailor</td>
</tr>
</tbody>
</table>'
try 'two-column table with empty cells' \
'
a | b
-----|------
hello|
|sailor' \
'<table>
<thead>
<tr>
<th> a </th>
<th> b</th>
</tr>
</thead>
<tbody>
<tr>
<td>hello</td>
<td></td>
</tr>
<tr>
<td> </td>
<td>sailor</td>
</tr>
</tbody>
</table>'
try 'two-column table with alignment' \
'
a | b
----:|:-----
hello|sailor' \
'<table>
<thead>
<tr>
<th align="right"> a </th>
<th align="left"> b</th>
</tr>
</thead>
<tbody>
<tr>
<td align="right">hello</td>
<td align="left">sailor</td>
</tr>
</tbody>
</table>'
try 'table with extra data column' \
'
a | b
-----|------
hello|sailor|boy' \
'<table>
<thead>
<tr>
<th> a </th>
<th> b</th>
</tr>
</thead>
<tbody>
<tr>
<td>hello</td>
<td>sailor|boy</td>
</tr>
</tbody>
</table>'
try -fnotables 'tables with -fnotables' \
'a|b
-|-
hello|sailor' \
'<p>a|b
&ndash;|&ndash;
hello|sailor</p>'
exit $rc
-66
View File
@@ -1,66 +0,0 @@
rc=0
unset MARKDOWN_FLAGS
unset MKD_TABSTOP
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
eval `./markdown -V | tr ' ' '\n' | grep TAB`
if [ "${TAB:-4}" -eq 8 ]; then
./echo "dealing with tabstop derangement"
LIST='
* A
* B
* C'
try 'markdown with TAB=8' \
"$LIST" \
'<ul>
<li>A
<ul>
<li>B
<ul>
<li>C</li>
</ul>
</li>
</ul>
</li>
</ul>'
try -F0x0200 'markdown with TAB=4' \
"$LIST" \
'<ul>
<li>A
<ul>
<li>B</li>
<li>C</li>
</ul>
</li>
</ul>'
fi
exit $rc
-41
View File
@@ -1,41 +0,0 @@
./echo "table-of-contents support"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
Q=`./echo "$2" | ./markdown $FLAGS`
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try '-T -ftoc' 'table of contents' \
'#H1
hi' \
'
<ul>
<li><a href="#H1">H1</a> </li>
</ul>
<h1 id="H1">H1</h1>
<p>hi</p>'
exit $rc
-39
View File
@@ -1,39 +0,0 @@
./echo "xml output with MKD_CDATA"
rc=0
MARKDOWN_FLAGS=
try() {
unset FLAGS
case "$1" in
-*) FLAGS=$1
shift ;;
esac
./echo -n " $1" '..................................' | ./cols 36
case "$2" in
-t*) Q=`./markdown $FLAGS "$2"` ;;
*) Q=`./echo "$2" | ./markdown $FLAGS` ;;
esac
if [ "$3" = "$Q" ]; then
./echo " ok"
else
./echo " FAILED"
./echo "wanted: $3"
./echo "got : $Q"
rc=1
fi
}
try -fcdata 'xml output from markdown()' 'hello,sailor' '&lt;p&gt;hello,sailor&lt;/p&gt;'
try -fcdata 'from mkd_generateline()' -t'"hello,sailor"' '&amp;ldquo;hello,sailor&amp;rdquo;'
try -fnocdata 'html output from markdown()' '"hello,sailor"' '<p>&ldquo;hello,sailor&rdquo;</p>'
try -fnocdata '... from mkd_generateline()' -t'"hello,sailor"' '&ldquo;hello,sailor&rdquo;'
try -fcdata 'xml output with multibyte utf-8' \
'tecnología y servicios más confiables' \
'&lt;p&gt;tecnología y servicios más confiables&lt;/p&gt;'
exit $rc
-142
View File
@@ -1,142 +0,0 @@
.\" %A%
.\"
.Dd January 23, 2008
.Dt THEME 1
.Os MASTODON
.Sh NAME
.Nm theme
.Nd create a web page from a template file
.Sh SYNOPSIS
.Nm
.Op Fl d Pa root
.Op Fl f
.Op Fl o Pa file
.Op Fl p Pa pagename
.Op Fl t Pa template
.Op Fl V
.Op Pa textfile
.Sh DESCRIPTION
The
.Nm
utility takes a
.Xr markdown 7 Ns -formatted
.Pa textfile
.Pq or stdin if not specified,
compiles it, and combines it with a
.Em template
.Po
.Pa page.theme
by default
.Pc
to produce a web page. If a path to the
template is not specified,
.Nm
looks for
.Pa page.theme
in the current directory, then each parent directory up to the
.Pa "document root"
.Po
set with
.Fl d
or, if unset, the
.Em "root directory"
of the system.
.Pc
If
.Pa page.theme
is found,
.Nm
copies it to the output, looking for
.Em "<?theme action?>"
html tags and processing the embedded
.Ar action
as appropriate.
.Pp
.Nm
processes the following actions:
.Bl -tag -width "include("
.It Ar author
Prints the author name(s) from the
.Xr mkd_doc_author 3
function.
.It Ar body
Prints the formatted
.Xr markdown 7
input file.
.It Ar date
Prints the date returned by
.Xr mkd_doc_date 3
or, if none, the
date the input file was last modified.
.It Ar dir
Prints the directory part of the pagename
.It Ar include Ns Pq Pa file
Prints the contents of
.Pa file .
.Xr Markdown 7
translation will
.Em NOT
be done on this file.
.It Ar source
The filename part of the pagename.
.It Ar style
Print any stylesheets
.Pq see Xr mkd-extensions 7
found in the input file.
.It Ar title
Print the title returned by
.Xr mkd_doc_title 3 ,
or, if that does not exist, the source filename.
.It Ar version
Print the version of
.Xr discount 7
that this copy of theme was compiled with.
.El
.Pp
If input is coming from a file and the output was not set with the
.Ar o
option,
.Nm writes the output to
.Pa file-sans-text.html
.Pq if
.Ar file
has a
.Pa .text
suffix, that will be stripped off and replaced with
.Pa .html ;
otherwise a
.Pa .html
will be appended to the end of the filename.)
.Pp
The options are as follows:
.Bl -tag -width "-o file"
.It Fl d Pa root
Set the
.Em "document root"
to
.Ar root
.It Fl f
Forcibly overwrite existing html files.
.It Fl o Pa filename
Write the output to
.Ar filename .
.It Fl p Ar path
Set the pagename to
.Ar path .
.It Fl t Ar filename
Use
.Ar filename
as the template file.
.El
.Sh RETURN VALUES
The
.Nm
utility exits 0 on success, and >0 if an error occurs.
.Sh SEE ALSO
.Xr markdown 1 ,
.Xr markdown 3 ,
.Xr markdown 7 ,
.Xr mkd-extensions 7 .
.Sh AUTHOR
.An David Parsons
.Pq Li orc@pell.chi.il.us
-593
View File
@@ -1,593 +0,0 @@
/*
* theme: use a template to create a webpage (markdown-style)
*
* usage: theme [-d root] [-p pagename] [-t template] [-o html] [source]
*
*/
/*
* Copyright (C) 2007 David L Parsons.
* The redistribution terms are provided in the COPYRIGHT file that must
* be distributed with this source code.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(HAVE_BASENAME) && defined(HAVE_LIBGEN_H)
# include <libgen.h>
#endif
#include <unistd.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#if HAVE_PWD_H
# include <pwd.h>
#endif
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
#include "mkdio.h"
#include "cstring.h"
#include "amalloc.h"
char *pgm = "theme";
char *output = 0;
char *pagename = 0;
char *root = 0;
#if HAVE_PWD_H
struct passwd *me = 0;
#endif
struct stat *infop = 0;
#ifndef HAVE_BASENAME
char *
basename(char *path)
{
char *p;
if (( p = strrchr(path, '/') ))
return 1+p;
return path;
}
#endif
#ifdef HAVE_FCHDIR
typedef int HERE;
#define NOT_HERE (-1)
#define pushd(d) open(d, O_RDONLY)
int
popd(HERE pwd)
{
int rc = fchdir(pwd);
close(pwd);
return rc;
}
#else
typedef char* HERE;
#define NOT_HERE 0
HERE
pushd(char *d)
{
HERE cwd;
int size;
if ( chdir(d) == -1 )
return NOT_HERE;
for (cwd = malloc(size=40); cwd; cwd = realloc(cwd, size *= 2))
if ( getcwd(cwd, size) )
return cwd;
return NOT_HERE;
}
int
popd(HERE pwd)
{
if ( pwd ) {
int rc = chdir(pwd);
free(pwd);
return rc;
}
return -1;
}
#endif
typedef STRING(int) Istring;
void
fail(char *why, ...)
{
va_list ptr;
va_start(ptr,why);
fprintf(stderr, "%s: ", pgm);
vfprintf(stderr, why, ptr);
fputc('\n', stderr);
va_end(ptr);
exit(1);
}
/* open_template() -- start at the current directory and work up,
* looking for the deepest nested template.
* Stop looking when we reach $root or /
*/
FILE *
open_template(char *template)
{
char *cwd;
int szcwd;
HERE here = pushd(".");
FILE *ret;
if ( here == NOT_HERE )
fail("cannot access the current directory");
szcwd = root ? 1 + strlen(root) : 2;
if ( (cwd = malloc(szcwd)) == 0 )
return 0;
while ( !(ret = fopen(template, "r")) ) {
if ( getcwd(cwd, szcwd) == 0 ) {
if ( errno == ERANGE )
goto up;
break;
}
if ( root && (strcmp(root, cwd) == 0) )
break; /* ran out of paths to search */
else if ( (strcmp(cwd, "/") == 0) || (*cwd == 0) )
break; /* reached / */
up: if ( chdir("..") == -1 )
break;
}
free(cwd);
popd(here);
return ret;
} /* open_template */
static Istring inbuf;
static int psp;
static int
prepare(FILE *input)
{
int c;
CREATE(inbuf);
psp = 0;
while ( (c = getc(input)) != EOF )
EXPAND(inbuf) = c;
fclose(input);
return 1;
}
static int
pull()
{
return psp < S(inbuf) ? T(inbuf)[psp++] : EOF;
}
static int
peek(int offset)
{
int pos = (psp + offset)-1;
if ( pos >= 0 && pos < S(inbuf) )
return T(inbuf)[pos];
return EOF;
}
static int
shift(int shiftwidth)
{
psp += shiftwidth;
return psp;
}
static int*
cursor()
{
return T(inbuf) + psp;
}
static int
thesame(int *p, char *pat)
{
int i;
for ( i=0; pat[i]; i++ ) {
if ( pat[i] == ' ' ) {
if ( !isspace(peek(i+1)) ) {
return 0;
}
}
else if ( tolower(peek(i+1)) != pat[i] ) {
return 0;
}
}
return 1;
}
static int
istag(int *p, char *pat)
{
int c;
if ( thesame(p, pat) ) {
c = peek(strlen(pat)+1);
return (c == '>' || isspace(c));
}
return 0;
}
/* finclude() includes some (unformatted) source
*/
static void
finclude(MMIOT *doc, FILE *out, int flags)
{
int c;
Cstring include;
FILE *f;
CREATE(include);
while ( (c = pull()) != '(' )
;
while ( (c=pull()) != ')' && c != EOF )
EXPAND(include) = c;
if ( c != EOF ) {
EXPAND(include) = 0;
S(include)--;
if (( f = fopen(T(include), "r") )) {
while ( (c = getc(f)) != EOF )
putc(c, out);
fclose(f);
}
}
DELETE(include);
}
/* fdirname() prints out the directory part of a path
*/
static void
fdirname(MMIOT *doc, FILE *output, int flags)
{
char *p;
if ( pagename && (p = basename(pagename)) )
fwrite(pagename, strlen(pagename)-strlen(p), 1, output);
}
/* fbasename() prints out the file name part of a path
*/
static void
fbasename(MMIOT *doc, FILE *output, int flags)
{
char *p;
if ( pagename ) {
p = basename(pagename);
if ( !p )
p = pagename;
if ( p )
fwrite(p, strlen(p), 1, output);
}
}
/* ftitle() prints out the document title
*/
static void
ftitle(MMIOT *doc, FILE* output, int flags)
{
char *h;
if ( (h = mkd_doc_title(doc)) == 0 && pagename )
h = pagename;
if ( h )
mkd_generateline(h, strlen(h), output, flags);
}
/* fdate() prints out the document date
*/
static void
fdate(MMIOT *doc, FILE *output, int flags)
{
char *h = infop ? ctime(&infop->st_mtime) : mkd_doc_date(doc);
if ( h )
mkd_generateline(h, strlen(h), output, flags|MKD_TAGTEXT);
}
/* fauthor() prints out the document author
*/
static void
fauthor(MMIOT *doc, FILE *output, int flags)
{
char *h = mkd_doc_author(doc);
#if HAVE_PWD_H
if ( (h == 0) && me )
h = me->pw_gecos;
#endif
if ( h )
mkd_generateline(h, strlen(h), output, flags);
}
/* fversion() prints out the document version
*/
static void
fversion(MMIOT *doc, FILE *output, int flags)
{
fwrite(markdown_version, strlen(markdown_version), 1, output);
}
/* fbody() prints out the document
*/
static void
fbody(MMIOT *doc, FILE *output, int flags)
{
mkd_generatehtml(doc, output);
}
/* ftoc() prints out the table of contents
*/
static void
ftoc(MMIOT *doc, FILE *output, int flags)
{
mkd_generatetoc(doc, output);
}
/* fstyle() prints out the document's style section
*/
static void
fstyle(MMIOT *doc, FILE *output, int flags)
{
mkd_generatecss(doc, output);
}
#define INTAG 0x01
#define INHEAD 0x02
#define INBODY 0x04
/*
* theme expansions we love:
* <?theme date?> -- the document date (file or header date)
* <?theme title?> -- the document title (header title or document name)
* <?theme author?> -- the document author (header author or document owner)
* <?theme version?> -- the version#
* <?theme body?> -- the document body
* <?theme source?> -- the filename part of the document name
* <?theme dir?> -- the directory part of the document name
* <?theme html?> -- the html file name
* <?theme style?> -- document-supplied style blocks
* <?theme include(file)?> -- include a file.
*/
static struct _keyword {
char *kw;
int where;
void (*what)(MMIOT*,FILE*,int);
} keyword[] = {
{ "author?>", 0xffff, fauthor },
{ "body?>", INBODY, fbody },
{ "toc?>", INBODY, ftoc },
{ "date?>", 0xffff, fdate },
{ "dir?>", 0xffff, fdirname },
{ "include(", 0xffff, finclude },
{ "source?>", 0xffff, fbasename },
{ "style?>", INHEAD, fstyle },
{ "title?>", 0xffff, ftitle },
{ "version?>", 0xffff, fversion },
};
#define NR(x) (sizeof x / sizeof x[0])
/* spin() - run through the theme template, looking for <?theme expansions
*/
void
spin(FILE *template, MMIOT *doc, FILE *output)
{
int c;
int *p;
int flags;
int where = 0x0;
int i;
prepare(template);
while ( (c = pull()) != EOF ) {
if ( c == '<' ) {
if ( peek(1) == '!' && peek(2) == '-' && peek(3) == '-' ) {
fputs("<!--", output);
shift(3);
do {
putc(c=pull(), output);
} while ( ! (c == '-' && peek(1) == '-' && peek(2) == '>') );
}
else if ( (peek(1) == '?') && thesame(cursor(), "?theme ") ) {
shift(strlen("?theme "));
while ( ((c = pull()) != EOF) && isspace(c) )
;
shift(-1);
p = cursor();
if ( where & INTAG )
flags = MKD_TAGTEXT;
else if ( where & INHEAD )
flags = MKD_NOIMAGE|MKD_NOLINKS;
else
flags = 0;
for (i=0; i < NR(keyword); i++)
if ( thesame(p, keyword[i].kw) ) {
if ( keyword[i].where & where )
(*keyword[i].what)(doc,output,flags);
break;
}
while ( (c = pull()) != EOF && (c != '?' && peek(1) != '>') )
;
shift(1);
}
else
putc(c, output);
if ( istag(cursor(), "head") ) {
where |= INHEAD;
where &= ~INBODY;
}
else if ( istag(cursor(), "body") ) {
where &= ~INHEAD;
where |= INBODY;
}
where |= INTAG;
continue;
}
else if ( c == '>' )
where &= ~INTAG;
putc(c, output);
}
} /* spin */
void
main(argc, argv)
char **argv;
{
char *template = "page.theme";
char *source = "stdin";
FILE *tmplfile;
int opt;
int force = 0;
MMIOT *doc;
struct stat sourceinfo;
opterr=1;
pgm = basename(argv[0]);
while ( (opt=getopt(argc, argv, "fd:t:p:o:V")) != EOF ) {
switch (opt) {
case 'd': root = optarg;
break;
case 'p': pagename = optarg;
break;
case 'f': force = 1;
break;
case 't': template = optarg;
break;
case 'o': output = optarg;
break;
case 'V': printf("theme+discount %s\n", markdown_version);
exit(0);
default: fprintf(stderr, "usage: %s [-V] [-d dir] [-p pagename] [-t template] [-o html] [file]\n", pgm);
exit(1);
}
}
tmplfile = open_template(template);
argc -= optind;
argv += optind;
if ( argc > 0 ) {
int added_text=0;
if ( (source = malloc(strlen(argv[0]) + strlen("/index.text") + 1)) == 0 )
fail("out of memory allocating name buffer");
strcpy(source,argv[0]);
if ( (stat(source, &sourceinfo) == 0) && S_ISDIR(sourceinfo.st_mode) )
strcat(source, "/index");
if ( !freopen(source, "r", stdin) ) {
strcat(source, ".text");
added_text = 1;
if ( !freopen(source, "r", stdin) )
fail("can't open either %s or %s", argv[0], source);
}
if ( !output ) {
char *p, *q;
output = alloca(strlen(source) + strlen(".html") + 1);
strcpy(output, source);
if (( p = strchr(output, '/') ))
q = strrchr(p+1, '.');
else
q = strrchr(output, '.');
if ( q )
*q = 0;
strcat(q, ".html");
}
}
if ( output ) {
if ( force )
unlink(output);
if ( !freopen(output, "w", stdout) )
fail("can't write to %s", output);
}
if ( !pagename )
pagename = source;
if ( (doc = mkd_in(stdin, 0)) == 0 )
fail("can't read %s", source ? source : "stdin");
if ( fstat(fileno(stdin), &sourceinfo) == 0 )
infop = &sourceinfo;
#if HAVE_GETPWUID
me = getpwuid(infop ? infop->st_uid : getuid());
if ( (root = strdup(me->pw_dir)) == 0 )
fail("out of memory");
#endif
if ( !mkd_compile(doc, MKD_TOC) )
fail("couldn't compile input");
if ( tmplfile )
spin(tmplfile,doc,stdout);
else
mkd_generatehtml(doc, stdout);
mkd_cleanup(doc);
exit(0);
}
-90
View File
@@ -1,90 +0,0 @@
/*
* toc -- spit out a table of contents based on header blocks
*
* Copyright (C) 2008 Jjgod Jiang, David L Parsons.
* The redistribution terms are provided in the COPYRIGHT file that must
* be distributed with this source code.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "cstring.h"
#include "markdown.h"
#include "amalloc.h"
/* write an header index
*/
int
mkd_toc(Document *p, char **doc)
{
Paragraph *tp, *srcp;
int last_hnumber = 0;
Cstring res;
CREATE(res);
RESERVE(res, 100);
*doc = 0;
if ( !(p && p->ctx) ) return -1;
if ( ! (p->ctx->flags & TOC) ) return 0;
for ( tp = p->code; tp ; tp = tp->next ) {
if ( tp->typ == SOURCE ) {
for ( srcp = tp->down; srcp; srcp = srcp->next ) {
if ( srcp->typ == HDR && srcp->text ) {
if ( last_hnumber == srcp->hnumber )
Csprintf(&res, "%*s</li>\n", srcp->hnumber, "");
else while ( last_hnumber > srcp->hnumber ) {
Csprintf(&res, "%*s</li>\n%*s</ul>\n",
last_hnumber, "",
last_hnumber-1,"");
--last_hnumber;
}
while ( srcp->hnumber > last_hnumber ) {
Csprintf(&res, "\n%*s<ul>\n", srcp->hnumber, "");
++last_hnumber;
}
Csprintf(&res, "%*s<li><a href=\"#", srcp->hnumber, "");
mkd_string_to_anchor(T(srcp->text->text), S(srcp->text->text), Csputc, &res);
Csprintf(&res, "\">");
Csreparse(&res, T(srcp->text->text), S(srcp->text->text), 0);
Csprintf(&res, "</a>");
}
}
}
}
while ( last_hnumber > 0 ) {
Csprintf(&res, "%*s</li>\n%*s</ul>\n",
last_hnumber, "", last_hnumber, "");
--last_hnumber;
}
/* HACK ALERT! HACK ALERT! HACK ALERT! */
*doc = T(res); /* we know that a T(Cstring) is a character pointer */
/* so we can simply pick it up and carry it away, */
return S(res); /* leaving the husk of the Ctring on the stack */
/* END HACK ALERT */
}
/* write an header index
*/
int
mkd_generatetoc(Document *p, FILE *out)
{
char *buf = 0;
int sz = mkd_toc(p, &buf);
int ret = EOF;
if ( sz > 0 )
ret = fwrite(buf, sz, 1, out);
if ( buf ) free(buf);
return ret;
}
-38
View File
@@ -1,38 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
main(argc, argv)
char **argv;
{
register c;
int xp;
int width;
if ( argc != 2 ) {
fprintf(stderr, "usage: %s width\n", argv[0]);
exit(1);
}
else if ( (width=atoi(argv[1])) < 1 ) {
fprintf(stderr, "%s: please set width to > 0\n", argv[0]);
exit(1);
}
for ( xp = 1; (c = getchar()) != EOF; xp++ ) {
while ( c & 0xC0 ) {
/* assume that (1) the output device understands utf-8, and
* (2) the only c & 0x80 input is utf-8.
*/
do {
if ( xp <= width )
putchar(c);
} while ( (c = getchar()) != EOF && (c & 0x80) && !(c & 0x40) );
++xp;
}
if ( c == '\n' )
xp = 0;
if ( xp <= width )
putchar(c);
}
exit(0);
}
-22
View File
@@ -1,22 +0,0 @@
#include <stdio.h>
#include <string.h>
main(argc, argv)
char **argv;
{
int nl = 1;
int i;
if ( (argc > 1) && (strcmp(argv[1], "-n") == 0) ) {
++argv;
--argc;
nl = 0;
}
for ( i=1; i < argc; i++ ) {
if ( i > 1 ) putchar(' ');
fputs(argv[i], stdout);
}
if (nl) putchar('\n');
}
-28
View File
@@ -1,28 +0,0 @@
#include "config.h"
char markdown_version[] = VERSION
#if DL_TAG_EXTENSION
" DL_TAG"
#endif
#if PANDOC_HEADER
" HEADER"
#endif
#if 4 != 4
" TAB=4"
#endif
#if USE_AMALLOC
" DEBUG"
#endif
#if SUPERSCRIPT
" SUPERSCRIPT"
#endif
#if RELAXED_EMPHASIS
" RELAXED"
#endif
#if DIV_QUOTE
" DIV"
#endif
#if ALPHA_LIST
" AL"
#endif
;
-28
View File
@@ -1,28 +0,0 @@
#include "config.h"
char markdown_version[] = VERSION
#if DL_TAG_EXTENSION
" DL_TAG"
#endif
#if PANDOC_HEADER
" HEADER"
#endif
#if @TABSTOP@ != 4
" TAB=@TABSTOP@"
#endif
#if USE_AMALLOC
" DEBUG"
#endif
#if SUPERSCRIPT
" SUPERSCRIPT"
#endif
#if RELAXED_EMPHASIS
" RELAXED"
#endif
#if DIV_QUOTE
" DIV"
#endif
#if ALPHA_LIST
" AL"
#endif
;
-82
View File
@@ -1,82 +0,0 @@
/* markdown: a C implementation of John Gruber's Markdown markup language.
*
* Copyright (C) 2007 David L Parsons.
* The redistribution terms are provided in the COPYRIGHT file that must
* be distributed with this source code.
*/
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include "config.h"
#include "cstring.h"
#include "markdown.h"
#include "amalloc.h"
/* return the xml version of a character
*/
static char *
mkd_xmlchar(unsigned char c)
{
switch (c) {
case '<': return "&lt;";
case '>': return "&gt;";
case '&': return "&amp;";
case '"': return "&quot;";
case '\'': return "&apos;";
default: if ( isascii(c) || (c & 0x80) )
return 0;
return "";
}
}
/* write output in XML format
*/
int
mkd_generatexml(char *p, int size, FILE *out)
{
unsigned char c;
char *entity;
while ( size-- > 0 ) {
c = *p++;
if ( entity = mkd_xmlchar(c) )
fputs(entity, out);
else
fputc(c, out);
}
return 0;
}
/* build a xml'ed version of a string
*/
int
mkd_xml(char *p, int size, char **res)
{
unsigned char c;
char *entity;
Cstring f;
CREATE(f);
RESERVE(f, 100);
while ( size-- > 0 ) {
c = *p++;
if ( entity = mkd_xmlchar(c) )
Cswrite(&f, entity, strlen(entity));
else
Csputc(c, &f);
}
/* HACK ALERT! HACK ALERT! HACK ALERT! */
*res = T(f); /* we know that a T(Cstring) is a character pointer */
/* so we can simply pick it up and carry it away, */
return S(f); /* leaving the husk of the Ctring on the stack */
/* END HACK ALERT */
}
-48
View File
@@ -1,48 +0,0 @@
/*
* xmlpage -- write a skeletal xhtml page
*
* Copyright (C) 2007 David L Parsons.
* The redistribution terms are provided in the COPYRIGHT file that must
* be distributed with this source code.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "cstring.h"
#include "markdown.h"
#include "amalloc.h"
int
mkd_xhtmlpage(Document *p, int flags, FILE *out)
{
char *title;
extern char *mkd_doc_title(Document *);
if ( mkd_compile(p, flags) ) {
fprintf(out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
fprintf(out, "<!DOCTYPE html "
" PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n");
fprintf(out, "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n");
fprintf(out, "<head>\n");
if ( title = mkd_doc_title(p) )
fprintf(out, "<title>%s</title>\n", title);
mkd_generatecss(p, out);
fprintf(out, "</head>\n");
fprintf(out, "<body>\n");
mkd_generatehtml(p, out);
fprintf(out, "</body>\n");
fprintf(out, "</html>\n");
mkd_cleanup(p);
return 0;
}
return -1;
}
-3
View File
@@ -1,3 +0,0 @@
#import <Foundation/Foundation.h>
NSString* discountToHTML(NSString *markdown);
-29
View File
@@ -1,29 +0,0 @@
#include "discountWrapper.h"
#define Line discountLine
#include "markdown.h"
#undef Line
#include "mkdioWrapper.h"
#include "markdownWrapper.h"
NSString* discountToHTML(NSString *markdown) {
NSString *result = nil;
char *markdownUTF8 = (char*)[markdown UTF8String];
Document *document = mkd_string_wrapper(markdownUTF8, strlen(markdownUTF8), 0);
if (document) {
if (mkd_compile_wrapper(document, 0)) {
char *htmlUTF8;
int htmlUTF8Len = mkd_document_wrapper(document, &htmlUTF8);
if (htmlUTF8Len != EOF) {
result = [[[NSString alloc] initWithBytes:htmlUTF8
length:htmlUTF8Len
encoding:NSUTF8StringEncoding] autorelease];
}
mkd_cleanup_wrapper(document);
}
}
return result;
}
-13
View File
@@ -1,13 +0,0 @@
//#include "markdownWrapper.h"
#include <stdio.h>
#include "markdown.h"
int mkd_compile_wrapper(Document *doc, int flags) {
return mkd_compile(doc, flags);
}
int mkd_document_wrapper(Document *p, char **res) {
return mkd_document(p, res);
}
-7
View File
@@ -1,7 +0,0 @@
#ifndef _mkdioWrapper_
#define _mkdioWrapper_
int mkd_compile_wrapper(Document *doc, int flags);
int mkd_document_wrapper(Document *p, char **res);
#endif // _mkdioWrapper_
-12
View File
@@ -1,12 +0,0 @@
//#include "mkdioWrapper.h"
#include "mkdio.h"
#define Document void
Document* mkd_string_wrapper(char *buf, int len, int flags) {
return mkd_string(buf, len, flags);
}
void mkd_cleanup_wrapper(Document *doc) {
mkd_cleanup(doc);
}
-7
View File
@@ -1,7 +0,0 @@
#ifndef _mkdioWrapper_
#define _mkdioWrapper_
Document* mkd_string_wrapper(char *buf, int len, int flags);
void mkd_cleanup_wrapper(Document *doc);
#endif // _mkdioWrapper_
Submodule
+1
Submodule mayday added at a6934e6f32