Commit 53750f4b authored by Alessandro Ghedini's avatar Alessandro Ghedini

Imported Upstream version 2.1.0

parent cf87eb68
......@@ -22,14 +22,14 @@ MAN3PAGES=mkd-callbacks.3 mkd-functions.3 markdown.3 mkd-line.3
all: $(PGMS) $(SAMPLE_PGMS) $(TESTFRAMEWORK)
install: $(PGMS)
install: $(PGMS) $(DESTDIR)/$(BINDIR) $(DESTDIR)/$(LIBDIR) $(DESTDIR)/$(INCDIR)
@INSTALL_PROGRAM@ $(PGMS) $(DESTDIR)/$(BINDIR)
./librarian.sh install libmarkdown VERSION $(DESTDIR)/$(LIBDIR)
@INSTALL_DATA@ mkdio.h $(DESTDIR)/$(INCDIR)
install.everything: install install.samples install.man
install.samples: $(SAMPLE_PGMS) install
install.samples: $(SAMPLE_PGMS) install $(DESTDIR)/$(BINDIR)
@INSTALL_PROGRAM@ $(SAMPLE_PGMS) $(DESTDIR)/$(BINDIR)
@INSTALL_DIR@ $(DESTDIR)/$(MANDIR)/man1
@INSTALL_DATA@ theme.1 makepage.1 mkd2html.1 $(DESTDIR)/$(MANDIR)/man1
......@@ -53,12 +53,18 @@ install.man:
install.everything: install install.man
$(DESTDIR)/$(BINDIR):
@INSTALL_DIR@ $(DESTDIR)/$(BINDIR)
$(DESTDIR)/$(INCDIR):
@INSTALL_DIR@ $(DESTDIR)/$(INCDIR)
$(DESTDIR)/$(LIBDIR):
@INSTALL_DIR@ $(DESTDIR)/$(LIBDIR)
version.o: version.c VERSION
$(CC) -DVERSION=\"`cat VERSION`\" -c version.c
markdown: main.o $(MKDLIB)
$(CC) $(CFLAGS) -o markdown main.o -lmarkdown @LIBS@
# example programs
@THEME@theme: theme.o $(MKDLIB) mkdio.h
@THEME@ $(CC) -o theme theme.o -lmarkdown @LIBS@
......@@ -67,8 +73,14 @@ markdown: main.o $(MKDLIB)
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@
markdown: main.o pgm_options.o $(MKDLIB)
$(CC) $(CFLAGS) -o markdown main.o pgm_options.o -lmarkdown @LIBS@
makepage: makepage.c pgm_options.o $(MKDLIB) mkdio.h
$(CC) $(CFLAGS) -o makepage makepage.c pgm_options.o -lmarkdown @LIBS@
pgm_options.o: pgm_options.c mkdio.h config.h
$(CC) -I. -c pgm_options.c
main.o: main.c mkdio.h config.h
$(CC) -I. -c main.c
......@@ -105,6 +117,7 @@ dumptree.o: dumptree.c markdown.h cstring.h amalloc.h config.h
emmatch.o: emmatch.c config.h cstring.h amalloc.h markdown.h
generate.o: generate.c config.h cstring.h amalloc.h markdown.h
main.o: main.c config.h amalloc.h
pgm_options.o: pgm_options.c pgm_options.h config.h amalloc.h
makepage.o: makepage.c
markdown.o: markdown.c config.h cstring.h amalloc.h markdown.h
mkd2html.o: mkd2html.c config.h mkdio.h cstring.h amalloc.h
......
This diff is collapsed.
......@@ -13,9 +13,11 @@
#include <mkdio.h>
#include <errno.h>
#include <string.h>
#include <stdarg.h>
#include "config.h"
#include "amalloc.h"
#include "pgm_options.h"
#if HAVE_LIBGEN_H
#include <libgen.h>
......@@ -36,123 +38,24 @@ basename(char *p)
char *pgm = "markdown";
static struct _opt {
char *name;
char *desc;
int off:1;
int skip:1;
int sayenable:1;
mkd_flag_t flag;
} opts[] = {
{ "tabstop", "default (4-space) tabstops", 0, 0, 1, MKD_TABSTOP },
{ "image", "images", 1, 0, 1, MKD_NOIMAGE },
{ "links", "links", 1, 0, 1, MKD_NOLINKS },
{ "relax", "emphasis inside words", 1, 1, 1, MKD_STRICT },
{ "strict", "emphasis inside words", 0, 0, 1, MKD_STRICT },
{ "tables", "tables", 1, 0, 1, MKD_NOTABLES },
{ "header", "pandoc-style headers", 1, 0, 1, MKD_NOHEADER },
{ "html", "raw html", 1, 0, 1, MKD_NOHTML },
{ "ext", "extended protocols", 1, 0, 1, MKD_NO_EXT },
{ "cdata", "generate cdata", 0, 0, 0, MKD_CDATA },
{ "smarty", "smartypants", 1, 0, 1, MKD_NOPANTS },
{ "pants", "smartypants", 1, 1, 1, MKD_NOPANTS },
{ "toc", "tables of contents", 0, 0, 1, MKD_TOC },
{ "autolink", "autolinking", 0, 0, 1, MKD_AUTOLINK },
{ "safelink", "safe links", 0, 0, 1, MKD_SAFELINK },
{ "strikethrough", "strikethrough", 1, 0, 1, MKD_NOSTRIKETHROUGH },
{ "del", "strikethrough", 1, 1, 1, MKD_NOSTRIKETHROUGH },
{ "superscript", "superscript", 1, 0, 1, MKD_NOSUPERSCRIPT },
{ "emphasis", "emphasis inside words", 0, 0, 1, MKD_NORELAXED },
{ "divquote", ">%class% blockquotes", 1, 0, 1, MKD_NODIVQUOTE },
{ "alphalist", "alpha lists", 1, 0, 1, MKD_NOALPHALIST },
{ "definitionlist","definition lists", 1, 0, 1, MKD_NODLIST },
{ "1.0", "markdown 1.0 compatibility", 0, 0, 1, MKD_1_COMPAT },
{ "footnotes", "markdown extra footnotes", 0, 0, 1, MKD_EXTRA_FOOTNOTE },
{ "footnote", "markdown extra footnotes", 0, 1, 1, MKD_EXTRA_FOOTNOTE },
} ;
#define NR(x) (sizeof x / sizeof x[0])
int
sort_by_name(struct _opt *a, struct _opt *b)
{
return strcmp(a->name,b->name);
}
int
sort_by_flag(struct _opt *a, struct _opt *b)
char *
e_flags(const char *text, const int size, void *context)
{
return a->flag - b->flag;
return (char*)context;
}
void
show_flags(int byname)
{
int i;
if ( byname ) {
qsort(opts, NR(opts), sizeof(opts[0]), sort_by_name);
for (i=0; i < NR(opts); i++)
if ( ! opts[i].skip )
fprintf(stderr, "%16s : %s\n", opts[i].name, opts[i].desc);
}
else {
qsort(opts, NR(opts), sizeof(opts[0]), sort_by_flag);
for (i=0; i < NR(opts); i++)
if ( ! opts[i].skip ) {
fprintf(stderr, "%08lx : ", (long)opts[i].flag);
if ( opts[i].sayenable )
fprintf(stderr, opts[i].off ? "disable " : "enable ");
fprintf(stderr, "%s\n", opts[i].desc);
}
}
}
void
set(mkd_flag_t *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);
}
}
char *
e_flags(const char *text, const int size, void *context)
complain(char *fmt, ...)
{
return (char*)context;
va_list ptr;
fprintf(stderr, "%s: ", pgm);
va_start(ptr, fmt);
vfprintf(stderr, fmt, ptr);
va_end(ptr);
fputc('\n', stderr);
fflush(stderr);
}
......@@ -204,8 +107,8 @@ main(int argc, char **argv)
show_flags(1);
exit(0);
}
else
set(&flags, optarg);
else if ( !set_flag(&flags, optarg) )
complain("unknown option <%s>", optarg);
break;
case 't': text = optarg;
use_mkd_line = 1;
......@@ -217,7 +120,7 @@ main(int argc, char **argv)
case 'C': extra_footnote_prefix = optarg;
break;
case 'o': if ( ofile ) {
fprintf(stderr, "Too many -o options\n");
complain("Too many -o options");
exit(1);
}
if ( !freopen(ofile = optarg, "w", stdout) ) {
......
......@@ -8,6 +8,9 @@
.Nd convert markdown input to a fully-formed xhtml page
.Sh SYNOPSIS
.Nm
.Op Fl V
.Op Fl F Pa bitmap
.Op Fl f Ar flags
.Op Pa file
.Sh DESCRIPTION
The
......@@ -18,6 +21,14 @@ utility parses a
.Pq or stdin if not specified,
compiles it, then prints a fully-formed xhtml page to stdout.
.Pp
The
.Fl F ,
.Fl f ,
and
.Fl V
flags are identical to the same options in
.Xr markdown 1 .
.Pp
.Nm
is part of discount.
.Sh RETURN VALUES
......
......@@ -4,7 +4,23 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <mkdio.h>
#include "config.h"
#include "pgm_options.h"
#ifndef HAVE_BASENAME
char*
basename(char *p)
{
char *ret = strrchr(p, '/');
return ret ? (1+ret) : p;
}
#endif
char *pgm = "makepage";
float
main(argc, argv)
......@@ -12,16 +28,60 @@ int argc;
char **argv;
{
MMIOT *doc;
char *q;
int version = 0;
int opt;
mkd_flag_t flags = 0;
if ( (q = getenv("MARKDOWN_FLAGS")) )
flags = strtol(q, 0, 0);
opterr = 1;
while ( (opt=getopt(argc, argv, "F:f:V")) != EOF ) {
switch (opt) {
case 'V': version++;
break;
case 'F': if ( strcmp(optarg, "?") == 0 ) {
show_flags(0);
exit(0);
}
else
flags = strtol(optarg, 0, 0);
break;
case 'f': if ( strcmp(optarg, "?") == 0 ) {
show_flags(1);
exit(0);
}
else if ( !set_flag(&flags, optarg) )
fprintf(stderr, "unknown option <%s>\n", optarg);
break;
default: fprintf(stderr, "usage: %s [-V] [-F bitmap] [-f {+-}flags]"
" [file]\n", pgm);
exit(1);
}
}
argc -= optind;
argv += optind;
if ( version ) {
printf("%s: discount %s", pgm, markdown_version);
if ( version > 1 )
mkd_flags_are(stdout, flags, 0);
putchar('\n');
exit(0);
}
if ( (argc > 1) && !freopen(argv[1], "r", stdin) ) {
perror(argv[1]);
exit(1);
}
if ( (doc = mkd_in(stdin, 0)) == 0 ) {
if ( (doc = mkd_in(stdin, flags)) == 0 ) {
perror( (argc > 1) ? argv[1] : "stdin" );
exit(1);
}
exit(mkd_xhtmlpage(doc, 0, stdout));
exit(mkd_xhtmlpage(doc, flags, stdout));
}
......@@ -84,6 +84,7 @@ void mkd_ref_prefix(MMIOT*, char*);
#define MKD_TAGTEXT 0x00000020 /* process text inside an html tag; no
* <em>, no <bold>, no html or [] expansion */
#define MKD_NO_EXT 0x00000040 /* don't allow pseudo-protocols */
#define MKD_NOEXT MKD_NO_EXT /* ^^^ (aliased for user convenience) */
#define MKD_CDATA 0x00000080 /* generate code for xml ![CDATA[...]] */
#define MKD_NOSUPERSCRIPT 0x00000100 /* no A^B */
#define MKD_NORELAXED 0x00000200 /* emphasis happens /everywhere/ */
......
/* markdown: a C implementation of John Gruber's Markdown markup language.
*
* Copyright (C) 2007-2011 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 <stdarg.h>
#include "config.h"
#include "amalloc.h"
#if HAVE_LIBGEN_H
#include <libgen.h>
#endif
static struct _opt {
char *name;
char *desc;
int off;
int skip;
int sayenable;
mkd_flag_t flag;
} opts[] = {
{ "tabstop", "default (4-space) tabstops", 0, 0, 1, MKD_TABSTOP },
{ "image", "images", 1, 0, 1, MKD_NOIMAGE },
{ "links", "links", 1, 0, 1, MKD_NOLINKS },
{ "relax", "emphasis inside words", 1, 1, 1, MKD_STRICT },
{ "strict", "emphasis inside words", 0, 0, 1, MKD_STRICT },
{ "tables", "tables", 1, 0, 1, MKD_NOTABLES },
{ "header", "pandoc-style headers", 1, 0, 1, MKD_NOHEADER },
{ "html", "raw html", 1, 0, 1, MKD_NOHTML },
{ "ext", "extended protocols", 1, 0, 1, MKD_NO_EXT },
{ "cdata", "generate cdata", 0, 0, 0, MKD_CDATA },
{ "smarty", "smartypants", 1, 0, 1, MKD_NOPANTS },
{ "pants", "smartypants", 1, 1, 1, MKD_NOPANTS },
{ "toc", "tables of contents", 0, 0, 1, MKD_TOC },
{ "autolink", "autolinking", 0, 0, 1, MKD_AUTOLINK },
{ "safelink", "safe links", 0, 0, 1, MKD_SAFELINK },
{ "strikethrough", "strikethrough", 1, 0, 1, MKD_NOSTRIKETHROUGH },
{ "del", "strikethrough", 1, 1, 1, MKD_NOSTRIKETHROUGH },
{ "superscript", "superscript", 1, 0, 1, MKD_NOSUPERSCRIPT },
{ "emphasis", "emphasis inside words", 0, 0, 1, MKD_NORELAXED },
{ "divquote", ">%class% blockquotes", 1, 0, 1, MKD_NODIVQUOTE },
{ "alphalist", "alpha lists", 1, 0, 1, MKD_NOALPHALIST },
{ "definitionlist","definition lists", 1, 0, 1, MKD_NODLIST },
{ "1.0", "markdown 1.0 compatibility", 0, 0, 1, MKD_1_COMPAT },
{ "footnotes", "markdown extra footnotes", 0, 0, 1, MKD_EXTRA_FOOTNOTE },
{ "footnote", "markdown extra footnotes", 0, 1, 1, MKD_EXTRA_FOOTNOTE },
} ;
#define NR(x) (sizeof x / sizeof x[0])
int
sort_by_name(struct _opt *a, struct _opt *b)
{
return strcmp(a->name,b->name);
}
int
sort_by_flag(struct _opt *a, struct _opt *b)
{
return a->flag - b->flag;
}
void
show_flags(int byname)
{
int i;
if ( byname ) {
qsort(opts, NR(opts), sizeof(opts[0]), sort_by_name);
for (i=0; i < NR(opts); i++)
if ( ! opts[i].skip )
fprintf(stderr, "%16s : %s\n", opts[i].name, opts[i].desc);
}
else {
qsort(opts, NR(opts), sizeof(opts[0]), sort_by_flag);
for (i=0; i < NR(opts); i++)
if ( ! opts[i].skip ) {
fprintf(stderr, "%08lx : ", (long)opts[i].flag);
if ( opts[i].sayenable )
fprintf(stderr, opts[i].off ? "disable " : "enable ");
fprintf(stderr, "%s\n", opts[i].desc);
}
}
}
int
set_flag(mkd_flag_t *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
return 0;
}
return 1;
}
#ifndef PGM_OPTIONS_D
#define PGM_OPTIONS_D
#include <mkdio.h>
int set_flag(mkd_flag_t *flags, char *optionstring);
void show_flags(int byname);
#endif/*PGM_OPTIONS_D*/
......@@ -9,6 +9,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl d Pa root
.Op Fl E
.Op Fl f
.Op Fl o Pa file
.Op Fl p Pa pagename
......@@ -94,7 +95,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
.Fl o
option,
.Nm writes the output to
.Pa file-sans-text.html
......@@ -115,6 +116,21 @@ Set the
.Em "document root"
to
.Ar root
.It Fl E
Normally
theme will not expand
.Pa "<?theme body?>"
or
.Pa "<?theme toc?>"
in the
.Pa "<head>"
section, or
.Pa "<?theme style?>"
in the
.Pa "<body>"
section, but the
.Fl E
option overrides this and allows expansions everywhere.
.It Fl f
Forcibly overwrite existing html files.
.It Fl o Pa filename
......
......@@ -37,6 +37,8 @@ char *pgm = "theme";
char *output = 0;
char *pagename = 0;
char *root = 0;
int everywhere = 0; /* expand all <?theme elements everywhere */
#if HAVE_PWD_H
struct passwd *me = 0;
#endif
......@@ -466,7 +468,7 @@ spin(FILE *template, MMIOT *doc, FILE *output)
for (i=0; i < NR(keyword); i++)
if ( thesame(p, keyword[i].kw) ) {
if ( keyword[i].where & where )
if ( everywhere || (keyword[i].where & where) )
(*keyword[i].what)(doc,output,flags,where);
break;
}
......@@ -512,10 +514,12 @@ char **argv;
opterr=1;
pgm = basename(argv[0]);
while ( (opt=getopt(argc, argv, "fd:t:p:o:V")) != EOF ) {
while ( (opt=getopt(argc, argv, "Efd:t:p:o:V")) != EOF ) {
switch (opt) {
case 'd': root = optarg;
break;
case 'E': everywhere = 1;
break;
case 'p': pagename = optarg;
break;
case 'f': force = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment