mdoc 0.0.3 → 0.0.5
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/.rubocop.yml +2 -0
- data/README.md +134 -47
- data/bin/mdoc +11 -32
- data/lib/mdoc/document/kramdown.rb +25 -0
- data/lib/mdoc/document.rb +87 -0
- data/lib/mdoc/meta.rb +14 -0
- data/lib/mdoc/options.rb +104 -0
- data/lib/mdoc/pipeline.rb +59 -0
- data/lib/mdoc/processor/add_title.rb +15 -0
- data/lib/mdoc/processor/add_toc.rb +11 -0
- data/lib/mdoc/processor/smart_code_block.rb +37 -0
- data/lib/mdoc/processor.rb +21 -0
- data/lib/mdoc/version.rb +3 -4
- data/lib/mdoc/writer.rb +18 -0
- data/lib/mdoc.rb +143 -2
- data/mdoc.gemspec +19 -19
- data/spec/add_title_spec.rb +10 -0
- data/spec/add_toc_spec.rb +12 -0
- data/spec/document_spec.rb +34 -0
- data/spec/execute_spec.rb +12 -0
- data/spec/find_doc_type_spec.rb +14 -0
- data/spec/fixtures/README.md +135 -0
- data/spec/fixtures/config/mdoc_a.cnf +1 -0
- data/spec/fixtures/config/mdoc_b.cnf +1 -0
- data/spec/fixtures/executes/a +0 -0
- data/spec/fixtures/executes/b +0 -0
- data/spec/fixtures/executes/c +0 -0
- data/spec/fixtures/general.txt +10 -0
- data/spec/fixtures/multikeys.html +18 -0
- data/{examples → spec/fixtures}/multikeys.md +10 -8
- data/{examples → spec/fixtures}/original.md +10 -10
- data/{examples → spec/fixtures}/pandoc.md +7 -7
- data/spec/fixtures/process.test.md +11 -0
- data/spec/fixtures/templates/default.html.erb +0 -0
- data/spec/fixtures/templates/pandoc.html.erb +0 -0
- data/spec/get_class_spec.rb +35 -0
- data/spec/kramdown_spec.rb +10 -0
- data/spec/meta_spec.rb +6 -0
- data/spec/options_spec.rb +66 -0
- data/spec/pipeline_spec.rb +95 -0
- data/spec/smart_code_block_spec.rb +10 -0
- data/spec/spec_helper.rb +40 -7
- data/spec/tpl_out_spec.rb +19 -0
- data/templates/default.html.erb +17 -0
- metadata +63 -25
- data/ROADMAP +0 -24
- data/config/members.yml +0 -16
- data/docs/css/jsgantt.css +0 -53
- data/docs/gantt.html +0 -237
- data/docs/js/jsgantt.js +0 -1681
- data/lib/mdoc/convert.rb +0 -92
- data/lib/mdoc/parser.rb +0 -80
- data/spec/parser_spec.rb +0 -32
data/lib/mdoc/convert.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
require 'tempfile'
|
2
|
-
require 'launchy'
|
3
|
-
require 'rest_client'
|
4
|
-
|
5
|
-
module Mdoc
|
6
|
-
class Html < Text
|
7
|
-
def convert
|
8
|
-
htmlname = @file.gsub(/\.md$/, '.html')
|
9
|
-
# content = `curl -X POST --data-urlencode content@#{@file} http://documentup.com/compiled`
|
10
|
-
title = @title
|
11
|
-
title = 'Preview' unless (title and title.size > 0)
|
12
|
-
|
13
|
-
resp = RestClient.post 'http://documentup.com/compiled', :content => @body, :name => title
|
14
|
-
content = resp.body
|
15
|
-
|
16
|
-
# convert the received content
|
17
|
-
content.gsub!('<title>undefined</title>', "<title>#{title}</title>")
|
18
|
-
content.gsub!('<a href="#" id="logo">undefined</a>', "<a href='\#' id='logo'>#{title}</a>")
|
19
|
-
wfh = File.new(htmlname, 'w')
|
20
|
-
wfh.write content
|
21
|
-
wfh.close
|
22
|
-
Launchy.open("file://" + htmlname)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class Pandoc < Text
|
27
|
-
def _convert type
|
28
|
-
base_name = @file.gsub(/\.md$/, '')
|
29
|
-
tmp_file = base_name + "__.md"
|
30
|
-
|
31
|
-
tfh = File.new(tmp_file, 'w:utf-8')
|
32
|
-
tfh.puts("% #{@title}") if @title
|
33
|
-
tfh.puts("% #{@author}") if @author
|
34
|
-
tfh.puts("% #{@date}") if @date
|
35
|
-
tfh.puts("")
|
36
|
-
tfh.puts(@body)
|
37
|
-
tfh.close
|
38
|
-
|
39
|
-
`pandoc -o #{base_name}.#{type} #{tmp_file}`
|
40
|
-
File.unlink tmp_file
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
class Rtf < Pandoc
|
45
|
-
def convert; self._convert('rtf') end
|
46
|
-
end
|
47
|
-
|
48
|
-
class Docx < Pandoc
|
49
|
-
def convert; self._convert('docx') end
|
50
|
-
end
|
51
|
-
|
52
|
-
class Epub < Pandoc
|
53
|
-
def convert; self._convert('epub') end
|
54
|
-
end
|
55
|
-
|
56
|
-
class Odt < Pandoc
|
57
|
-
def convert; self._convert('odt') end
|
58
|
-
end
|
59
|
-
|
60
|
-
class Pdf < Pandoc
|
61
|
-
def convert
|
62
|
-
self._convert('tex')
|
63
|
-
basename = @file.gsub(/\.md$/, '')
|
64
|
-
File.rename(basename + ".tex", basename + '__.tex')
|
65
|
-
fh = File.new(@file.gsub(/\.md$/, '.tex'), 'w:utf-8')
|
66
|
-
hd =<<ENDHEADER
|
67
|
-
\\documentclass[11pt,twocolumn]{article}
|
68
|
-
\\setlength{\\parindent}{2em}
|
69
|
-
\\usepackage{fontspec}
|
70
|
-
\\setmainfont{NSimSun}
|
71
|
-
\\usepackage{xeCJK}
|
72
|
-
|
73
|
-
\\begin{document}
|
74
|
-
ENDHEADER
|
75
|
-
|
76
|
-
fh.puts hd
|
77
|
-
rfh = File.new(basename + '__.tex', 'r:utf-8')
|
78
|
-
rfh.each do |line|
|
79
|
-
fh.puts line
|
80
|
-
end
|
81
|
-
|
82
|
-
fh.puts "\n\n\\end{document}\n\n"
|
83
|
-
rfh.close
|
84
|
-
fh.close
|
85
|
-
|
86
|
-
#`xelatex #{basename + ".tex"}`
|
87
|
-
|
88
|
-
#%w[log tex aux].each {|type| File.unlink(basename + ".#{type}")}
|
89
|
-
#File.unlink(basename + '__.tex')
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
data/lib/mdoc/parser.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
module Mdoc
|
4
|
-
class Text
|
5
|
-
attr_accessor :meta, :body, :title, :author, :date
|
6
|
-
|
7
|
-
def initialize file
|
8
|
-
@file = file
|
9
|
-
fh = file.is_a?(String) ? ::File.new(file, 'r:utf-8') : file
|
10
|
-
|
11
|
-
@raw_meta = Array.new
|
12
|
-
@body = String.new
|
13
|
-
|
14
|
-
first_line = true # if this is the first line
|
15
|
-
meta_type = nil # three meta format supported
|
16
|
-
on_meta = true # read lines on meta or on body
|
17
|
-
|
18
|
-
# parse the file, load all into the object
|
19
|
-
fh.each do |line|
|
20
|
-
|
21
|
-
# ignore heading blank lines
|
22
|
-
next if first_line and /^\s*$/.match(line)
|
23
|
-
|
24
|
-
# parse first line, determine the meta format
|
25
|
-
if first_line
|
26
|
-
first_line = false
|
27
|
-
if /\%\s*\-{3,}\s*$/ =~ line
|
28
|
-
meta_type = :o # original format
|
29
|
-
next # skip the first line
|
30
|
-
elsif /\%\s*.+$/ =~ line
|
31
|
-
meta_type = :p # pandoc format
|
32
|
-
elsif /^[a-z]+\:\s*/ =~ line
|
33
|
-
meta_type = :m # multi-key format
|
34
|
-
else
|
35
|
-
on_meta = false
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
if on_meta
|
40
|
-
# catch end of meta line
|
41
|
-
if meta_type == :o and /\%\s*\-{3,}\s*$/ =~ line
|
42
|
-
on_meta = false
|
43
|
-
next # skip the
|
44
|
-
elsif meta_type == :p
|
45
|
-
on_meta = false unless /^\%/ =~ line
|
46
|
-
elsif meta_type == :m and /^\s*$/ =~ line
|
47
|
-
on_meta = false
|
48
|
-
next
|
49
|
-
end
|
50
|
-
|
51
|
-
# puts line
|
52
|
-
@raw_meta << line.gsub(/^\s*\%\s*/, '').chomp
|
53
|
-
next
|
54
|
-
end
|
55
|
-
|
56
|
-
@body << line
|
57
|
-
end # parse lines
|
58
|
-
|
59
|
-
# set title, author and date
|
60
|
-
if meta_type == :p
|
61
|
-
@title = @raw_meta[0] || ''
|
62
|
-
@author= @raw_meta[1] || ''
|
63
|
-
@date = @raw_meta[2] || ''
|
64
|
-
@meta = {
|
65
|
-
'title' => @title,
|
66
|
-
'author' => @author,
|
67
|
-
'date' => @date
|
68
|
-
}
|
69
|
-
else
|
70
|
-
@meta = YAML.load(@raw_meta.join("\n"))
|
71
|
-
if @meta
|
72
|
-
@title = @meta['title'] || ''
|
73
|
-
@author= @meta['author'] || ''
|
74
|
-
@date = @meta['date'].to_s || ''
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
data/spec/parser_spec.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mdoc::Text do
|
4
|
-
context "pandoc format" do
|
5
|
-
subject(:mf) { Mdoc::Text.new('examples/pandoc.md') }
|
6
|
-
|
7
|
-
its(:title) { should eq('Pandoc Title') }
|
8
|
-
its(:author) { should eq('Author Like Me') }
|
9
|
-
its(:date) { should eq('Date in Some Format') }
|
10
|
-
its(:body) { should match('The first line of contents') }
|
11
|
-
its(:body) { should match('The Third line of contents') }
|
12
|
-
its(:body) { should eq("The first line of contents\r\n\r\nThe Third line of contents\r\n")}
|
13
|
-
end
|
14
|
-
|
15
|
-
context "original format" do
|
16
|
-
subject(:mf) { Mdoc::Text.new('examples/original.md') }
|
17
|
-
|
18
|
-
its(:title) { should eq('The title for our document') }
|
19
|
-
its(:author) { should eq('unknown person') }
|
20
|
-
its(:date) { should eq('2009-08-01') }
|
21
|
-
its(:body) { should eq("\r\nThe content inside\r\n")}
|
22
|
-
end
|
23
|
-
|
24
|
-
context "multi-key format" do
|
25
|
-
subject(:mf) { Mdoc::Text.new('examples/multikeys.md') }
|
26
|
-
|
27
|
-
its(:title) { should eq('The title for our document') }
|
28
|
-
its(:author) { should eq('unknown person') }
|
29
|
-
its(:date) { should eq('2009-08-01') }
|
30
|
-
its(:body) { should match("The content inside")}
|
31
|
-
end
|
32
|
-
end
|