pfm 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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +60 -0
- data/bin/pfm +32 -0
- data/lib/pfm.rb +138 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a8ffc1441bca5b36a1f20521b68349d24e613b4c
|
4
|
+
data.tar.gz: af01484f2f9daf15c3ddc4f1c1045f3d865fa40b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bfeb95b7f659475b07328f4790ae2ea6cba6c69a13f68157d680ea0b144c4d2c5a9d09d1f211a23a039287e2d8be38b7f0e757c5fb85ff745c25d5db73eef0f3
|
7
|
+
data.tar.gz: edc5f01d8af829725d2b24ec7ec1b29fe400b3d78effb9ad7ab394338eae9954bb88b86d67d8e4f1ade69bee7924839a0ea62f9ddfb538c9faff7304cde57e91
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Panda Strike
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Panda Flavored Markdown
|
2
|
+
|
3
|
+
A few clever extensions to GitHub Flavored Markdown syntax.
|
4
|
+
|
5
|
+
* Code block includes
|
6
|
+
* Pandoc-style footnotes
|
7
|
+
|
8
|
+
## Code Block includes
|
9
|
+
|
10
|
+
Include as a code block all of the content from another file (paths
|
11
|
+
relative to PWD). The code block type will be inferred from the
|
12
|
+
file extension when possible.
|
13
|
+
|
14
|
+
```path/to/source.coffee```
|
15
|
+
|
16
|
+
Include only a selection of the file content:
|
17
|
+
|
18
|
+
|
19
|
+
```path/to/source.coffee#L33-42```
|
20
|
+
|
21
|
+
|
22
|
+
## Pandoc's footnote syntax
|
23
|
+
|
24
|
+
This text:
|
25
|
+
|
26
|
+
Sometimes you wish to have a footnote, but GFM[^gfm] doesn't have a syntax
|
27
|
+
for it. Pandoc[^pandoc] has a nice syntax as illustrated here.
|
28
|
+
|
29
|
+
|
30
|
+
[^gfm]: GitHub Flavored Markdown.
|
31
|
+
|
32
|
+
[^pandoc]: [Pandoc](http://johnmacfarlane.net/pandoc/) is the swiss-army
|
33
|
+
knife of document conversion tools.
|
34
|
+
|
35
|
+
The location of the footnote definitions doesn't matter, as they will be
|
36
|
+
collected and appended to a Notes section at the end of the document.
|
37
|
+
|
38
|
+
|
39
|
+
Processes to this markdown:
|
40
|
+
|
41
|
+
|
42
|
+
```markdown
|
43
|
+
Sometimes you wish to have a footnote, but GFM<sup><a name="__gfm" href="#gfm">1</a>.</sup> doesn't have a syntax
|
44
|
+
for it. Pandoc<sup><a name="__pandoc" href="#pandoc">2</a>.</sup> has a nice syntax as illustrated here.
|
45
|
+
|
46
|
+
|
47
|
+
The location of the footnote definitions doesn't matter, as they will be
|
48
|
+
collected and appended to a Notes section at the end of the document.
|
49
|
+
|
50
|
+
# Notes
|
51
|
+
|
52
|
+
<a name="gfm" href="#__gfm">1 ↩</a>. GitHub Flavored Markdown.
|
53
|
+
|
54
|
+
<a name="pandoc" href="#__pandoc">2 ↩</a>. [Pandoc](http://johnmacfarlane.net/pandoc/) is the swiss-army
|
55
|
+
knife of document conversion tools.
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
|
60
|
+
|
data/bin/pfm
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
project = File.expand_path("#{File.dirname(__FILE__)}/../")
|
4
|
+
$LOAD_PATH.unshift "#{project}/lib"
|
5
|
+
|
6
|
+
require "optparse"
|
7
|
+
require "pfm"
|
8
|
+
|
9
|
+
options = {}
|
10
|
+
|
11
|
+
parser = OptionParser.new do |opts|
|
12
|
+
|
13
|
+
opts.on "-o", "--output FILE", "path to a file to write output" do |file|
|
14
|
+
options[:file] = file
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
parser.parse!
|
20
|
+
|
21
|
+
input = ARGF.read
|
22
|
+
|
23
|
+
output = PFM.process(input, options)
|
24
|
+
|
25
|
+
if options[:file]
|
26
|
+
File.open options[:file], "w" do |f|
|
27
|
+
f.puts output
|
28
|
+
end
|
29
|
+
else
|
30
|
+
STDOUT.puts(output)
|
31
|
+
end
|
32
|
+
|
data/lib/pfm.rb
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
|
2
|
+
module PFM
|
3
|
+
|
4
|
+
def self.process(string, options={})
|
5
|
+
lines = string.split("\n")
|
6
|
+
out = FootnoteProcessor.new.process(lines)
|
7
|
+
out = CodeBlockInclude.new.process(out)
|
8
|
+
|
9
|
+
processed = out.join("\n")
|
10
|
+
end
|
11
|
+
|
12
|
+
class CodeBlockInclude
|
13
|
+
def initialize(options={})
|
14
|
+
@regex = %r{^```([^\s#]+)(#L(\S+))?\s*```$}
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def process(lines)
|
19
|
+
# TODO: handle URLs
|
20
|
+
out = []
|
21
|
+
lines.each do |line|
|
22
|
+
if md = @regex.match(line)
|
23
|
+
_full, source_path, badline, line_spec = md.to_a
|
24
|
+
if line_spec
|
25
|
+
start, stop = line_spec.split("-").map { |s| s.to_i}
|
26
|
+
else
|
27
|
+
start = 1
|
28
|
+
end
|
29
|
+
|
30
|
+
source_path = File.expand_path(source_path).strip
|
31
|
+
extension = File.extname(source_path).slice(1..-1)
|
32
|
+
out << "```#{extension}"
|
33
|
+
|
34
|
+
embed = []
|
35
|
+
File.open(source_path, "r") do |source|
|
36
|
+
source.each_line do |line|
|
37
|
+
embed << line
|
38
|
+
end
|
39
|
+
end
|
40
|
+
start -= 1
|
41
|
+
if stop
|
42
|
+
stop -=1
|
43
|
+
else
|
44
|
+
stop = embed.size - 1
|
45
|
+
end
|
46
|
+
selection = embed.slice(start..stop)
|
47
|
+
while selection.last =~ /^\s+$/
|
48
|
+
selection.pop
|
49
|
+
end
|
50
|
+
out << selection.join()
|
51
|
+
out << "```\n"
|
52
|
+
else
|
53
|
+
out << line
|
54
|
+
end
|
55
|
+
end
|
56
|
+
out
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
# Converts Pandoc-style footnotes into appropriate HTML
|
62
|
+
class FootnoteProcessor
|
63
|
+
|
64
|
+
def initialize(options={})
|
65
|
+
# looking for footnote refs like [^some_identifier]
|
66
|
+
@note_regex = /
|
67
|
+
^
|
68
|
+
\[\^
|
69
|
+
([\d\w\-_]+)
|
70
|
+
\]:
|
71
|
+
/x
|
72
|
+
@ref_regex = /
|
73
|
+
\[\^
|
74
|
+
([\d\w\-_]+)
|
75
|
+
\]
|
76
|
+
/x
|
77
|
+
end
|
78
|
+
|
79
|
+
def process(lines)
|
80
|
+
out = []
|
81
|
+
refs = []
|
82
|
+
notes = {}
|
83
|
+
ref_counter = 0
|
84
|
+
while line = lines.shift
|
85
|
+
if md = @note_regex.match(line)
|
86
|
+
full, identifier = md.to_a
|
87
|
+
note = notes[identifier] = [line]
|
88
|
+
while (next_line = lines.shift) && next_line !~ /^\s*$/
|
89
|
+
note << next_line
|
90
|
+
end
|
91
|
+
|
92
|
+
elsif md = @ref_regex.match(line)
|
93
|
+
full, identifier = md.to_a
|
94
|
+
ref_counter += 1
|
95
|
+
refs << identifier
|
96
|
+
out << line.sub(full, format_ref(ref_counter, identifier))
|
97
|
+
else
|
98
|
+
out << line
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
if refs.size > 0
|
103
|
+
out << ""
|
104
|
+
out << "# Notes"
|
105
|
+
out << ""
|
106
|
+
refs.each_with_index do |identifier, index|
|
107
|
+
if note = notes[identifier]
|
108
|
+
start = note.shift
|
109
|
+
anchor = format_anchor(index + 1, identifier)
|
110
|
+
start.sub! /^\[.*\]: /, ""
|
111
|
+
out << "#{anchor} #{start}"
|
112
|
+
|
113
|
+
note.each do |line|
|
114
|
+
out << line
|
115
|
+
end
|
116
|
+
out << ""
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
out << ""
|
121
|
+
out
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
def format_anchor(number, identifier)
|
126
|
+
%Q{<a name="#{identifier}" href="#__#{identifier}">#{number} ↩</a>.}
|
127
|
+
end
|
128
|
+
|
129
|
+
def format_ref(number, identifier)
|
130
|
+
%Q{
|
131
|
+
<sup><a name="__#{identifier}" href="##{identifier}">#{number}</a>.</sup>
|
132
|
+
}.strip
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
end
|
138
|
+
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pfm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew King
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: starter
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.2'
|
27
|
+
description: A few extensions of GitHub Flavored Markdown syntax
|
28
|
+
email: matthew@pandastrike.com
|
29
|
+
executables:
|
30
|
+
- pfm
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- bin/pfm
|
37
|
+
- lib/pfm.rb
|
38
|
+
homepage: https://github.com/pandastrike/pfm-rb
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
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
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 2.2.0
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: Panda Flavored Markdown
|
62
|
+
test_files: []
|