markdown_helper 0.2.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 128fe00dd89389615391ceb4cc69127317a7249b
4
- data.tar.gz: bc50bd8214659764a83503c2a02f36a8c5795ec7
3
+ metadata.gz: 9350e847948120c0b6cd8da04deb1eb77a915631
4
+ data.tar.gz: f5eb9065d158d45ee87d0f4cb0e9e9e74529c48c
5
5
  SHA512:
6
- metadata.gz: 6b11b8fc50ede26c160679b2fa750653e8f1b78e84b824052c233a53a35d2672812b322e76aab382e3476fa5c0ba1c21935fecc154cefd7bd22c54cc38cb11eb
7
- data.tar.gz: efe58d2174a05141b743346b0a9fe043681fcd30f13111400d67c25b5015e5bbdfd771116d9cc64c4db3724061130af82ecaee2817f39a2de6c85e4ffd6ef203
6
+ metadata.gz: e98b19de2d10445af71e05e271f73c0de7ea563c7d009e9870ab7783b3a8a20a33fae2463fc6ffa1ba841deda72df0edd97f1880352cf5e7fb7fed5e90073602
7
+ data.tar.gz: c7f039f5e9ec548b713c23c759a6e34918eec4f25f20b900375d002c0f3caaa76124972bbd4a25310a4a84814061811436634a784b933c58773b5eb2f469a08b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdown_helper (0.2.4)
4
+ markdown_helper (1.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,10 +1,14 @@
1
1
  <!-- >>>>>> BEGIN GENERATED FILE (include): SOURCE readme_files/temp_resolved.md -->
2
2
  <!-- >>>>>> BEGIN GENERATED FILE (resolve): SOURCE readme_files/README.template.md -->
3
- # MarkdownHelper
3
+ # Markdown Helper
4
4
 
5
- ## What's This?
5
+ <!-- >>>>>> BEGIN RESOLVED IMAGES: INPUT-LINE '![Gem Version](https://badge.fury.io/rb/markdown_helper.svg)
6
+ ' -->
7
+ <img src="https://badge.fury.io/rb/markdown_helper.svg" alt="Gem Version">
8
+ <!-- <<<<<< END RESOLVED IMAGES: INPUT-LINE '![Gem Version](https://badge.fury.io/rb/markdown_helper.svg)
9
+ ' -->
6
10
 
7
- [![Gem Version](https://badge.fury.io/rb/markdown_helper.svg)](https://badge.fury.io/rb/markdown_helper)
11
+ ## What's This?
8
12
 
9
13
  Class <code>MarkdownHelper</code> supports:
10
14
 
@@ -30,10 +34,10 @@ You can suppress those comments using the <code>pristine</code> option.
30
34
 
31
35
  ## File Inclusion
32
36
 
33
- <!-- >>>>>> BEGIN RESOLVED IMAGE: DESCRIPTION '![include_icon](images/include.png | width=50)
37
+ <!-- >>>>>> BEGIN RESOLVED IMAGES: INPUT-LINE '![include_icon](images/include.png | width=50)
34
38
  ' -->
35
- <img src="https://raw.githubusercontent.com/BurdetteLamar/MarkdownHelper/master/images/include.png" alt="include_icon" width="50">
36
- <!-- <<<<<< END RESOLVED IMAGE: DESCRIPTION '![include_icon](images/include.png | width=50)
39
+ <img src="https://raw.githubusercontent.com/BurdetteLamar/markdown_helper/master/images/include.png" alt="include_icon" width="50">
40
+ <!-- <<<<<< END RESOLVED IMAGES: INPUT-LINE '![include_icon](images/include.png | width=50)
37
41
  ' -->
38
42
 
39
43
  This markdown helper enables file inclusion in GitHub markdown.
@@ -152,10 +156,10 @@ where:
152
156
 
153
157
  ## Image Path Resolution
154
158
 
155
- <!-- >>>>>> BEGIN RESOLVED IMAGE: DESCRIPTION '![image_icon](images/image.png | width=50)
159
+ <!-- >>>>>> BEGIN RESOLVED IMAGES: INPUT-LINE '![image_icon](images/image.png | width=50)
156
160
  ' -->
157
- <img src="https://raw.githubusercontent.com/BurdetteLamar/MarkdownHelper/master/images/image.png" alt="image_icon" width="50">
158
- <!-- <<<<<< END RESOLVED IMAGE: DESCRIPTION '![image_icon](images/image.png | width=50)
161
+ <img src="https://raw.githubusercontent.com/BurdetteLamar/markdown_helper/master/images/image.png" alt="image_icon" width="50">
162
+ <!-- <<<<<< END RESOLVED IMAGES: INPUT-LINE '![image_icon](images/image.png | width=50)
159
163
  ' -->
160
164
 
161
165
  This markdown helper enables image path resolution in GitHub markdown.
@@ -236,10 +240,10 @@ where:
236
240
 
237
241
  ## Image Attributes
238
242
 
239
- <!-- >>>>>> BEGIN RESOLVED IMAGE: DESCRIPTION '![html_icon](images/html.png | width=50)
243
+ <!-- >>>>>> BEGIN RESOLVED IMAGES: INPUT-LINE '![html_icon](images/html.png | width=50)
240
244
  ' -->
241
- <img src="https://raw.githubusercontent.com/BurdetteLamar/MarkdownHelper/master/images/html.png" alt="html_icon" width="50">
242
- <!-- <<<<<< END RESOLVED IMAGE: DESCRIPTION '![html_icon](images/html.png | width=50)
245
+ <img src="https://raw.githubusercontent.com/BurdetteLamar/markdown_helper/master/images/html.png" alt="html_icon" width="50">
246
+ <!-- <<<<<< END RESOLVED IMAGES: INPUT-LINE '![html_icon](images/html.png | width=50)
243
247
  ' -->
244
248
 
245
249
  This markdown helper enables HTML image attributes in GitHub markdown [image descriptions](https://github.github.com/gfm/#image-description).
@@ -318,13 +322,13 @@ where:
318
322
 
319
323
  ## What Should Be Next?
320
324
 
321
- I have opened some enhancement Issues in the GitHub [MarkdownHelper](https://github.com/BurdetteLamar/MarkdownHelper) project:
325
+ I have opened some enhancement Issues in the GitHub [markdown_helper](https://github.com/BurdetteLamar/markdown_helper) project:
322
326
 
323
- * [Pagination](https://github.com/BurdetteLamar/MarkdownHelper/issues/40): series of markdown pages connected by prev/next navigation links.
324
- * [Partial file inclusion](https://github.com/BurdetteLamar/MarkdownHelper/issues/38): including only specified lines from a file (instead of the whole file).
325
- * [Ruby-entity inclusion](https://github.com/BurdetteLamar/MarkdownHelper/issues/39): like file inclusion, but including a Ruby class, module, or method.
326
- * [File TOC](https://github.com/BurdetteLamar/MarkdownHelper/issues/36): table of contents of all headers in a markdown page.
327
- * [Project TOC](https://github.com/BurdetteLamar/MarkdownHelper/issues/37): table of contents of all markdown pages in project.
327
+ * [File TOC](https://github.com/BurdetteLamar/markdown_helper/issues/36): table of contents of all headers in a markdown page.
328
+ * [Project TOC](https://github.com/BurdetteLamar/markdown_helper/issues/37): table of contents of all markdown pages in project.
329
+ * [Partial file inclusion](https://github.com/BurdetteLamar/markdown_helper/issues/38): including only specified lines from a file (instead of the whole file).
330
+ * [Ruby-entity inclusion](https://github.com/BurdetteLamar/markdown_helper/issues/39): like file inclusion, but including a Ruby class, module, or method.
331
+ * [Pagination](https://github.com/BurdetteLamar/markdown_helper/issues/40): series of markdown pages connected by prev/next navigation links.
328
332
 
329
333
  Feel free to comment on any of these, or to add more Issues (enhancement or otherwise).
330
334
  <!-- <<<<<< END GENERATED FILE (resolve): SOURCE readme_files/README.template.md -->
data/_config.yml ADDED
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-cayman
@@ -1,3 +1,3 @@
1
1
  class MarkdownHelper
2
- VERSION = '0.2.4'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -6,8 +6,8 @@ require 'markdown_helper/version'
6
6
  # @author Burdette Lamar
7
7
  class MarkdownHelper
8
8
 
9
- IMAGE_REGEXP = /^!\[([^\[]+)\]\(([^)]+)\)/
10
- INCLUDE_REGEXP = /^@\[([^\[]+)\]\(([^)]+)\)/
9
+ IMAGE_REGEXP = /!\[([^\[]+)\]\(([^)]+)\)/
10
+ INCLUDE_REGEXP = /^@\[([^\[]+)\]\(([^)]+)\)$/
11
11
 
12
12
  attr_accessor :pristine
13
13
 
@@ -104,41 +104,12 @@ class MarkdownHelper
104
104
  # Method :generate_file does the first things, yields the block, does the last things.
105
105
  output = send(:generate_file, template_file_path, markdown_file_path, __method__) do |input_lines, output_lines|
106
106
  input_lines.each do |input_line|
107
- match_data = input_line.match(IMAGE_REGEXP)
108
- unless match_data
107
+ scan_data = input_line.scan(IMAGE_REGEXP)
108
+ if scan_data.empty?
109
109
  output_lines.push(input_line)
110
110
  next
111
111
  end
112
- send(:comment_resolve, input_line, output_lines) do
113
- alt_text = match_data[1]
114
- relative_file_path, attributes_s = match_data[2].split(/\s?\|\s?/, 2)
115
- attributes = attributes_s ? attributes_s.split(/\s+/) : []
116
- formatted_attributes = ['']
117
- attributes.each do |attribute|
118
- name, value = attribute.split('=', 2)
119
- formatted_attributes.push(format('%s="%s"', name, value))
120
- end
121
- formatted_attributes_s = formatted_attributes.join(' ')
122
- repo_user, repo_name = repo_user_and_name
123
- absolute_file_path = nil
124
- if relative_file_path.start_with?('http')
125
- absolute_file_path = relative_file_path
126
- else
127
- absolute_file_path = File.join(
128
- "https://raw.githubusercontent.com/#{repo_user}/#{repo_name}/master",
129
- relative_file_path,
130
- )
131
- end
132
- following_text = input_line.sub(IMAGE_REGEXP, '').chomp
133
- line = format(
134
- '<img src="%s" alt="%s"%s>%s',
135
- absolute_file_path,
136
- alt_text,
137
- formatted_attributes_s,
138
- following_text
139
- ) + "\n"
140
- output_lines.push(line)
141
- end
112
+ send(:resolve_images, scan_data, input_line, output_lines)
142
113
  end
143
114
  end
144
115
  output
@@ -193,10 +164,38 @@ class MarkdownHelper
193
164
  output_lines.push(comment(" <<<<<< END INCLUDED FILE (#{treatment}): SOURCE #{include_file.path} ")) unless pristine
194
165
  end
195
166
 
196
- def comment_resolve(description, output_lines)
197
- output_lines.push(comment(" >>>>>> BEGIN RESOLVED IMAGE: DESCRIPTION '#{description}' ")) unless pristine
198
- yield
199
- output_lines.push(comment(" <<<<<< END RESOLVED IMAGE: DESCRIPTION '#{description}' ")) unless pristine
167
+ def resolve_images(scan_data, input_line, output_lines)
168
+ output_lines.push(comment(" >>>>>> BEGIN RESOLVED IMAGES: INPUT-LINE '#{input_line}' ")) unless pristine
169
+ output_line = input_line
170
+ scan_data.each do |alt_text, path_and_attributes|
171
+ relative_file_path, attributes_s =path_and_attributes.split(/\s?\|\s?/, 2)
172
+ attributes = attributes_s ? attributes_s.split(/\s+/) : []
173
+ formatted_attributes = ['']
174
+ attributes.each do |attribute|
175
+ name, value = attribute.split('=', 2)
176
+ formatted_attributes.push(format('%s="%s"', name, value))
177
+ end
178
+ formatted_attributes_s = formatted_attributes.join(' ')
179
+ repo_user, repo_name = repo_user_and_name
180
+ absolute_file_path = nil
181
+ if relative_file_path.start_with?('http')
182
+ absolute_file_path = relative_file_path
183
+ else
184
+ absolute_file_path = File.join(
185
+ "https://raw.githubusercontent.com/#{repo_user}/#{repo_name}/master",
186
+ relative_file_path,
187
+ )
188
+ end
189
+ img_element = format(
190
+ '<img src="%s" alt="%s"%s>',
191
+ absolute_file_path,
192
+ alt_text,
193
+ formatted_attributes_s,
194
+ )
195
+ output_line = output_line.sub(IMAGE_REGEXP, img_element)
196
+ end
197
+ output_lines.push(output_line)
198
+ output_lines.push(comment(" <<<<<< END RESOLVED IMAGES: INPUT-LINE '#{input_line}' ")) unless pristine
200
199
  end
201
200
 
202
201
  end
@@ -17,7 +17,7 @@ Class to help with GitHub markdown:
17
17
  * Image path resolution
18
18
  * Image attributes
19
19
  EOT
20
- spec.homepage = 'https://github.com/BurdetteLamar/MarkdownHelper'
20
+ spec.homepage = 'https://github.com/BurdetteLamar/markdown_helper'
21
21
  spec.license = 'MIT'
22
22
 
23
23
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
@@ -1,8 +1,8 @@
1
- # MarkdownHelper
1
+ # Markdown Helper
2
2
 
3
- ## What's This?
3
+ ![Gem Version](https://badge.fury.io/rb/markdown_helper.svg)
4
4
 
5
- [![Gem Version](https://badge.fury.io/rb/markdown_helper.svg)](https://badge.fury.io/rb/markdown_helper)
5
+ ## What's This?
6
6
 
7
7
  Class <code>MarkdownHelper</code> supports:
8
8
 
@@ -160,12 +160,12 @@ where:
160
160
 
161
161
  ## What Should Be Next?
162
162
 
163
- I have opened some enhancement Issues in the GitHub [MarkdownHelper](https://github.com/BurdetteLamar/MarkdownHelper) project:
163
+ I have opened some enhancement Issues in the GitHub [markdown_helper](https://github.com/BurdetteLamar/markdown_helper) project:
164
164
 
165
- * [Pagination](https://github.com/BurdetteLamar/MarkdownHelper/issues/40): series of markdown pages connected by prev/next navigation links.
166
- * [Partial file inclusion](https://github.com/BurdetteLamar/MarkdownHelper/issues/38): including only specified lines from a file (instead of the whole file).
167
- * [Ruby-entity inclusion](https://github.com/BurdetteLamar/MarkdownHelper/issues/39): like file inclusion, but including a Ruby class, module, or method.
168
- * [File TOC](https://github.com/BurdetteLamar/MarkdownHelper/issues/36): table of contents of all headers in a markdown page.
169
- * [Project TOC](https://github.com/BurdetteLamar/MarkdownHelper/issues/37): table of contents of all markdown pages in project.
165
+ * [File TOC](https://github.com/BurdetteLamar/markdown_helper/issues/36): table of contents of all headers in a markdown page.
166
+ * [Project TOC](https://github.com/BurdetteLamar/markdown_helper/issues/37): table of contents of all markdown pages in project.
167
+ * [Partial file inclusion](https://github.com/BurdetteLamar/markdown_helper/issues/38): including only specified lines from a file (instead of the whole file).
168
+ * [Ruby-entity inclusion](https://github.com/BurdetteLamar/markdown_helper/issues/39): like file inclusion, but including a Ruby class, module, or method.
169
+ * [Pagination](https://github.com/BurdetteLamar/markdown_helper/issues/40): series of markdown pages connected by prev/next navigation links.
170
170
 
171
171
  Feel free to comment on any of these, or to add more Issues (enhancement or otherwise).
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.2.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - burdettelamar
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-18 00:00:00.000000000 Z
11
+ date: 2018-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,6 +87,7 @@ files:
87
87
  - LICENSE.txt
88
88
  - README.md
89
89
  - Rakefile
90
+ - _config.yml
90
91
  - bin/console
91
92
  - bin/include
92
93
  - bin/resolve
@@ -96,7 +97,6 @@ files:
96
97
  - images/html.png
97
98
  - images/image.png
98
99
  - images/include.png
99
- - images_resolved.md
100
100
  - lib/markdown_helper.rb
101
101
  - lib/markdown_helper/version.rb
102
102
  - markdown_helper.gemspec
@@ -110,7 +110,7 @@ files:
110
110
  - readme_files/resolve.md
111
111
  - readme_files/resolve_usage.rb
112
112
  - readme_files/verbatim_ruby_template.md
113
- homepage: https://github.com/BurdetteLamar/MarkdownHelper
113
+ homepage: https://github.com/BurdetteLamar/markdown_helper
114
114
  licenses:
115
115
  - MIT
116
116
  metadata: {}
data/images_resolved.md DELETED
@@ -1,96 +0,0 @@
1
- # MarkdownHelper
2
-
3
- [![Gem Version](https://badge.fury.io/rb/markdown_helper.svg)](https://badge.fury.io/rb/markdown_helper)
4
-
5
- ## File Inclusion
6
-
7
- <img src="https://raw.githubusercontent.com/BurdetteLamar/MarkdownHelper/master/images/include.png" alt="include_icon" width="50">
8
-
9
- This markdown helper enables file inclusion in GitHub markdown.
10
-
11
- (Actually, this README file itself is built using file inclusion.)
12
-
13
- Use the markdown helper to merge external files into a markdown (</code>.md</code>) file.
14
-
15
- ### Merged Text Formats
16
-
17
- #### Highlighted Code Block
18
-
19
- @[ruby](include.rb)
20
-
21
- #### Plain Code Block
22
-
23
- @[:code_block](include.rb)
24
-
25
- [Note: In the gem documentation, RubyDoc.info chooses to highlight this code block regardless. Go figure.]
26
-
27
- #### Verbatim
28
-
29
- Verbatim text is included unadorned. Most often, verbatim text is markdown to be rendered as part of the markdown page.
30
-
31
- ### Usage
32
-
33
- #### CLI
34
-
35
- @[:code_block](../bin/usage/include.txt)
36
-
37
- #### API
38
-
39
- @[ruby](include_usage.rb)
40
-
41
- #### Include Pragmas
42
-
43
- Specify each file inclusion via an *include pragma*, which has the form:
44
-
45
- <code>@[</code>*format*<code>]\(</code>*relative_file_path*<code>)</code>
46
-
47
- where:
48
-
49
- * *format* (in square brackets) is one of the following:
50
- * Highlighting mode such as <code>[ruby]</code>, 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).
51
- * <code>[:code_block]</code>, to include a plain code block.
52
- * <code>[:verbatim]</code>, to include text verbatim (to be rendered as markdown).
53
- * *relative_file_path* points to the file to be included.
54
-
55
- ##### Example Include Pragmas
56
-
57
- @[code_block](include.md)
58
-
59
- ## Image Path Resolution
60
-
61
- <img src="https://raw.githubusercontent.com/BurdetteLamar/MarkdownHelper/master/images/image.png" alt="image_icon" width="50">
62
-
63
- This markdown helper enables image path resolution in GitHub markdown.
64
-
65
- (Actually, this README file itself is built using image path resolution.)
66
-
67
- Use the markdown helper to resolve image relative paths in a markdown (</code>.md</code>) file.
68
-
69
- This matters because when markdown becomes part of a Ruby gem, its images will have been relocated in the documentation at RubyDoc.info, breaking the relative paths. The resolved (absolute) urls, however, will still be valid.
70
-
71
- ### Usage
72
-
73
- #### CLI
74
-
75
- @[:code_block](../bin/usage/resolve.txt)
76
-
77
- #### API
78
-
79
- @[ruby](resolve_usage.rb)
80
-
81
- #### Image Pragmas
82
-
83
- Specify each image file via an *image pragma*, which has the form:
84
-
85
- <code>![*alt_text*]\(</code>*relative_file_path* <code>|</code> *attributes*<code>)</code>
86
-
87
- where:
88
-
89
- * *alt_text* is the usual alt text for an HTML image.
90
- * *relative_file_path* points to the file to be included.
91
- * *attributes* are whitespace-separated name-value pairs in the form *name*<code>=</code>*value*. These are passed through to the generated <code>img</code> HTML element.
92
-
93
- ##### Example Image Pragmas
94
-
95
- @[code_block](resolve.md)
96
-