markdown_helper 0.1.0 → 0.1.1
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +11 -8
- data/lib/markdown_helper/version.rb +1 -1
- data/lib/markdown_helper.rb +49 -26
- data/markdown_helper.gemspec +2 -2
- data/readme/README.template.md +11 -8
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ace2948d3bb763d09030ba4d4a55fd3f098a6e42
|
4
|
+
data.tar.gz: 8472ec4219bec0e1f81c2c9ced8b1a511efd2858
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c8641b78321d8d2d8efb659591883efaa80b31510542c28a73778b43a46e78d777176ac66f586d8e001438cc5017635c5172888f529e08224389d091f62a124
|
7
|
+
data.tar.gz: 0b1540cff797e44a371a0c4667bfbcd2ecc75f93fabc068c4738bcd4d4a6a59d50604e3cbe6cb3ceab9039a651c34863299b621f64237969b5afb2ad5c036143
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# MarkdownHelper
|
2
2
|
|
3
|
-
## File Inclusion <img src="/images/include.png" width="50">
|
3
|
+
## File Inclusion <img src="https://github.com/BurdetteLamar/MarkdownHelper/blob/master/images/include.png" width="50">
|
4
4
|
|
5
5
|
This markdown helper enables file inclusion in GitHub markdown.
|
6
6
|
|
@@ -32,9 +32,9 @@ end
|
|
32
32
|
|
33
33
|
or verbatim (which GitHub renders however it likes).
|
34
34
|
|
35
|
-
|
35
|
+
### Usage
|
36
36
|
|
37
|
-
|
37
|
+
#### Specify Include Files with Pragmas
|
38
38
|
|
39
39
|
<code>include.md</code>
|
40
40
|
```verbatim
|
@@ -45,16 +45,19 @@ or verbatim (which GitHub renders however it likes).
|
|
45
45
|
@[:verbatim](include.rb)
|
46
46
|
```
|
47
47
|
|
48
|
-
|
48
|
+
An inclusion pragma has the form:
|
49
49
|
|
50
|
-
|
51
|
-
|
50
|
+
```@[```*treatment*```](```*relative_file_path*```)```
|
51
|
+
|
52
|
+
where:
|
53
|
+
|
54
|
+
* *treatment* (in square brackets) is one of the following:
|
52
55
|
* Highlighting mode such as ```[ruby]```, to include a highlighted code block. This can be any Ace mode mentioned in [GitHub Languages](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml).
|
53
56
|
* ```[:code_block]```, to include a plain code block.
|
54
57
|
* ```[:verbatim]```, to include text verbatim (to be rendered as markdown).
|
55
|
-
*
|
58
|
+
* *relative_file_path* points to the file to be included.
|
56
59
|
|
57
|
-
|
60
|
+
#### Include the Files with ```MarkdownHelper#include```
|
58
61
|
|
59
62
|
<code>usage.rb</code>
|
60
63
|
```ruby
|
data/lib/markdown_helper.rb
CHANGED
@@ -1,43 +1,51 @@
|
|
1
1
|
require 'markdown_helper/version'
|
2
2
|
|
3
|
+
# Helper class for working with GitHub markdown.
|
4
|
+
# Supports file inclusion.
|
5
|
+
#
|
6
|
+
# @author Burdette Lamar
|
3
7
|
class MarkdownHelper
|
4
8
|
|
5
9
|
INCLUDE_REGEXP = /^@\[(:code_block|:verbatim|\w+)\]/
|
6
10
|
|
7
|
-
|
11
|
+
# For later.
|
12
|
+
# attr_accessor :tag_as_generated
|
8
13
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
+
# For later.
|
15
|
+
# DEFAULT_TREATMENT_FOR_FILE_EXT = {
|
16
|
+
# :md => :verbatim,
|
17
|
+
# :rb => 'ruby',
|
18
|
+
# :xml => 'xml',
|
19
|
+
# }
|
14
20
|
|
15
21
|
def initialize
|
16
|
-
|
17
|
-
@treatment_for_file_ext
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
def get_treatment(file_type)
|
22
|
-
@treatment_for_file_ext[file_type]
|
23
|
-
end
|
24
|
-
|
25
|
-
def set_treatment(file_type, treatment)
|
26
|
-
treatment_symbols = [:verbatim, :code_block]
|
27
|
-
if treatment_symbols.include?(treatment) || treatment.kind_of?(String)
|
28
|
-
@treatment_for_file_ext[file_type] = treatment
|
29
|
-
else
|
30
|
-
message = "treatment must be a single word or must be in #{treatment_symbols.inspect}, not #{treatment.inspect}"
|
31
|
-
raise ArgumentError.new(message)
|
32
|
-
end
|
22
|
+
# For later.
|
23
|
+
# @treatment_for_file_ext = DEFAULT_TREATMENT_FOR_FILE_EXT
|
24
|
+
# @treatment_for_file_ext.default = :code_block
|
25
|
+
# self.tag_as_generated = false
|
33
26
|
end
|
34
27
|
|
28
|
+
# Merges external files into markdown text.
|
29
|
+
# @param template_file_path [String] the path to the input template markdown file, usually containing include pragmas.
|
30
|
+
# @param markdown_file_path [String] the path to the output merged markdown file.
|
31
|
+
# @raise [RuntimeError] if an include pragma parsing error occurs.
|
32
|
+
# @return [String] the resulting markdown text.
|
33
|
+
#
|
34
|
+
# @example Pragma to include text as a highlighted code block.
|
35
|
+
# @[ruby](foo.rb)
|
36
|
+
#
|
37
|
+
# @example Pragma to include text as a plain code block.
|
38
|
+
# @[:code_block](foo.xyz)
|
39
|
+
#
|
40
|
+
# @example Pragma to include text verbatim, to be rendered as markdown.
|
41
|
+
# @[:verbatim](foo.md)
|
35
42
|
def include(template_file_path, markdown_file_path)
|
36
43
|
output_lines = []
|
37
44
|
File.open(template_file_path, 'r') do |template_file|
|
38
|
-
|
39
|
-
|
40
|
-
|
45
|
+
# For later.
|
46
|
+
# if tag_as_generated
|
47
|
+
# output_lines.push("<!--- GENERATED FILE, DO NOT EDIT --->\n")
|
48
|
+
# end
|
41
49
|
template_file.each_line do |input_line|
|
42
50
|
match_data = input_line.match(INCLUDE_REGEXP)
|
43
51
|
unless match_data
|
@@ -91,4 +99,19 @@ class MarkdownHelper
|
|
91
99
|
output
|
92
100
|
end
|
93
101
|
|
102
|
+
# For later.
|
103
|
+
# def get_treatment(file_type)
|
104
|
+
# @treatment_for_file_ext[file_type]
|
105
|
+
# end
|
106
|
+
#
|
107
|
+
# def set_treatment(file_type, treatment)
|
108
|
+
# treatment_symbols = [:verbatim, :code_block]
|
109
|
+
# if treatment_symbols.include?(treatment) || treatment.kind_of?(String)
|
110
|
+
# @treatment_for_file_ext[file_type] = treatment
|
111
|
+
# else
|
112
|
+
# message = "treatment must be a single word or must be in #{treatment_symbols.inspect}, not #{treatment.inspect}"
|
113
|
+
# raise ArgumentError.new(message)
|
114
|
+
# end
|
115
|
+
# end
|
116
|
+
|
94
117
|
end
|
data/markdown_helper.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ['burdettelamar']
|
10
10
|
spec.email = ['BurdetteLamar@Yahoo.com']
|
11
11
|
|
12
|
-
spec.summary = '
|
13
|
-
spec.description = '
|
12
|
+
spec.summary = 'Class to help with GitHub markdown.'
|
13
|
+
spec.description = 'Class to help with GitHub markdown. So far: file inclusion.'
|
14
14
|
spec.homepage = 'https://rubygems.org/gems/markdown_helper'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
data/readme/README.template.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# MarkdownHelper
|
2
2
|
|
3
|
-
## File Inclusion <img src="/images/include.png" width="50">
|
3
|
+
## File Inclusion <img src="https://github.com/BurdetteLamar/MarkdownHelper/blob/master/images/include.png" width="50">
|
4
4
|
|
5
5
|
This markdown helper enables file inclusion in GitHub markdown.
|
6
6
|
|
@@ -18,21 +18,24 @@ or plain in a code block:
|
|
18
18
|
|
19
19
|
or verbatim (which GitHub renders however it likes).
|
20
20
|
|
21
|
-
|
21
|
+
### Usage
|
22
22
|
|
23
|
-
|
23
|
+
#### Specify Include Files with Pragmas
|
24
24
|
|
25
25
|
@[verbatim](include.md)
|
26
26
|
|
27
|
-
|
27
|
+
An inclusion pragma has the form:
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
```@[```*treatment*```](```*relative_file_path*```)```
|
30
|
+
|
31
|
+
where:
|
32
|
+
|
33
|
+
* *treatment* (in square brackets) is one of the following:
|
31
34
|
* Highlighting mode such as ```[ruby]```, to include a highlighted code block. This can be any Ace mode mentioned in [GitHub Languages](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml).
|
32
35
|
* ```[:code_block]```, to include a plain code block.
|
33
36
|
* ```[:verbatim]```, to include text verbatim (to be rendered as markdown).
|
34
|
-
*
|
37
|
+
* *relative_file_path* points to the file to be included.
|
35
38
|
|
36
|
-
|
39
|
+
#### Include the Files with ```MarkdownHelper#include```
|
37
40
|
|
38
41
|
@[ruby](usage.rb)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: markdown_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- burdettelamar
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.3'
|
69
|
-
description: '
|
69
|
+
description: 'Class to help with GitHub markdown. So far: file inclusion.'
|
70
70
|
email:
|
71
71
|
- BurdetteLamar@Yahoo.com
|
72
72
|
executables: []
|
@@ -119,5 +119,5 @@ rubyforge_project:
|
|
119
119
|
rubygems_version: 2.4.5.2
|
120
120
|
signing_key:
|
121
121
|
specification_version: 4
|
122
|
-
summary:
|
122
|
+
summary: Class to help with GitHub markdown.
|
123
123
|
test_files: []
|