github-markdown 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +87 -0
- data/bin/gfm +26 -0
- data/ext/markdown/autolink.c +264 -0
- data/ext/markdown/autolink.h +36 -0
- data/ext/markdown/buffer.c +223 -0
- data/ext/markdown/buffer.h +88 -0
- data/ext/markdown/extconf.rb +4 -0
- data/ext/markdown/gh-markdown.c +204 -0
- data/ext/markdown/houdini.h +29 -0
- data/ext/markdown/houdini_href_e.c +108 -0
- data/ext/markdown/houdini_html_e.c +84 -0
- data/ext/markdown/html.c +635 -0
- data/ext/markdown/html.h +69 -0
- data/ext/markdown/html_blocks.h +206 -0
- data/ext/markdown/markdown.c +2505 -0
- data/ext/markdown/markdown.h +130 -0
- data/ext/markdown/stack.c +81 -0
- data/ext/markdown/stack.h +21 -0
- data/github-markdown.gemspec +40 -0
- data/lib/github/markdown.rb +38 -0
- data/test/gfm_test.rb +26 -0
- metadata +98 -0
@@ -0,0 +1,130 @@
|
|
1
|
+
/* markdown.h - generic markdown parser */
|
2
|
+
|
3
|
+
/*
|
4
|
+
* Copyright (c) 2009, Natacha Porté
|
5
|
+
*
|
6
|
+
* Permission to use, copy, modify, and distribute this software for any
|
7
|
+
* purpose with or without fee is hereby granted, provided that the above
|
8
|
+
* copyright notice and this permission notice appear in all copies.
|
9
|
+
*
|
10
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
11
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
12
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
13
|
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
14
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
15
|
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
16
|
+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef UPSKIRT_MARKDOWN_H
|
20
|
+
#define UPSKIRT_MARKDOWN_H
|
21
|
+
|
22
|
+
#include "buffer.h"
|
23
|
+
#include "autolink.h"
|
24
|
+
|
25
|
+
#define UPSKIRT_VERSION "1.15.2"
|
26
|
+
#define UPSKIRT_VER_MAJOR 1
|
27
|
+
#define UPSKIRT_VER_MINOR 15
|
28
|
+
#define UPSKIRT_VER_REVISION 2
|
29
|
+
|
30
|
+
/********************
|
31
|
+
* TYPE DEFINITIONS *
|
32
|
+
********************/
|
33
|
+
|
34
|
+
/* mkd_autolink - type of autolink */
|
35
|
+
enum mkd_autolink {
|
36
|
+
MKDA_NOT_AUTOLINK, /* used internally when it is not an autolink*/
|
37
|
+
MKDA_NORMAL, /* normal http/http/ftp/mailto/etc link */
|
38
|
+
MKDA_EMAIL, /* e-mail link without explit mailto: */
|
39
|
+
};
|
40
|
+
|
41
|
+
enum mkd_tableflags {
|
42
|
+
MKD_TABLE_ALIGN_L = 1,
|
43
|
+
MKD_TABLE_ALIGN_R = 2,
|
44
|
+
MKD_TABLE_ALIGN_CENTER = 3,
|
45
|
+
MKD_TABLE_ALIGNMASK = 3,
|
46
|
+
MKD_TABLE_HEADER = 4
|
47
|
+
};
|
48
|
+
|
49
|
+
enum mkd_extensions {
|
50
|
+
MKDEXT_NO_INTRA_EMPHASIS = (1 << 0),
|
51
|
+
MKDEXT_TABLES = (1 << 1),
|
52
|
+
MKDEXT_FENCED_CODE = (1 << 2),
|
53
|
+
MKDEXT_AUTOLINK = (1 << 3),
|
54
|
+
MKDEXT_STRIKETHROUGH = (1 << 4),
|
55
|
+
MKDEXT_LAX_HTML_BLOCKS = (1 << 5),
|
56
|
+
MKDEXT_SPACE_HEADERS = (1 << 6),
|
57
|
+
MKDEXT_SUPERSCRIPT = (1 << 7),
|
58
|
+
};
|
59
|
+
|
60
|
+
/* sd_callbacks - functions for rendering parsed data */
|
61
|
+
struct sd_callbacks {
|
62
|
+
/* block level callbacks - NULL skips the block */
|
63
|
+
void (*blockcode)(struct buf *ob, const struct buf *text, const struct buf *lang, void *opaque);
|
64
|
+
void (*blockquote)(struct buf *ob, const struct buf *text, void *opaque);
|
65
|
+
void (*blockhtml)(struct buf *ob,const struct buf *text, void *opaque);
|
66
|
+
void (*header)(struct buf *ob, const struct buf *text, int level, void *opaque);
|
67
|
+
void (*hrule)(struct buf *ob, void *opaque);
|
68
|
+
void (*list)(struct buf *ob, const struct buf *text, int flags, void *opaque);
|
69
|
+
void (*listitem)(struct buf *ob, const struct buf *text, int flags, void *opaque);
|
70
|
+
void (*paragraph)(struct buf *ob, const struct buf *text, void *opaque);
|
71
|
+
void (*table)(struct buf *ob, const struct buf *header, const struct buf *body, void *opaque);
|
72
|
+
void (*table_row)(struct buf *ob, const struct buf *text, void *opaque);
|
73
|
+
void (*table_cell)(struct buf *ob, const struct buf *text, int flags, void *opaque);
|
74
|
+
|
75
|
+
|
76
|
+
/* span level callbacks - NULL or return 0 prints the span verbatim */
|
77
|
+
int (*autolink)(struct buf *ob, const struct buf *link, enum mkd_autolink type, void *opaque);
|
78
|
+
int (*codespan)(struct buf *ob, const struct buf *text, void *opaque);
|
79
|
+
int (*double_emphasis)(struct buf *ob, const struct buf *text, void *opaque);
|
80
|
+
int (*emphasis)(struct buf *ob, const struct buf *text, void *opaque);
|
81
|
+
int (*image)(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *alt, void *opaque);
|
82
|
+
int (*linebreak)(struct buf *ob, void *opaque);
|
83
|
+
int (*link)(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *content, void *opaque);
|
84
|
+
int (*raw_html_tag)(struct buf *ob, const struct buf *tag, void *opaque);
|
85
|
+
int (*triple_emphasis)(struct buf *ob, const struct buf *text, void *opaque);
|
86
|
+
int (*strikethrough)(struct buf *ob, const struct buf *text, void *opaque);
|
87
|
+
int (*superscript)(struct buf *ob, const struct buf *text, void *opaque);
|
88
|
+
|
89
|
+
/* low level callbacks - NULL copies input directly into the output */
|
90
|
+
void (*entity)(struct buf *ob, const struct buf *entity, void *opaque);
|
91
|
+
void (*normal_text)(struct buf *ob, const struct buf *text, void *opaque);
|
92
|
+
|
93
|
+
/* header and footer */
|
94
|
+
void (*doc_header)(struct buf *ob, void *opaque);
|
95
|
+
void (*doc_footer)(struct buf *ob, void *opaque);
|
96
|
+
};
|
97
|
+
|
98
|
+
struct sd_markdown;
|
99
|
+
|
100
|
+
/*********
|
101
|
+
* FLAGS *
|
102
|
+
*********/
|
103
|
+
|
104
|
+
/* list/listitem flags */
|
105
|
+
#define MKD_LIST_ORDERED 1
|
106
|
+
#define MKD_LI_BLOCK 2 /* <li> containing block data */
|
107
|
+
|
108
|
+
/**********************
|
109
|
+
* EXPORTED FUNCTIONS *
|
110
|
+
**********************/
|
111
|
+
|
112
|
+
extern struct sd_markdown *
|
113
|
+
sd_markdown_new(
|
114
|
+
unsigned int extensions,
|
115
|
+
size_t max_nesting,
|
116
|
+
const struct sd_callbacks *callbacks,
|
117
|
+
void *opaque);
|
118
|
+
|
119
|
+
extern void
|
120
|
+
sd_markdown_render(struct buf *ob, const uint8_t *document, size_t doc_size, struct sd_markdown *md);
|
121
|
+
|
122
|
+
extern void
|
123
|
+
sd_markdown_free(struct sd_markdown *md);
|
124
|
+
|
125
|
+
extern void
|
126
|
+
sd_version(int *major, int *minor, int *revision);
|
127
|
+
|
128
|
+
#endif
|
129
|
+
|
130
|
+
/* vim: set filetype=c: */
|
@@ -0,0 +1,81 @@
|
|
1
|
+
#include "stack.h"
|
2
|
+
#include <string.h>
|
3
|
+
|
4
|
+
int
|
5
|
+
stack_grow(struct stack *st, size_t new_size)
|
6
|
+
{
|
7
|
+
void **new_st;
|
8
|
+
|
9
|
+
if (st->asize >= new_size)
|
10
|
+
return 0;
|
11
|
+
|
12
|
+
new_st = realloc(st->item, new_size * sizeof(void *));
|
13
|
+
if (new_st == NULL)
|
14
|
+
return -1;
|
15
|
+
|
16
|
+
memset(new_st + st->asize, 0x0,
|
17
|
+
(new_size - st->asize) * sizeof(void *));
|
18
|
+
|
19
|
+
st->item = new_st;
|
20
|
+
st->asize = new_size;
|
21
|
+
|
22
|
+
if (st->size > new_size)
|
23
|
+
st->size = new_size;
|
24
|
+
|
25
|
+
return 0;
|
26
|
+
}
|
27
|
+
|
28
|
+
void
|
29
|
+
stack_free(struct stack *st)
|
30
|
+
{
|
31
|
+
if (!st)
|
32
|
+
return;
|
33
|
+
|
34
|
+
free(st->item);
|
35
|
+
|
36
|
+
st->item = NULL;
|
37
|
+
st->size = 0;
|
38
|
+
st->asize = 0;
|
39
|
+
}
|
40
|
+
|
41
|
+
int
|
42
|
+
stack_init(struct stack *st, size_t initial_size)
|
43
|
+
{
|
44
|
+
st->item = NULL;
|
45
|
+
st->size = 0;
|
46
|
+
st->asize = 0;
|
47
|
+
|
48
|
+
if (!initial_size)
|
49
|
+
initial_size = 8;
|
50
|
+
|
51
|
+
return stack_grow(st, initial_size);
|
52
|
+
}
|
53
|
+
|
54
|
+
void *
|
55
|
+
stack_pop(struct stack *st)
|
56
|
+
{
|
57
|
+
if (!st->size)
|
58
|
+
return NULL;
|
59
|
+
|
60
|
+
return st->item[--st->size];
|
61
|
+
}
|
62
|
+
|
63
|
+
int
|
64
|
+
stack_push(struct stack *st, void *item)
|
65
|
+
{
|
66
|
+
if (stack_grow(st, st->size * 2) < 0)
|
67
|
+
return -1;
|
68
|
+
|
69
|
+
st->item[st->size++] = item;
|
70
|
+
return 0;
|
71
|
+
}
|
72
|
+
|
73
|
+
void *
|
74
|
+
stack_top(struct stack *st)
|
75
|
+
{
|
76
|
+
if (!st->size)
|
77
|
+
return NULL;
|
78
|
+
|
79
|
+
return st->item[st->size - 1];
|
80
|
+
}
|
81
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#ifndef STACK_H__
|
2
|
+
#define STACK_H__
|
3
|
+
|
4
|
+
#include <stdlib.h>
|
5
|
+
|
6
|
+
struct stack {
|
7
|
+
void **item;
|
8
|
+
size_t size;
|
9
|
+
size_t asize;
|
10
|
+
};
|
11
|
+
|
12
|
+
void stack_free(struct stack *);
|
13
|
+
int stack_grow(struct stack *, size_t);
|
14
|
+
int stack_init(struct stack *, size_t);
|
15
|
+
|
16
|
+
int stack_push(struct stack *, void *);
|
17
|
+
|
18
|
+
void *stack_pop(struct stack *);
|
19
|
+
void *stack_top(struct stack *);
|
20
|
+
|
21
|
+
#endif
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.name = 'github-markdown'
|
4
|
+
s.version = '0.1.3'
|
5
|
+
s.summary = 'The Markdown parser for GitHub.com'
|
6
|
+
s.description = 'Self-contained Markdown parser for GitHub, with all our custom extensions'
|
7
|
+
s.date = '2012-04-04'
|
8
|
+
s.email = 'vicent@github.com'
|
9
|
+
s.homepage = 'http://github.github.com/github-flavored-markdown/'
|
10
|
+
s.authors = ['GitHub, Inc']
|
11
|
+
# = MANIFEST =
|
12
|
+
s.files = %w[
|
13
|
+
Rakefile
|
14
|
+
bin/gfm
|
15
|
+
ext/markdown/autolink.c
|
16
|
+
ext/markdown/autolink.h
|
17
|
+
ext/markdown/buffer.c
|
18
|
+
ext/markdown/buffer.h
|
19
|
+
ext/markdown/extconf.rb
|
20
|
+
ext/markdown/gh-markdown.c
|
21
|
+
ext/markdown/houdini.h
|
22
|
+
ext/markdown/houdini_href_e.c
|
23
|
+
ext/markdown/houdini_html_e.c
|
24
|
+
ext/markdown/html.c
|
25
|
+
ext/markdown/html.h
|
26
|
+
ext/markdown/html_blocks.h
|
27
|
+
ext/markdown/markdown.c
|
28
|
+
ext/markdown/markdown.h
|
29
|
+
ext/markdown/stack.c
|
30
|
+
ext/markdown/stack.h
|
31
|
+
github-markdown.gemspec
|
32
|
+
lib/github/markdown.rb
|
33
|
+
test/gfm_test.rb
|
34
|
+
]
|
35
|
+
# = MANIFEST =
|
36
|
+
s.test_files = ["test/gfm_test.rb"]
|
37
|
+
s.extensions = ["ext/markdown/extconf.rb"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.add_development_dependency "rake-compiler"
|
40
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
# GitHub Markdown Rendering class
|
3
|
+
#
|
4
|
+
# Provides a Markdown rendering method as a singleton, and two
|
5
|
+
# auxiliary functions
|
6
|
+
#
|
7
|
+
# There are two kinds of Markdown in GitHub.com:
|
8
|
+
#
|
9
|
+
# - Plain Markdown: used in Wikis, Pages and GitHub::Markup (READMEs).
|
10
|
+
# This is standards-compliant Markdown, with some of the PHP-Markdown
|
11
|
+
# extensions:
|
12
|
+
#
|
13
|
+
# - GitHub-flavored Markdown: used in user-input text, such as comments.
|
14
|
+
# Same extensions as Plain Markdown, and additionally the following
|
15
|
+
# extensions:
|
16
|
+
#
|
17
|
+
# GitHub::Markdown.render(content)
|
18
|
+
# #=> Rendered Markdown as HTML plaintext with the default extensions
|
19
|
+
#
|
20
|
+
# GitHub::Markdown.render_gfm(content)
|
21
|
+
# #=> Rendered GitHub-flavored Markdown as HTML plaintext
|
22
|
+
#
|
23
|
+
# GitHub::Markdown._to_html(content, mode) { |code, lang| ... }
|
24
|
+
# #=> Rendered Markdown with the given mode as HTML plaintext
|
25
|
+
module GitHub
|
26
|
+
class Markdown
|
27
|
+
def self.render(content)
|
28
|
+
self.to_html(content, :markdown)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.render_gfm(content)
|
32
|
+
self.to_html(content, :gfm)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Load the actual C extension
|
38
|
+
require 'github/markdown.so'
|
data/test/gfm_test.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
rootdir = File.dirname(File.dirname(__FILE__))
|
3
|
+
$LOAD_PATH.unshift "#{rootdir}/lib"
|
4
|
+
|
5
|
+
if defined? Encoding
|
6
|
+
Encoding.default_internal = 'UTF-8'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'test/unit'
|
10
|
+
require 'github/markdown'
|
11
|
+
require 'nokogiri'
|
12
|
+
|
13
|
+
def html_equal(html_a, html_b)
|
14
|
+
assert_equal Nokogiri::HTML::DocumentFragment.parse(html_a).to_html,
|
15
|
+
Nokogiri::HTML::DocumentFragment.parse(html_b).to_html
|
16
|
+
end
|
17
|
+
|
18
|
+
class GFMBasicTest < Test::Unit::TestCase
|
19
|
+
def test_that_render_works
|
20
|
+
GitHub::Markdown.to_html("Hello **world**!", :gfm)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_that_code_blocks_work
|
24
|
+
GitHub::Markdown.to_html("~~~~~~~~~~\nhello world!\n~~~~~~~~~\n", :gfm)
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: github-markdown
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- GitHub, Inc
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-04-04 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rake-compiler
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
description: Self-contained Markdown parser for GitHub, with all our custom extensions
|
35
|
+
email: vicent@github.com
|
36
|
+
executables: []
|
37
|
+
|
38
|
+
extensions:
|
39
|
+
- ext/markdown/extconf.rb
|
40
|
+
extra_rdoc_files: []
|
41
|
+
|
42
|
+
files:
|
43
|
+
- Rakefile
|
44
|
+
- bin/gfm
|
45
|
+
- ext/markdown/autolink.c
|
46
|
+
- ext/markdown/autolink.h
|
47
|
+
- ext/markdown/buffer.c
|
48
|
+
- ext/markdown/buffer.h
|
49
|
+
- ext/markdown/extconf.rb
|
50
|
+
- ext/markdown/gh-markdown.c
|
51
|
+
- ext/markdown/houdini.h
|
52
|
+
- ext/markdown/houdini_href_e.c
|
53
|
+
- ext/markdown/houdini_html_e.c
|
54
|
+
- ext/markdown/html.c
|
55
|
+
- ext/markdown/html.h
|
56
|
+
- ext/markdown/html_blocks.h
|
57
|
+
- ext/markdown/markdown.c
|
58
|
+
- ext/markdown/markdown.h
|
59
|
+
- ext/markdown/stack.c
|
60
|
+
- ext/markdown/stack.h
|
61
|
+
- github-markdown.gemspec
|
62
|
+
- lib/github/markdown.rb
|
63
|
+
- test/gfm_test.rb
|
64
|
+
homepage: http://github.github.com/github-flavored-markdown/
|
65
|
+
licenses: []
|
66
|
+
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
requirements: []
|
91
|
+
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.8.15
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: The Markdown parser for GitHub.com
|
97
|
+
test_files:
|
98
|
+
- test/gfm_test.rb
|