rpeg-markdown 0.1.0

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.
@@ -0,0 +1,84 @@
1
+ /* markdown_peg.h */
2
+
3
+ extern char *strdup(const char *string);
4
+
5
+ /**********************************************************************
6
+
7
+ Data Structures
8
+
9
+ ***********************************************************************/
10
+
11
+ /* Information (label, URL and title) for a link. */
12
+ struct Link {
13
+ struct Element *label;
14
+ char *url;
15
+ char *title;
16
+ };
17
+
18
+ typedef struct Link link;
19
+
20
+ /* Union for contents of an Element (string, list, or link). */
21
+ union Contents {
22
+ char *str;
23
+ struct Link link;
24
+ };
25
+
26
+ /* Types of semantic values returned by parsers. */
27
+ enum keys { LIST, /* A generic list of values. For ordered and bullet lists, see below. */
28
+ RAW, /* Raw markdown to be processed further */
29
+ SPACE,
30
+ LINEBREAK,
31
+ ELLIPSIS,
32
+ EMDASH,
33
+ ENDASH,
34
+ APOSTROPHE,
35
+ SINGLEQUOTED,
36
+ DOUBLEQUOTED,
37
+ STR,
38
+ LINK,
39
+ IMAGE,
40
+ CODE,
41
+ HTML,
42
+ EMPH,
43
+ STRONG,
44
+ PLAIN,
45
+ PARA,
46
+ LISTITEM,
47
+ BULLETLIST,
48
+ ORDEREDLIST,
49
+ H1, H2, H3, H4, H5, H6, /* Code assumes that these are in order. */
50
+ BLOCKQUOTE,
51
+ VERBATIM,
52
+ HTMLBLOCK,
53
+ HRULE,
54
+ REFERENCE,
55
+ NOTE,
56
+ };
57
+
58
+ /* Semantic value of a parsing action. */
59
+ struct Element {
60
+ int key;
61
+ union Contents contents;
62
+ struct Element *children;
63
+ struct Element *next;
64
+ };
65
+
66
+ typedef struct Element element;
67
+
68
+ enum markdown_extensions {
69
+ EXT_SMART = 1,
70
+ EXT_NOTES = 2
71
+ };
72
+
73
+ element *cons(element new, element *list);
74
+ element *reverse(element *list);
75
+ element markdown(char *string, int extensions);
76
+
77
+ /* Output formats. */
78
+ enum formats { HTML_FORMAT,
79
+ LATEX_FORMAT,
80
+ GROFF_MM_FORMAT
81
+ };
82
+
83
+ void print_element(element elt, int format);
84
+
data/lib/markdown.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'markdown.so'
2
+
3
+ class Markdown
4
+
5
+ # Original Markdown formatted text.
6
+ attr_reader :text
7
+
8
+ # Whether smarty-like quote translation should be performed.
9
+ attr_accessor :smart
10
+
11
+ # Whether footnotes should be
12
+ attr_accessor :notes
13
+
14
+ def initialize(text, *extensions)
15
+ @smart = false
16
+ @notes = false
17
+ @text = text
18
+ extensions.each { |e| send("#{e}=", true) }
19
+ end
20
+
21
+ end
data/test.rb ADDED
@@ -0,0 +1,25 @@
1
+ $: << File.join(File.dirname(__FILE__), "lib")
2
+
3
+ require 'test/unit'
4
+ require 'markdown'
5
+
6
+ class MarkdownTest < Test::Unit::TestCase
7
+
8
+ def test_that_extension_methods_are_present_on_markdown_class
9
+ assert Markdown.instance_methods.include?('to_html'),
10
+ "Markdown class should respond to #to_html"
11
+ end
12
+
13
+ def test_converting_simple_string_to_html
14
+ markdown = Markdown.new('Hello World.')
15
+ assert_respond_to markdown, :to_html
16
+ assert_equal "\n\n<p>Hello World.</p>", markdown.to_html
17
+ end
18
+
19
+ def test_converting_markup_string_to_html
20
+ markdown = Markdown.new('_Hello World_!')
21
+ assert_respond_to markdown, :to_html
22
+ assert_equal '<p><em>Hello World</em>!</p>', markdown.to_html
23
+ end
24
+
25
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rpeg-markdown
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Tomayko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-21 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: r@tomayko.com
18
+ executables:
19
+ - rpeg-markdown
20
+ extensions:
21
+ - ext/extconf.rb
22
+ extra_rdoc_files:
23
+ - README
24
+ - LICENSE
25
+ files:
26
+ - README
27
+ - LICENSE
28
+ - Rakefile
29
+ - test.rb
30
+ - lib/markdown.rb
31
+ - ext/extconf.rb
32
+ - ext/markdown.c
33
+ - ext/markdown_buffer.c
34
+ - ext/markdown_output.c
35
+ - ext/markdown_parser.c
36
+ - ext/markdown_buffer.h
37
+ - ext/markdown_peg.h
38
+ - bin/rpeg-markdown
39
+ has_rdoc: true
40
+ homepage: http://github.com/rtomayko/rpeg-markdown
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project: wink
61
+ rubygems_version: 1.1.1
62
+ signing_key:
63
+ specification_version: 2
64
+ summary: Ruby extension library for peg-markdown
65
+ test_files:
66
+ - test.rb