Browse Source

Initial commit

sekimura 10 years ago
commit
2c46fcb478
15 changed files with 7174 additions and 0 deletions
  1. 6
    0
      Changes
  2. 8
    0
      MANIFEST
  3. 17
    0
      Makefile.PL
  4. 40
    0
      README
  5. 39
    0
      XS.xs
  6. 29
    0
      amalloc.h
  7. 28
    0
      config.h
  8. 68
    0
      cstring.h
  9. 86
    0
      lib/Text/Markdown/XS.pm
  10. 131
    0
      markdown.h
  11. 65
    0
      mkdio.h
  12. 6376
    0
      ppport.h
  13. 15
    0
      t/Text-Markdown-XS.t
  14. 233
    0
      xt/index.text
  15. 33
    0
      xt/test.pl

+ 6
- 0
Changes View File

@@ -0,0 +1,6 @@
1
+Revision history for Perl extension Text::Markdown::XS.
2
+
3
+0.01  Thu Feb 12 22:49:17 2009
4
+	- original version; created by h2xs 1.23 with options
5
+		-A -n Text::Markdown::XS
6
+

+ 8
- 0
MANIFEST View File

@@ -0,0 +1,8 @@
1
+Changes
2
+Makefile.PL
3
+MANIFEST
4
+ppport.h
5
+README
6
+XS.xs
7
+t/Text-Markdown-XS.t
8
+lib/Text/Markdown/XS.pm

+ 17
- 0
Makefile.PL View File

@@ -0,0 +1,17 @@
1
+use 5.010000;
2
+use ExtUtils::MakeMaker;
3
+# See lib/ExtUtils/MakeMaker.pm for details of how to influence
4
+# the contents of the Makefile that is written.
5
+WriteMakefile(
6
+    NAME              => 'Text::Markdown::XS',
7
+    VERSION_FROM      => 'lib/Text/Markdown/XS.pm', # finds $VERSION
8
+    PREREQ_PM         => {}, # e.g., Module::Name => 1.1
9
+    ($] >= 5.005 ?     ## Add these new keywords supported since 5.005
10
+      (ABSTRACT_FROM  => 'lib/Text/Markdown/XS.pm', # retrieve abstract from module
11
+       AUTHOR         => 'Masayoshi Sekimura <sekimura@>') : ()),
12
+    LIBS              => ['-lmarkdown'], # e.g., '-lm'
13
+    DEFINE            => '', # e.g., '-DHAVE_SOMETHING'
14
+    INC               => '-I.', # e.g., '-I. -I/usr/include/other'
15
+	# Un-comment this if you add C files to link with later:
16
+    # OBJECT            => '$(O_FILES)', # link all the C files too
17
+);

+ 40
- 0
README View File

@@ -0,0 +1,40 @@
1
+Text-Markdown-XS version 0.01
2
+=============================
3
+
4
+The README is used to introduce the module and provide instructions on
5
+how to install the module, any machine dependencies it may have (for
6
+example C compilers and installed libraries) and any other information
7
+that should be provided before the module is installed.
8
+
9
+A README file is required for CPAN modules since CPAN extracts the
10
+README file from a module distribution so that people browsing the
11
+archive can use it get an idea of the modules uses. It is usually a
12
+good idea to provide version information here so that people can
13
+decide whether fixes for the module are worth downloading.
14
+
15
+INSTALLATION
16
+
17
+To install this module type the following:
18
+
19
+   perl Makefile.PL
20
+   make
21
+   make test
22
+   make install
23
+
24
+DEPENDENCIES
25
+
26
+This module requires these other modules and libraries:
27
+
28
+  blah blah blah
29
+
30
+COPYRIGHT AND LICENCE
31
+
32
+Put the correct copyright and licence information here.
33
+
34
+Copyright (C) 2009 by Masayoshi Sekimura
35
+
36
+This library is free software; you can redistribute it and/or modify
37
+it under the same terms as Perl itself, either Perl version 5.10.0 or,
38
+at your option, any later version of Perl 5 you may have available.
39
+
40
+

+ 39
- 0
XS.xs View File

@@ -0,0 +1,39 @@
1
+#include "EXTERN.h"
2
+#include "perl.h"
3
+#include "XSUB.h"
4
+
5
+#include "ppport.h"
6
+
7
+#include "cstring.h"
8
+#include "markdown.h"
9
+
10
+typedef struct {
11
+        char sym;
12
+        char * xml_sym;
13
+} e_char;
14
+
15
+
16
+
17
+MODULE = Text::Markdown::XS		PACKAGE = Text::Markdown::XS		
18
+
19
+SV *
20
+_markdown(text)
21
+        char *text;
22
+    PREINIT:
23
+        SV* r = &PL_sv_undef;
24
+    CODE:
25
+        int rc;
26
+        int flags = 0x0004;
27
+        char *ret;
28
+        int szret;
29
+        Document *doc;
30
+        if ( (doc = mkd_string(text, strlen(text), flags)) == 0 ) {
31
+            exit(1);
32
+        }
33
+        mkd_compile(doc, flags);
34
+        szret = mkd_document(doc, &ret);
35
+
36
+        r = newSVpv(ret, 0);
37
+        RETVAL = r;
38
+    OUTPUT:
39
+        RETVAL

+ 29
- 0
amalloc.h View File

@@ -0,0 +1,29 @@
1
+/*
2
+ * debugging malloc()/realloc()/calloc()/free() that attempts
3
+ * to keep track of just what's been allocated today.
4
+ */
5
+#ifndef AMALLOC_D
6
+#define AMALLOC_D
7
+
8
+#include "config.h"
9
+
10
+#ifdef USE_AMALLOC
11
+
12
+extern void *amalloc(int);
13
+extern void *acalloc(int,int);
14
+extern void *arealloc(void*,int);
15
+extern void afree(void*);
16
+extern void adump();
17
+
18
+#define malloc	amalloc
19
+#define	calloc	acalloc
20
+#define realloc	arealloc
21
+#define free	afree
22
+
23
+#else
24
+
25
+#define adump()	(void)1
26
+
27
+#endif
28
+
29
+#endif/*AMALLOC_D*/

+ 28
- 0
config.h View File

@@ -0,0 +1,28 @@
1
+/*
2
+ * configuration for markdown, generated Thu Feb 12 22:57:30 PST 2009
3
+ * by sekimura@liz
4
+ */
5
+#ifndef __AC_MARKDOWN_D
6
+#define __AC_MARKDOWN_D 1
7
+
8
+
9
+#define OS_LINUX 1
10
+#define DWORD	unsigned long
11
+#define WORD	unsigned short
12
+#define BYTE	unsigned char
13
+#define HAVE_BASENAME 1
14
+#define HAVE_LIBGEN_H 1
15
+#define HAVE_PWD_H 1
16
+#define HAVE_GETPWUID 1
17
+#define HAVE_SRANDOM 1
18
+#define INITRNG(x) srandom((unsigned int)x)
19
+#define HAVE_RANDOM 1
20
+#define COINTOSS() (random()&1)
21
+#define HAVE_STRCASECMP 1
22
+#define HAVE_STRNCASECMP 1
23
+#define HAVE_FCHDIR 1
24
+#define TABSTOP 4
25
+#define HAVE_MALLOC_H 1
26
+#define PATH_SED "/bin/sed"
27
+
28
+#endif/* __AC_MARKDOWN_D */

+ 68
- 0
cstring.h View File

@@ -0,0 +1,68 @@
1
+/* two template types:  STRING(t) which defines a pascal-style string
2
+ * of element (t) [STRING(char) is the closest to the pascal string],
3
+ * and ANCHOR(t) which defines a baseplate that a linked list can be
4
+ * built up from.   [The linked list /must/ contain a ->next pointer
5
+ * for linking the list together with.]
6
+ */
7
+#ifndef _CSTRING_D
8
+#define _CSTRING_D
9
+
10
+#include <string.h>
11
+#include <stdlib.h>
12
+
13
+#include "amalloc.h"
14
+
15
+/* expandable Pascal-style string.
16
+ */
17
+#define STRING(type)	struct { type *text; int size, alloc; }
18
+
19
+#define CREATE(x)	T(x) = (void*)(S(x) = (x).alloc = 0)
20
+#define EXPAND(x)	(S(x)++)[(S(x) < (x).alloc) \
21
+			    ? (T(x)) \
22
+			    : (T(x) = T(x) ? realloc(T(x), sizeof T(x)[0] * ((x).alloc += 100)) \
23
+					   : malloc(sizeof T(x)[0] * ((x).alloc += 100)) )]
24
+
25
+#define DELETE(x)	(x).alloc ? (free(T(x)), S(x) = (x).alloc = 0) \
26
+				  : ( S(x) = 0 )
27
+#define CLIP(t,i,sz)	\
28
+	    ( ((i) >= 0) && ((sz) > 0) && (((i)+(sz)) <= S(t)) ) ? \
29
+	    (memmove(&T(t)[i], &T(t)[i+sz], (S(t)-(i+sz)+1)*sizeof(T(t)[0])), \
30
+		S(t) -= (sz)) : -1
31
+
32
+#define RESERVE(x, sz)	T(x) = ((x).alloc > S(x) + (sz) \
33
+			    ? T(x) \
34
+			    : T(x) \
35
+				? realloc(T(x), sizeof T(x)[0] * ((x).alloc = 100+(sz)+S(x))) \
36
+				: malloc(sizeof T(x)[0] * ((x).alloc = 100+(sz)+S(x))))
37
+#define SUFFIX(t,p,sz)	\
38
+	    memcpy(((S(t) += (sz)) - (sz)) + \
39
+		    (T(t) = T(t) ? realloc(T(t), sizeof T(t)[0] * ((t).alloc += sz)) \
40
+				 : malloc(sizeof T(t)[0] * ((t).alloc += sz))), \
41
+		    (p), sizeof(T(t)[0])*(sz))
42
+
43
+#define PREFIX(t,p,sz)	\
44
+	    RESERVE( (t), (sz) ); \
45
+	    if ( S(t) ) { memmove(T(t)+(sz), T(t), S(t)); } \
46
+	    memcpy( T(t), (p), (sz) ); \
47
+	    S(t) += (sz)
48
+
49
+/* reference-style links (and images) are stored in an array
50
+ */
51
+#define T(x)		(x).text
52
+#define S(x)		(x).size
53
+
54
+/* abstract anchor type that defines a list base
55
+ * with a function that attaches an element to
56
+ * the end of the list.
57
+ *
58
+ * the list base field is named .text so that the T()
59
+ * macro will work with it.
60
+ */
61
+#define ANCHOR(t)	struct { t *text, *end; }
62
+
63
+#define ATTACH(t, p)	( (t).text ?( ((t).end->next = (p)), ((t).end = (p)) ) \
64
+				   :( ((t).text = (t).end = (p)) ) )
65
+
66
+typedef STRING(char) Cstring;
67
+
68
+#endif/*_CSTRING_D*/

+ 86
- 0
lib/Text/Markdown/XS.pm View File

@@ -0,0 +1,86 @@
1
+package Text::Markdown::XS;
2
+
3
+use 5.010000;
4
+use strict;
5
+use warnings;
6
+
7
+require Exporter;
8
+
9
+our @ISA = qw(Exporter);
10
+
11
+# Items to export into callers namespace by default. Note: do not export
12
+# names by default without a very good reason. Use EXPORT_OK instead.
13
+# Do not simply export all your public functions/methods/constants.
14
+
15
+# This allows declaration	use Text::Markdown::XS ':all';
16
+# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
17
+# will save memory.
18
+our %EXPORT_TAGS = ( 'all' => [ qw(
19
+	
20
+) ] );
21
+
22
+our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
23
+
24
+our @EXPORT = qw(
25
+	
26
+);
27
+
28
+our $VERSION = '0.01';
29
+
30
+require XSLoader;
31
+XSLoader::load('Text::Markdown::XS', $VERSION);
32
+
33
+# Preloaded methods go here.
34
+
35
+1;
36
+__END__
37
+# Below is stub documentation for your module. You'd better edit it!
38
+
39
+=head1 NAME
40
+
41
+Text::Markdown::XS - Perl extension for blah blah blah
42
+
43
+=head1 SYNOPSIS
44
+
45
+  use Text::Markdown::XS;
46
+  blah blah blah
47
+
48
+=head1 DESCRIPTION
49
+
50
+Stub documentation for Text::Markdown::XS, created by h2xs. It looks like the
51
+author of the extension was negligent enough to leave the stub
52
+unedited.
53
+
54
+Blah blah blah.
55
+
56
+=head2 EXPORT
57
+
58
+None by default.
59
+
60
+
61
+
62
+=head1 SEE ALSO
63
+
64
+Mention other useful documentation such as the documentation of
65
+related modules or operating system documentation (such as man pages
66
+in UNIX), or any relevant external documentation such as RFCs or
67
+standards.
68
+
69
+If you have a mailing list set up for your module, mention it here.
70
+
71
+If you have a web site set up for your module, mention it here.
72
+
73
+=head1 AUTHOR
74
+
75
+Masayoshi Sekimura, E<lt>sekimura@E<gt>
76
+
77
+=head1 COPYRIGHT AND LICENSE
78
+
79
+Copyright (C) 2009 by Masayoshi Sekimura
80
+
81
+This library is free software; you can redistribute it and/or modify
82
+it under the same terms as Perl itself, either Perl version 5.10.0 or,
83
+at your option, any later version of Perl 5 you may have available.
84
+
85
+
86
+=cut

+ 131
- 0
markdown.h View File

@@ -0,0 +1,131 @@
1
+#ifndef _MARKDOWN_D
2
+#define _MARKDOWN_D
3
+
4
+#include "cstring.h"
5
+
6
+/* reference-style links (and images) are stored in an array
7
+ * of footnotes.
8
+ */
9
+typedef struct footnote {
10
+    Cstring tag;		/* the tag for the reference link */
11
+    Cstring link;		/* what this footnote points to */
12
+    Cstring title;		/* what it's called (TITLE= attribute) */
13
+    int height, width;		/* dimensions (for image link) */
14
+} Footnote;
15
+
16
+/* each input line is read into a Line, which contains the line,
17
+ * the offset of the first non-space character [this assumes 
18
+ * that all tabs will be expanded to spaces!], and a pointer to
19
+ * the next line.
20
+ */
21
+typedef struct line {
22
+    Cstring text;
23
+    struct line *next;
24
+    int dle;
25
+} Line;
26
+
27
+
28
+/* a paragraph is a collection of Lines, with links to the next paragraph
29
+ * and (if it's a QUOTE, UL, or OL) to the reparsed contents of this
30
+ * paragraph.
31
+ */
32
+typedef struct paragraph {
33
+    struct paragraph *next;	/* next paragraph */
34
+    struct paragraph *down;	/* recompiled contents of this paragraph */
35
+    struct line *text;		/* all the text in this paragraph */
36
+    char *ident;		/* %id% tag for QUOTE */
37
+    enum { WHITESPACE=0, CODE, QUOTE, MARKUP,
38
+	   HTML, STYLE, DL, UL, OL, AL, LISTITEM,
39
+	   HDR, HR } typ;
40
+    enum { IMPLICIT=0, PARA, CENTER} align;
41
+    int hnumber;		/* <Hn> for typ == HDR */
42
+} Paragraph;
43
+
44
+enum { ETX, SETEXT };	/* header types */
45
+
46
+
47
+typedef struct ablock {
48
+    enum { bTEXT, bSTAR, bUNDER } b_type;
49
+    int  b_count;
50
+    char b_char;
51
+    Cstring b_text;
52
+    Cstring b_post;
53
+} ablock;
54
+
55
+typedef STRING(ablock) Qblock;
56
+
57
+
58
+/* a magic markdown io thing holds all the data structures needed to
59
+ * do the backend processing of a markdown document
60
+ */
61
+typedef struct mmiot {
62
+    Cstring out;
63
+    Cstring in;
64
+    Qblock Q;
65
+    int isp;
66
+    STRING(Footnote) *footnotes;
67
+    int flags;
68
+#define DENY_A		0x0001
69
+#define DENY_IMG	0x0002
70
+#define DENY_SMARTY	0x0004
71
+#define DENY_HTML	0x0008
72
+#define STRICT		0x0010
73
+#define INSIDE_TAG	0x0020
74
+#define NO_PSEUDO_PROTO	0x0040
75
+#define CDATA_OUTPUT	0x0080
76
+#define TOC		0x1000
77
+#define USER_FLAGS	0xF0FF
78
+#define EMBEDDED	DENY_A|DENY_IMG|NO_PSEUDO_PROTO|CDATA_OUTPUT
79
+    char *base;
80
+} MMIOT;
81
+
82
+
83
+/*
84
+ * the mkdio text input functions return a document structure,
85
+ * which contains a header (retrieved from the document if
86
+ * markdown was configured * with the * --enable-pandoc-header
87
+ * and the document begins with a pandoc-style header) and the
88
+ * root of the linked list of Lines.
89
+ */
90
+typedef struct document {
91
+    Line *headers;		/* title -> author(s) -> date */
92
+    ANCHOR(Line) content;	/* uncompiled text, not valid after compile() */
93
+    Paragraph *code;		/* intermediate code generated by compile() */
94
+    int compiled;		/* set after mkd_compile() */
95
+    int html;			/* set after (internal) htmlify() */
96
+    int tabstop;		/* for properly expanding tabs (ick) */
97
+    MMIOT *ctx;			/* backend buffers, flags, and structures */
98
+    char *base;			/* url basename for url fragments */
99
+} Document;
100
+
101
+
102
+extern int  mkd_firstnonblank(Line *);
103
+extern int  mkd_compile(Document *, int);
104
+extern int  mkd_document(Document *, char **);
105
+extern int  mkd_generatehtml(Document *, FILE *);
106
+extern int  mkd_style(Document *, FILE *);
107
+extern void mkd_cleanup(Document *);
108
+extern int  mkd_text(char *, int, FILE*, int);
109
+extern void mkd_basename(Document*, char *);
110
+extern void mkd_string_to_anchor(char*,int, void(*)(int,void*), void*);
111
+
112
+extern Document *mkd_in(FILE *, int);
113
+extern Document *mkd_string(char*,int, int);
114
+
115
+#define NO_HEADER	0x0100
116
+#define STD_TABSTOP	0x0200
117
+#define INPUT_MASK	(NO_HEADER|STD_TABSTOP)
118
+
119
+
120
+/* internal resource handling functions.
121
+ */
122
+extern void ___mkd_freeLine(Line *);
123
+extern void ___mkd_freeLines(Line *);
124
+extern void ___mkd_freeParagraph(Paragraph *);
125
+extern void ___mkd_freefootnotes(MMIOT *);
126
+extern void ___mkd_initmmiot(MMIOT *, void *);
127
+extern void ___mkd_freemmiot(MMIOT *, void *);
128
+extern void ___mkd_freeLineRange(Line *, Line *);
129
+extern void ___mkd_xml(char *, int, FILE *);
130
+
131
+#endif/*_MARKDOWN_D*/

+ 65
- 0
mkdio.h View File

@@ -0,0 +1,65 @@
1
+#ifndef _MKDIO_D
2
+#define _MKDIO_D
3
+
4
+#include <stdio.h>
5
+
6
+typedef void MMIOT;
7
+
8
+/* line builder for markdown()
9
+ */
10
+MMIOT *mkd_in(FILE*,int);		/* assemble input from a file */
11
+MMIOT *mkd_string(char*,int,int);	/* assemble input from a buffer */
12
+
13
+void mkd_basename(MMIOT*,char*);
14
+
15
+/* compilation, debugging, cleanup
16
+ */
17
+int mkd_compile(MMIOT*, int);
18
+int mkd_generatehtml(MMIOT*,FILE*);
19
+int mkd_generatetoc(MMIOT*,FILE*);
20
+int mkd_xhtmlpage(MMIOT*,int,FILE*);
21
+int mkd_cleanup(MMIOT*);
22
+
23
+/* markup functions
24
+ */
25
+int mkd_text(char *, int, FILE*, int);
26
+int mkd_style(MMIOT*, FILE*);
27
+int mkd_dump(MMIOT*, FILE*, int, char*);
28
+int markdown(MMIOT*, FILE*, int);
29
+void mkd_basename(MMIOT*,char*);
30
+void mkd_string_to_anchor(char *, int, int (*)(int,void*), void*);
31
+
32
+/* header block access
33
+ */
34
+char* mkd_doc_title(MMIOT*);
35
+char* mkd_doc_author(MMIOT*);
36
+char* mkd_doc_date(MMIOT*);
37
+
38
+/* compiled data access
39
+ */
40
+int mkd_document(MMIOT*, char**);
41
+
42
+/* version#.
43
+ */
44
+extern char markdown_version[];
45
+
46
+/* special flags for markdown() and mkd_text()
47
+ */
48
+#define MKD_NOLINKS	0x0001	/* don't do link processing, block <a> tags  */
49
+#define MKD_NOIMAGE	0x0002	/* don't do image processing, block <img> */
50
+#define MKD_NOPANTS	0x0004	/* don't run smartypants() */
51
+#define MKD_NOHTML	0x0008	/* don't allow raw html through AT ALL */
52
+#define MKD_STRICT	0x0010	/* disable SUPERSCRIPT, RELAXED_EMPHASIS */
53
+#define MKD_TAGTEXT	0x0020	/* don't expand `_` and `*` */
54
+#define MKD_NO_EXT	0x0040	/* don't allow pseudo-protocols */
55
+#define MKD_CDATA	0x0080	/* generate code for xml ![CDATA[...]] */
56
+#define MKD_TOC		0x1000	/* do table-of-contents processing */
57
+#define MKD_EMBED	MKD_NOLINKS|MKD_NOIMAGE|MKD_TAGTEXT
58
+
59
+/* special flags for mkd_in() and mkd_string()
60
+ */
61
+#define MKD_NOHEADER	0x0100	/* don't process header blocks */
62
+#define MKD_TABSTOP	0x0200	/* expand tabs to 4 spaces */
63
+
64
+
65
+#endif/*_MKDIO_D*/

+ 6376
- 0
ppport.h
File diff suppressed because it is too large
View File


+ 15
- 0
t/Text-Markdown-XS.t View File

@@ -0,0 +1,15 @@
1
+# Before `make install' is performed this script should be runnable with
2
+# `make test'. After `make install' it should work as `perl Text-Markdown-XS.t'
3
+
4
+#########################
5
+
6
+# change 'tests => 1' to 'tests => last_test_to_print';
7
+
8
+use Test::More tests => 1;
9
+BEGIN { use_ok('Text::Markdown::XS') };
10
+
11
+#########################
12
+
13
+# Insert your test code below, the Test::More module is use()ed here so read
14
+# its man page ( perldoc Test::More ) for help writing this test script.
15
+

+ 233
- 0
xt/index.text View File

@@ -0,0 +1,233 @@
1
+
2
+Download
3
+--------
4
+
5
+[Markdown 1.0.1][dl] (18 KB) -- 17 Dec 2004
6
+
7
+[dl]: http://daringfireball.net/projects/downloads/Markdown_1.0.1.zip
8
+
9
+
10
+Introduction
11
+------------
12
+
13
+Markdown is a text-to-HTML conversion tool for web writers. Markdown
14
+allows you to write using an easy-to-read, easy-to-write plain text
15
+format, then convert it to structurally valid XHTML (or HTML).
16
+
17
+Thus, "Markdown" is two things: (1) a plain text formatting syntax;
18
+and (2) a software tool, written in Perl, that converts the plain text
19
+formatting to HTML. See the [Syntax][] page for details pertaining to
20
+Markdown's formatting syntax. You can try it out, right now, using the
21
+online [Dingus][].
22
+
23
+  [syntax]: /projects/markdown/syntax
24
+  [dingus]: /projects/markdown/dingus
25
+
26
+The overriding design goal for Markdown's formatting syntax is to make
27
+it as readable as possible. The idea is that a Markdown-formatted
28
+document should be publishable as-is, as plain text, without looking
29
+like it's been marked up with tags or formatting instructions. While
30
+Markdown's syntax has been influenced by several existing text-to-HTML
31
+filters, the single biggest source of inspiration for Markdown's
32
+syntax is the format of plain text email.
33
+
34
+The best way to get a feel for Markdown's formatting syntax is simply
35
+to look at a Markdown-formatted document. For example, you can view
36
+the Markdown source for the article text on this page here:
37
+<http://daringfireball.net/projects/markdown/index.text>
38
+
39
+(You can use this '.text' suffix trick to view the Markdown source for
40
+the content of each of the pages in this section, e.g. the
41
+[Syntax][s_src] and [License][l_src] pages.)
42
+
43
+  [s_src]: /projects/markdown/syntax.text
44
+  [l_src]: /projects/markdown/license.text
45
+
46
+Markdown is free software, available under a BSD-style open source
47
+license. See the [License] [pl] page for more information.
48
+
49
+  [pl]: /projects/markdown/license
50
+
51
+
52
+Discussion List <a id="discussion-list" />
53
+---------------
54
+
55
+I've set up a public [mailing list for discussion about Markdown] [ml].
56
+Any topic related to Markdown -- both its formatting syntax and
57
+its software -- is fair game for discussion. Anyone who is interested
58
+is welcome to join.
59
+
60
+It's my hope that the mailing list will lead to good ideas for future
61
+improvements to Markdown.
62
+
63
+  [ml]: http://six.pairlist.net/mailman/listinfo/markdown-discuss
64
+
65
+
66
+Installation and Requirements <a id="install" />
67
+-----------------------------
68
+
69
+Markdown requires Perl 5.6.0 or later. Welcome to the 21st Century.
70
+Markdown also requires the standard Perl library module [Digest::MD5]
71
+[md5], which is probably already installed on your server.
72
+
73
+  [md5]: http://search.cpan.org/dist/Digest-MD5/MD5.pm
74
+
75
+
76
+### Movable Type ###
77
+
78
+Markdown works with Movable Type version 2.6 or later (including
79
+Movable Type 3.0).
80
+
81
+1.  Copy the "Markdown.pl" file into your Movable Type "plugins"
82
+	directory. The "plugins" directory should be in the same directory
83
+	as "mt.cgi"; if the "plugins" directory doesn't already exist, use
84
+	your FTP program to create it. Your installation should look like
85
+	this:
86
+
87
+        (mt home)/plugins/Markdown.pl
88
+
89
+2.  Once installed, Markdown will appear as an option in Movable Type's
90
+	Text Formatting pop-up menu. This is selectable on a per-post basis:
91
+	
92
+	![Screenshot of Movable Type 'Text Formatting' Menu][tfmenu]
93
+	
94
+	Markdown translates your posts to HTML when you publish; the posts
95
+	themselves are stored in your MT database in Markdown format.
96
+
97
+3.	If you also install SmartyPants 1.5 (or later), Markdown will
98
+	offer a second text formatting option: "Markdown With
99
+	SmartyPants". This option is the same as the regular "Markdown"
100
+	formatter, except that it automatically uses SmartyPants to create
101
+	typographically correct curly quotes, em-dashes, and ellipses. See
102
+	the [SmartyPants web page][sp] for more information.
103
+
104
+4.	To make Markdown (or "Markdown With SmartyPants") your default
105
+	text formatting option for new posts, go to Weblog Config:
106
+	Preferences.
107
+
108
+Note that by default, Markdown produces XHTML output. To configure
109
+Markdown to produce HTML 4 output, see "Configuration", below.
110
+
111
+  [sp]: http://daringfireball.net/projects/smartypants/
112
+
113
+
114
+
115
+### Blosxom ###
116
+
117
+Markdown works with Blosxom version 2.0 or later.
118
+
119
+1.  Rename the "Markdown.pl" plug-in to "Markdown" (case is
120
+    important). Movable Type requires plug-ins to have a ".pl"
121
+    extension; Blosxom forbids it.
122
+
123
+2.  Copy the "Markdown" plug-in file to your Blosxom plug-ins folder.
124
+    If you're not sure where your Blosxom plug-ins folder is, see the
125
+    Blosxom documentation for information.
126
+
127
+3.  That's it. The entries in your weblog will now automatically be
128
+	processed by Markdown.
129
+
130
+4.	If you'd like to apply Markdown formatting only to certain
131
+	posts, rather than all of them, Markdown can optionally be used in
132
+	conjunction with Blosxom's [Meta][] plug-in. First, install the
133
+	Meta plug-in. Next, open the Markdown plug-in file in a text
134
+	editor, and set the configuration variable `$g_blosxom_use_meta`
135
+	to 1. Then, simply include a "`meta-markup: Markdown`" header line
136
+	at the top of each post you compose using Markdown.
137
+
138
+  [meta]: http://www.blosxom.com/plugins/meta/meta.htm
139
+
140
+
141
+### BBEdit ###
142
+
143
+Markdown works with BBEdit 6.1 or later on Mac OS X. It also works
144
+with BBEdit 5.1 or later and MacPerl 5.6.1 on Mac OS 8.6 or later. If
145
+you're running Mac OS X 10.2 (Jaguar), you may need to install the
146
+Perl module [Digest::MD5] [md5] from CPAN; Digest::MD5 comes
147
+pre-installed on Mac OS X 10.3 (Panther).
148
+
149
+1.  Copy the "Markdown.pl" file to appropriate filters folder in your
150
+	"BBEdit Support" folder. On Mac OS X, this should be:
151
+
152
+        BBEdit Support/Unix Support/Unix Filters/
153
+
154
+    See the BBEdit documentation for more details on the location of
155
+    these folders.
156
+
157
+    You can rename "Markdown.pl" to whatever you wish.
158
+
159
+2.  That's it. To use Markdown, select some text in a BBEdit document,
160
+	then choose Markdown from the Filters sub-menu in the "#!" menu, or
161
+	the Filters floating palette
162
+
163
+
164
+
165
+Configuration  <a id="configuration"></a>
166
+-------------
167
+
168
+By default, Markdown produces XHTML output for tags with empty elements.
169
+E.g.:
170
+
171
+    <br />
172
+
173
+Markdown can be configured to produce HTML-style tags; e.g.:
174
+
175
+    <br>
176
+
177
+
178
+### Movable Type ###
179
+
180
+You need to use a special `MTMarkdownOptions` container tag in each
181
+Movable Type template where you want HTML 4-style output:
182
+
183
+    <MTMarkdownOptions output='html4'>
184
+        ... put your entry content here ...
185
+    </MTMarkdownOptions>
186
+
187
+The easiest way to use MTMarkdownOptions is probably to put the
188
+opening tag right after your `<body>` tag, and the closing tag right
189
+before `</body>`.
190
+
191
+To suppress Markdown processing in a particular template, i.e. to
192
+publish the raw Markdown-formatted text without translation into
193
+(X)HTML, set the `output` attribute to 'raw':
194
+
195
+    <MTMarkdownOptions output='raw'>
196
+        ... put your entry content here ...
197
+    </MTMarkdownOptions>
198
+
199
+
200
+### Command-Line ###
201
+
202
+Use the `--html4tags` command-line switch to produce HTML output from a
203
+Unix-style command line. E.g.:
204
+
205
+    % perl Markdown.pl --html4tags foo.text
206
+
207
+Type `perldoc Markdown.pl`, or read the POD documentation within the
208
+Markdown.pl source code for more information.
209
+
210
+
211
+Acknowledgements <a id="acknowledgements" />
212
+----------------
213
+
214
+[Aaron Swartz][] deserves a tremendous amount of credit for helping to
215
+design Markdown's formatting syntax. Markdown is *much* better thanks
216
+to Aaron's ideas, feedback, and testing. Also, Aaron's [html2text][]
217
+is a very handy (and free) utility for turning HTML into
218
+Markdown-formatted plain text.
219
+
220
+[Nathaniel Irons][], [Dan Benjamin][], [Daniel Bogan][], and [Jason Perkins][]
221
+also deserve thanks for their feedback.
222
+
223
+[Michel Fortin][] has ported Markdown to PHP; it's a splendid port, and highly recommended for anyone looking for a PHP implementation of Markdown.
224
+
225
+  [Aaron Swartz]:		http://www.aaronsw.com/
226
+  [Nathaniel Irons]:	http://bumppo.net/
227
+  [Dan Benjamin]:		http://hivelogic.com/
228
+  [Daniel Bogan]:		http://waferbaby.com/
229
+  [Jason Perkins]:		http://pressedpants.com/
230
+  [Michel Fortin]:		http://www.michelf.com/projects/php-markdown/
231
+  [html2text]:          http://www.aaronsw.com/2002/html2text/
232
+ 
233
+  [tfmenu]: /graphics/markdown/mt_textformat_menu.png

+ 33
- 0
xt/test.pl View File

@@ -0,0 +1,33 @@
1
+#/usr/bin/perl
2
+
3
+use ExtUtils::testlib;
4
+
5
+use Text::Markdown 'markdown';
6
+use Text::Markdown::XS;
7
+use Benchmark;
8
+use File::Slurp;
9
+use Text::Diff;
10
+
11
+my $text = read_file('index.text');
12
+warn "XXXX";
13
+my $a = Text::Markdown::XS::_markdown($text);
14
+my $b = Text::Markdown::markdown($text);
15
+$a .= "\n";
16
+
17
+unless ( $a eq $b ) {
18
+print diff \$a, \$b; 
19
+#   die "BOO";
20
+}
21
+my $count = 1000;
22
+timethese($count, {
23
+    'Text::Markdown::XS' => sub { Text::Markdown::XS::_markdown($text) },
24
+    'Text::Markdown' => sub { Text::Markdown::markdown($text) },
25
+});
26
+
27
+
28
+#warn Text::Markdown::markdown(<<EOF);
29
+Text::Markdown::XS::_markdown(<<EOF);
30
+* test
31
+* Yup, test
32
+EOF
33
+

Loading…
Cancel
Save