github-to-canvas 0.1.2 → 0.1.3

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
  SHA256:
3
- metadata.gz: f5628681c8cda313989c521770b0b7f2a20e9b7a0aa0f661446d25d1040eca8d
4
- data.tar.gz: da78038dd5492dbb897c9fb6d65e05c76f02e7e57df952630c859d9b446d6c79
3
+ metadata.gz: d3d7cf49277d1fb40bb6a956a16865fded3e5a722b115313ab598c8b0ac16338
4
+ data.tar.gz: '01129c91256e4391343d2dd4bafc0c87acf57d7f8e0a4f3b040289ab045b6dea'
5
5
  SHA512:
6
- metadata.gz: abc12344a24c0c7d67980dc4911462e7c7eb3aba0c31e18b42e5f95fda97fef7b60a994c4ce59fc6da3d6fb7db044fc47ae443979e06455a82906e4ae863f4cd
7
- data.tar.gz: 467e1d799b929fccf52cb155d27411050232c30b704fde8d216516c1bc7891d69c6617252cfdd8782ceb35a10fd05b2d5efdf5dd6754bfb097f22ee740876f36
6
+ metadata.gz: ead1b6073842a1d3c65214ffc3e3cd8bd20048df97a878d8f12dd522655090e02b98f9fb2d45be70a16a044d05aea682bf5c6c71cd31ccd8a6ab9fb215591948
7
+ data.tar.gz: cb340a9d7f4910116ede731ad44cb44a02f90bf77dae5e632669d2b54879af2eab38a8ff1ebf4e1fd639ee1c68ac22fdd5ded4d3ae5f57cd283696b4e32b0834
data/README.md CHANGED
@@ -294,29 +294,45 @@ includes HTML that is not meant to be rendered, the content will be rendered as
294
294
  part of the page's HTML, resulting in unusual display errors in Canvas. Examples of
295
295
  this would be lessons on HTML or JavaScript that include HTML code snippets.
296
296
 
297
- To fix any rendering issues in Canvas, go to the Canvas WYSIWYG editor for the
298
- afflicted lesson. Click the HTML editor option (`</>` button in the lower right) to
299
- switch to HTML.
300
-
301
- Read the GitHub repo as HTML:
302
-
303
- ```sh
304
- github-to-canvas --read-from-github URL
305
- ```
306
-
307
- Copy the output HTML and paste it in to the Canvas editor. This should clear up
308
- some larger page rendering issues, but may not fix all code snippets issues. To
309
- fix these, switch back to the regular Canvas WYSIWYG editor, then open a second
310
- tab to the GitHub repo you're converting from. Copy any HTML code snippets from
311
- GitHub and paste them into the Canvas editor where they should be displayed.
297
+ To prevent HTML from being rendered, include the `--contains-html` option when
298
+ running the GitHub to Canvas gem. This replaces `<` and `>` characters with HTML
299
+ charset values wrapped in `span` elements. This will stop Canvas from rendering
300
+ the HTML.
301
+
302
+ If your markdown contains a mix of HTML that should and should not be rendered,
303
+ you will need to either replace HTML that you want to be rendered with markdown
304
+ syntax equivalents. For example, HTML you want to display as code and an `<img>`
305
+ element you want to render as the image itself, replace the `<img>` tag with
306
+ markdown syntax (`![alt text](url)`).
307
+
308
+ The one exception is the `<iframe>` element. There is no way to easily embed
309
+ videos in GitHub markdown without HTML, so this tag will always be allowed to
310
+ render in Canvas, whether or not you use `--contains-html`.
311
+
312
+ If you have HTML related rendering issues in Canvas that can't be fixed with
313
+ `--contains-html`:
314
+
315
+ - Go to the Canvas WYSIWYG editor for the afflicted lesson.
316
+ - Click the HTML editor option (`</>` button in the lower right) to switch to
317
+ HTML.
318
+ - Read the GitHub repo as HTML:
319
+
320
+ ```sh
321
+ github-to-canvas --read-from-github URL
322
+ ```
323
+
324
+ - Copy the output HTML and paste it in to the Canvas editor. This should clear up
325
+ some larger page rendering issues, but may not fix all code snippets issues.
326
+ - Switch back to the regular Canvas WYSIWYG editor
327
+ - Open a second tab to the GitHub repo you're converting from.
328
+ - Copy any HTML code snippets from GitHub and paste them into the Canvas editor
329
+ where they should be displayed.
312
330
 
313
331
  The Canvas editor will treat the pasted HTML content as code and will
314
332
  automatically replace some characters, escaping the code from the
315
333
  normal rendering process.
316
334
 
317
- Note that realigning after fixing this content with the gem will break the
318
- rendering for these lessons again. A fix is planned for this issue, but has not
319
- been implemented.
335
+ Note that realigning after fixing this content may overwrite fixes.
320
336
 
321
337
  ### Multi-Line Code Snippets Render as a Single Line
322
338
 
@@ -77,7 +77,6 @@ OptionParser.new do |opts|
77
77
  opts.on("-tTYPE", "--type TYPE",
78
78
  "Sets the type Canvas lesson to be created (page or assignment). If no type, type decided based on repository structure") do |type|
79
79
  # byebug
80
- puts type.downcase
81
80
  options[:type] = type.downcase
82
81
  abort if type == 'quiz' || type == 'discussion'
83
82
  # if type == 'page' || type == 'assignment' || type == 'discussion' || type == 'quiz' || type == 'Page' || type == 'Assignment' || type == 'Discussion' || type == 'Quiz'
@@ -107,6 +106,10 @@ OptionParser.new do |opts|
107
106
  "Adds additional Flatiron School HTML after markdown conversion") do |f|
108
107
  options[:fis] = true
109
108
  end
109
+ opts.on("--aaq",
110
+ "Adds AAQ flag to HTML header appended with --fis-links") do |aaq|
111
+ options[:aaq] = aaq
112
+ end
110
113
  opts.on("--forkable",
111
114
  "Used with --fis-links, adds fork button to HTML header injected into Canvas lesson") do |remote|
112
115
  options[:forkable] = true
@@ -175,6 +178,10 @@ OptionParser.new do |opts|
175
178
  "Iterates over provided course YAML file and clones repos locally") do |file|
176
179
  options[:clone_from_yaml] = file
177
180
  end
181
+ opts.on("--contains-html",
182
+ "Escapes all HTML included in source markdown by replacing '<' and '>' with HTML charset values") do |html|
183
+ options[:contains_html] = html
184
+ end
178
185
 
179
186
  end.parse!
180
187
 
@@ -184,12 +191,19 @@ if options[:version]
184
191
  end
185
192
 
186
193
  if options[:read_from_canvas]
187
- GithubToCanvas.new(mode: 'canvas_read', filepath: options[:read_from_canvas])
194
+ GithubToCanvas.new(mode: 'canvas_read',
195
+ filepath: options[:read_from_canvas])
188
196
  abort
189
197
  end
190
198
 
191
199
  if options[:read_from_github]
192
- GithubToCanvas.new(mode: 'github_read', filepath: options[:read_from_github])
200
+ GithubToCanvas.new(mode: 'github_read',
201
+ filepath: options[:read_from_github],
202
+ remove_header_and_footer: !!options[:remove_header_and_footer],
203
+ forkable: !!options[:forkable],
204
+ fis_links: !!options[:fis],
205
+ aaq: !!options[:aaq],
206
+ contains_html: options[:contains_html])
193
207
  abort
194
208
  end
195
209
 
@@ -199,9 +213,12 @@ if options[:create_from_github]
199
213
  filepath: options[:create_from_github],
200
214
  course_id: options[:course_id],
201
215
  type: options[:type],
216
+ name: options[:name],
202
217
  remove_header_and_footer: !!options[:remove_header_and_footer],
203
218
  forkable: !!options[:forkable],
204
- fis_links: !!options[:fis])
219
+ fis_links: !!options[:fis],
220
+ aaq: !!options[:aaq],
221
+ contains_html: options[:contains_html])
205
222
  else
206
223
  puts 'Canvas course ID and lesson type required. Example: github-to-canvas --create-from-github URL --course ID --type TYPE'
207
224
  end
@@ -218,7 +235,9 @@ if options[:align_from_github]
218
235
  name: options[:name],
219
236
  remove_header_and_footer: !!options[:remove_header_and_footer],
220
237
  forkable: !!options[:forkable],
221
- fis_links: !!options[:fis])
238
+ fis_links: !!options[:fis],
239
+ aaq: !!options[:aaq],
240
+ contains_html: options[:contains_html])
222
241
  else
223
242
  puts 'Canvas course ID, lesson ID, and type required. Example: github-to-canvas --create-from-github URL --course COURSE_ID --id LESSON_ID --type TYPE'
224
243
  end
@@ -245,6 +264,7 @@ if options[:build_course]
245
264
  file_to_convert: options[:build_course],
246
265
  fis_links: !!options[:fis],
247
266
  remove_header_and_footer: !!options[:remove_header_and_footer],
267
+ aaq: !!options[:aaq],
248
268
  forkable: !!options[:forkable])
249
269
  abort
250
270
  end
@@ -256,7 +276,9 @@ if options[:add_to_course]
256
276
  file_to_convert: options[:add_to_course],
257
277
  fis_links: !!options[:fis],
258
278
  remove_header_and_footer: !!options[:remove_header_and_footer],
259
- forkable: !!options[:forkable])
279
+ forkable: !!options[:forkable],
280
+ aaq: !!options[:aaq],
281
+ contains_html: options[:contains_html])
260
282
  else
261
283
  puts '--course required'
262
284
  end
@@ -268,7 +290,9 @@ if options[:update_course_lessons]
268
290
  file_to_convert: options[:update_course_lessons],
269
291
  fis_links: !!options[:fis],
270
292
  remove_header_and_footer: !!options[:remove_header_and_footer],
271
- forkable: !!options[:forkable])
293
+ forkable: !!options[:forkable],
294
+ aaq: !!options[:aaq],
295
+ contains_html: options[:contains_html])
272
296
  abort
273
297
  end
274
298
 
@@ -330,7 +354,9 @@ if options[:create_lesson]
330
354
  fis_links: !!options[:fis],
331
355
  remove_header_and_footer: !!options[:remove_header_and_footer],
332
356
  only_update_content: !!options[:only_content],
333
- forkable: !!options[:forkable])
357
+ forkable: !!options[:forkable],
358
+ aaq: !!options[:aaq],
359
+ contains_html: options[:contains_html])
334
360
  end
335
361
 
336
362
  if options[:align]
@@ -346,5 +372,7 @@ if options[:align]
346
372
  fis_links: !!options[:fis],
347
373
  remove_header_and_footer: !!options[:remove_header_and_footer],
348
374
  only_update_content: !!options[:only_content],
349
- forkable: !!options[:forkable])
375
+ forkable: !!options[:forkable],
376
+ aaq: !!options[:aaq],
377
+ contains_html: options[:contains_html])
350
378
  end
@@ -27,8 +27,8 @@ class GithubToCanvas
27
27
  when 'canvas_read'
28
28
  puts CanvasInterface.read_lesson(options[:filepath])
29
29
  when 'github_read'
30
- markdown = GithubInterface.read_remote(options[:filepath])
31
- puts RepositoryConverter.convert_to_html(markdown)
30
+ html = RepositoryConverter.remote_file_conversion(options)
31
+ puts RepositoryConverter.adjust_converted_html(options, html)
32
32
  when 'create' # used with a local repo
33
33
  html = RepositoryConverter.local_file_conversion(options)
34
34
  name = RepositoryInterface.get_name(options[:filepath], html)
@@ -38,13 +38,13 @@ class GithubToCanvas
38
38
  puts "Canvas lesson created. Lesson available at #{response['html_url']}"
39
39
  when 'align' # used with a local repo
40
40
  html = RepositoryConverter.local_file_conversion(options)
41
- name = RepositoryInterface.get_name(options[:filepath], html)
41
+ name = options[:name] ? options[:name] : RepositoryInterface.get_name(options[:filepath], html)
42
42
  html = RepositoryConverter.adjust_converted_html(options, html)
43
43
  CanvasInterface.update_all_related_lessons(options, name, html)
44
44
 
45
45
  when 'github_create'
46
46
  html = RepositoryConverter.remote_file_conversion(options)
47
- name = RepositoryInterface.get_name(options[:filepath], html)
47
+ name = options[:name] ? options[:name] : RepositoryInterface.get_name(options[:filepath], html)
48
48
  html = RepositoryConverter.adjust_converted_html(options, html)
49
49
 
50
50
  response = CanvasInterface.create_lesson(options, name, html)
@@ -47,10 +47,6 @@ class CanvasInterface
47
47
  JSON.parse(response.body)
48
48
  end
49
49
 
50
- def self.create_quiz(options, quiz_data)
51
-
52
- end
53
-
54
50
  def self.add_to_module(course_id, module_info, lesson_info)
55
51
  # POST /api/v1/courses/:course_id/modules/:module_id/items
56
52
  url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/modules/#{module_info["id"]}/items"
@@ -76,15 +72,12 @@ class CanvasInterface
76
72
  }
77
73
  end
78
74
  begin
79
- byebug
80
75
  response = RestClient.post(url, payload, self.headers)
81
76
  rescue
82
77
  puts "Something went wrong while adding lesson #{lesson_info["id"]} to module #{module_info["id"]} in course #{course_id}" if lesson_info["type"] == "Assignment"
83
78
  puts "Something went wrong while adding lesson #{lesson_info["page_url"]} to module #{module_info["id"]} in course #{course_id}" if lesson_info["type"] == "Page"
84
79
  abort
85
80
  end
86
-
87
-
88
81
  response
89
82
 
90
83
  end
@@ -17,7 +17,7 @@ class RepositoryConverter
17
17
  GithubInterface.get_updated_repo(options[:filepath], options[:branch])
18
18
  markdown = RepositoryInterface.read_local_file(options[:filepath], options[:file_to_convert])
19
19
  raw_remote_url = self.set_raw_image_remote_url(options[:filepath])
20
-
20
+ markdown = self.escape_existing_html(markdown) if options[:contains_html]
21
21
  markdown = self.fix_local_images(options, markdown, raw_remote_url)
22
22
  html = self.convert_to_html(markdown)
23
23
  # self.fix_local_html_links(options, html, options[:filepath])
@@ -26,6 +26,7 @@ class RepositoryConverter
26
26
  def self.remote_file_conversion(options)
27
27
  markdown = GithubInterface.read_remote(options[:filepath])
28
28
  raw_remote_url = self.set_raw_image_remote_url(options[:filepath])
29
+ markdown = self.escape_existing_html(markdown) if options[:contains_html]
29
30
  markdown = self.fix_local_images(options, markdown, raw_remote_url)
30
31
  html = self.convert_to_html(markdown)
31
32
  # self.fix_local_html_links(options, html, options[:filepath])
@@ -46,9 +47,24 @@ class RepositoryConverter
46
47
  if options[:fis_links]
47
48
  html = self.add_fis_links(options, html)
48
49
  end
50
+
51
+ html = self.fix_escaped_inline_html_code(html)
52
+
49
53
  html
50
54
  end
51
55
 
56
+ def self.fix_escaped_inline_html_code(html)
57
+ html = html.gsub("<code>&amp;lt;", "<code>&lt;")
58
+ html = html.gsub("&amp;gt;</code>", "&gt;</code>")
59
+ end
60
+
61
+
62
+ def self.escape_existing_html(markdown)
63
+ markdown = markdown.gsub(/<\/(?!iframe)/, "&lt;/")
64
+ markdown = markdown.gsub(/<(?!iframe)/, "&lt;")
65
+ markdown = markdown.gsub(/(?<!iframe)>/, "&gt;")
66
+ end
67
+
52
68
  def self.remove_header_and_footer(html)
53
69
  new_html = self.remove_html_header(html)
54
70
  new_html = self.remove_footer(new_html)
@@ -56,7 +72,7 @@ class RepositoryConverter
56
72
  end
57
73
 
58
74
  def self.remove_header(readme)
59
- readme.gsub!(/^# .+?\n\n/,"")
75
+ readme = readme.gsub(/^# .+?\n\n/,"")
60
76
  readme.gsub(/^# .+?\n/,"")
61
77
  end
62
78
 
@@ -163,7 +179,7 @@ class RepositoryConverter
163
179
  repo_info = self.get_repo_info(options[:filepath])
164
180
  html = html.sub(/<div id="git-data-element.*<header class="fis-header.*<\/header>/,'') # remove existing fis header
165
181
  header = self.create_github_link_header(repo_info[:repo_path], options[:forkable])
166
- data_element = self.create_data_element(repo_info[:repo_org], repo_info[:repo_name])
182
+ data_element = self.create_data_element(repo_info[:repo_org], repo_info[:repo_name], options[:aaq])
167
183
  data_element + header + html
168
184
  end
169
185
 
@@ -183,8 +199,12 @@ class RepositoryConverter
183
199
  end
184
200
  end
185
201
 
186
- def self.create_data_element(repo_org, repo_name)
187
- "<div id='git-data-element' data-org='#{repo_org}' data-repo='#{repo_name}'></div>"
202
+ def self.create_data_element(repo_org, repo_name, aaq)
203
+ if (aaq)
204
+ "<div id='git-data-element' data-aaq='enabled' data-org='#{repo_org}' data-repo='#{repo_name}'></div>"
205
+ else
206
+ "<div id='git-data-element' data-org='#{repo_org}' data-repo='#{repo_name}'></div>"
207
+ end
188
208
  end
189
209
 
190
210
 
@@ -1,3 +1,3 @@
1
1
  class GithubToCanvas
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github-to-canvas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxwellbenton