github-to-canvas 0.1.13 → 0.1.17

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: e00c11cef1a74df9d857668f55757142f23769398db63415aba5f0fb13dba005
4
- data.tar.gz: 3d9393d1d5051a944dc9df64009ab92028fab0239eb7bcae90f99ed1ad01b14b
3
+ metadata.gz: 59e47d1d256dca36a7312ef82f6953c5c50df08286a481928233fcdd4dbe0aad
4
+ data.tar.gz: 4d705224c21ac7c70e6c7543a3484baffed2f64c5069c50c070b991079d8011b
5
5
  SHA512:
6
- metadata.gz: fd74299fd8e4cc882a3bddb8e670fb09aea8641a0b79e97f1f0da4db50e514921eaca22bd49a16531da7b45d04fb41fd94de383f016c62b77853ec754ecada4f
7
- data.tar.gz: fe082b1a81263e4984757d26bbcbede2c97498011b1b1c3ad1a2b9dd65dedcb2758f205bb2e897501e5a0176f0299768e362d699542205b1dd295c34bcba19c6
6
+ metadata.gz: 03f61185beb39e4fc34421ad7c5a90dc18e7897154fdcfe5da7d7501ae16b13974045e5c4071182f1a02c72b839cfb5688df0a73f0a2f0127ec919f1ef1493b7
7
+ data.tar.gz: 2ad4a5f5d700f377e69ce81c5c26463007faf415ca31aef149b2520e4b843c730e68c052d1467bacedc51a6f9511d94f1a89cd00a94db86081d5f65d803ad967
data/Gemfile CHANGED
@@ -4,8 +4,5 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  ruby "2.6.1"
6
6
 
7
- gem 'require_all'
8
- gem 'json'
9
- gem 'redcarpet'
10
- gem 'rest-client'
11
- # Specify your gem's dependencies in github-to-canvas.gemspec
7
+ # Specify your gem's dependencies in github-to-canvas.gemspec
8
+ gemspec
data/README.md CHANGED
@@ -25,18 +25,18 @@ also required for some features.
25
25
  In order to access the Canvas API, you must first generate an API key. Go to
26
26
  your Canvas Account Settings and under **Approved Integrations**, create a
27
27
  **New Access Token**. You will need to store this API key as an `ENV` variable
28
- called `CANVAS_API_KEY`.
28
+ called `CANVAS_API_KEY`.
29
29
 
30
30
  If you are using Zsh, the following command will add your new key to the top of `~/.zshrc`:
31
31
 
32
32
  ```sh
33
- echo "$(export 'CANVAS_API_KEY=your-new-API-key-here' | cat - ~/.zshrc)" > ~/.zshrc
33
+ echo "$(export 'CANVAS_API_KEY=<your-new-API-key-here>' | cat - ~/.zshrc)" > ~/.zshrc
34
34
  ```
35
35
 
36
36
  If you are using Bash, use this command instead:
37
37
 
38
38
  ```sh
39
- echo "$(export 'CANVAS_API_KEY=your-new-API-key-here' | cat - ~/.bash_profile)" > ~/.bash_profile
39
+ echo "$(export 'CANVAS_API_KEY=<your-new-API-key-here>' | cat - ~/.bash_profile)" > ~/.bash_profile
40
40
  ```
41
41
 
42
42
  > If you aren't sure which you use, run `echo $SHELL`
@@ -74,6 +74,7 @@ The GitHub to Canvas gem can be used for the following:
74
74
  - [Map GitHub Repositories to a Canvas Course YAML file](#map)
75
75
  - [Create New Canvas Course from a YAML file](#buildcourse)
76
76
  - [Update Lessons in an Existing Course from a YAML file](#updatecourse)
77
+ - [Syntax Highlighting](#syntaxhighlighting)
77
78
 
78
79
  ### Creating and Updating Canvas Lessons
79
80
 
@@ -123,7 +124,7 @@ To read the contents of a remote repo:
123
124
  github-to-canvas --read-from-github <URL>
124
125
  ```
125
126
 
126
- This will produce an HTML conversion of the repository's markdwon. This HTML can
127
+ This will produce an HTML conversion of the repository's markdown. This HTML can
127
128
  be directly pasted into Canvas' HTML editor if a manual process is needed.
128
129
 
129
130
  #### Update a Canvas Lesson from a Local Repository <a name="update"></a>
@@ -191,30 +192,30 @@ The output will look similar to this:
191
192
  :name: The Course's Title
192
193
  :id: 111
193
194
  :modules:
194
- - :id: 2020
195
- :name: First Module's Name
196
- :lessons:
197
- - id: slugified-page-name
198
- title: This is the Title Of The First Lesson, a Page
199
- indent: 0
200
- type: Page
201
- html_url: https://learning.flatironschool.com/courses/111/modules/items/27001
202
- page_url: slugified-page-name
203
- url: https://learning.flatironschool.com/api/v1/courses/111/pages/slugified-page-name
204
- published: false
205
- repository: ''
206
- - id: 333
207
- title: This is the Title Of The Second Lesson, an Assignment
208
- indent: 1
209
- type: Assignment
210
- html_url: https://learning.flatironschool.com/courses/111/modules/items/27002
211
- page_url: ''
212
- url: https://learning.flatironschool.com/api/v1/courses/111/assignments/333
213
- published: false
214
- repository: ''
215
- - :id: 2021
216
- :name: Second Module's Name
217
- :lessons:
195
+ - :id: 2020
196
+ :name: First Module's Name
197
+ :lessons:
198
+ - id: slugified-page-name
199
+ title: This is the Title Of The First Lesson, a Page
200
+ indent: 0
201
+ type: Page
202
+ html_url: https://learning.flatironschool.com/courses/111/modules/items/27001
203
+ page_url: slugified-page-name
204
+ url: https://learning.flatironschool.com/api/v1/courses/111/pages/slugified-page-name
205
+ published: false
206
+ repository: ""
207
+ - id: 333
208
+ title: This is the Title Of The Second Lesson, an Assignment
209
+ indent: 1
210
+ type: Assignment
211
+ html_url: https://learning.flatironschool.com/courses/111/modules/items/27002
212
+ page_url: ""
213
+ url: https://learning.flatironschool.com/api/v1/courses/111/assignments/333
214
+ published: false
215
+ repository: ""
216
+ - :id: 2021
217
+ :name: Second Module's Name
218
+ :lessons:
218
219
  ```
219
220
 
220
221
  The output YAML will not include associated GitHub repository information.
@@ -246,7 +247,27 @@ To create a Canvas course with this gem, you will need a correctly structured
246
247
  YAML file with the course info, modules, lessons and associated lesson
247
248
  repositories. In addition, all lessons must have a type (`Page` or
248
249
  `Assignment`), a repository, and a title. Other lesson options are currently
249
- ignored.
250
+ ignored.
251
+
252
+ Here's an example of what the YAML file should look like. Note that for Pages
253
+ the id needs to be present and match the title, based on how Canvas creates
254
+ URL slugs for pages.
255
+
256
+ ```yaml
257
+ ---
258
+ :name: Test Building Course
259
+ :course_code: TEST-GEM-COURSE
260
+ :modules:
261
+ - :name: Module 1
262
+ :lessons:
263
+ - title: Lesson 1
264
+ type: Assignment
265
+ repository: https://github.com/learn-co-curriculum/react-hooks-component-props-mini-project
266
+ - id: lesson-2
267
+ title: Lesson 2
268
+ type: Page
269
+ repository: https://github.com/learn-co-curriculum/phase-0-pac-1-js-variables
270
+ ```
250
271
 
251
272
  With the necessary data configured, use the `--build-course` option and pass in
252
273
  the course's YAML file:
@@ -262,7 +283,7 @@ This command will cause the following to happen:
262
283
  - Create the first lesson using the repository, title and type, as well as additional command options
263
284
  - Add the newly created lesson to the current module
264
285
  - Create the second lesson and add it to the module...
265
- - Repeate process until all modules and lessons are created
286
+ - Repeat process until all modules and lessons are created
266
287
 
267
288
  #### Update Lessons in an Existing Course from a YAML file <a name="updatecourse"></a>
268
289
 
@@ -285,6 +306,23 @@ github-to-canvas --update-course YAML_FILE -lr --forkable
285
306
  The gem will iterate over the data and update every lesson according to the
286
307
  associated repository.
287
308
 
309
+ ## Syntax Highlighting <a name="syntaxhighlighting"></a>
310
+
311
+ This gem uses the [Rouge](https://github.com/rouge-ruby/rouge) Ruby gem to add
312
+ syntax highlighting to
313
+ [fenced code blocks](https://www.markdownguide.org/extended-syntax/#syntax-highlighting).
314
+ Rouge tokenizes the fenced code blocks and generates HTML elements with CSS
315
+ classes to style code blocks. The classes generated by Rouge are intended to
316
+ work with [Pygments](https://pygments.org/).
317
+
318
+ You can download and customize CSS themes for the classes generated by Rouge at this site:
319
+
320
+ - [http://jwarby.github.io/jekyll-pygments-themes/languages/javascript.html](http://jwarby.github.io/jekyll-pygments-themes/languages/javascript.html)
321
+
322
+ After selecting your preferred CSS, you will need to
323
+ [update your Canvas theme](https://community.canvaslms.com/t5/Admin-Guide/How-do-I-upload-custom-JavaScript-and-CSS-files-to-an-account/ta-p/253)
324
+ so the CSS can run on each page.
325
+
288
326
  ## Known Issues
289
327
 
290
328
  ### HTML Code Snippets Do Not Render
@@ -294,58 +332,35 @@ includes HTML that is not meant to be rendered, the content will be rendered as
294
332
  part of the page's HTML, resulting in unusual display errors in Canvas. Examples of
295
333
  this would be lessons on HTML or JavaScript that include HTML code snippets.
296
334
 
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`:
335
+ To fix any rendering issues in Canvas, go to the Canvas WYSIWYG editor for the
336
+ afflicted lesson. Click the HTML editor option (`</>` button in the lower right) to
337
+ switch to HTML.
314
338
 
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:
339
+ Read the GitHub repo as HTML:
319
340
 
320
- ```sh
321
- github-to-canvas --read-from-github URL
322
- ```
341
+ ```sh
342
+ github-to-canvas --read-from-github URL
343
+ ```
323
344
 
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.
345
+ Copy the output HTML and paste it into the Canvas editor (if your lesson has a
346
+ `<header>` with github links, leave this in). This should clear up some larger
347
+ page rendering issues, but may not fix all code snippets issues. To fix these,
348
+ switch back to the regular Canvas WYSIWYG editor, then open a second tab to the
349
+ GitHub repo you're converting from. Copy any HTML code snippets from GitHub and
350
+ paste them into the Canvas editor where they should be displayed.
330
351
 
331
352
  The Canvas editor will treat the pasted HTML content as code and will
332
353
  automatically replace some characters, escaping the code from the
333
354
  normal rendering process.
334
355
 
335
- Note that realigning after fixing this content may overwrite fixes.
336
-
337
- ### Multi-Line Code Snippets Render as a Single Line
338
-
339
- The Github to Canvas gem uses an existing gem, Redcarpet, to handle the Markdown to HTML
340
- conversion. This gem does not currently support multi-line codeblocks. This
341
- functionality has been added in the Github to Canvas gem through monkeypatching.
342
- This error should be resolved, but if you encounter code snippet rendering
343
- issues, please open a new issue with a markdown example to replicate the error.
356
+ Note that realigning after fixing this content with the gem will break the
357
+ rendering for these lessons again. A fix is planned for this issue, but has not
358
+ been implemented.
344
359
 
345
360
  ### Markdown Formatting Issues Cause Errors in Canvas
346
361
 
347
362
  An empty line should separate individual markdown headers, paragraphs and code snippets
348
- in the markdown. Without these empty lines, the contents will be interpretted as one
363
+ in the markdown. Without these empty lines, the contents will be interpreted as one
349
364
  continuous paragraph and ignore formatting.
350
365
 
351
366
  ### New Repos That Use a `main` Branch
@@ -419,7 +434,7 @@ Run `github-to-canvas --help` for additional options not listed in this Readme.
419
434
 
420
435
  ## Examples of Valid Images This Gem Can Convert
421
436
 
422
- This gem can convert both standard inline markdown and HTML images.
437
+ This gem can convert both standard inline markdown and HTML images.
423
438
 
424
439
  Inline Markdown:
425
440
 
@@ -431,5 +446,5 @@ HTML:
431
446
  <img src="https://curriculum-content.s3.amazonaws.com/fewpjs/fewpjs-fetch-lab/Image_25_AsynchronousJavaScript.png" width="500">
432
447
  </p>
433
448
 
434
- [Canvas LMS API]: https://canvas.instructure.com/doc/api/index.html
435
- [Flatiron School]: https://flatironschool.com/
449
+ [canvas lms api]: https://canvas.instructure.com/doc/api/index.html
450
+ [flatiron school]: https://flatironschool.com/
data/bin/github-to-canvas CHANGED
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../lib'))
4
+ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
3
5
 
4
6
  require 'optparse'
5
- require 'github-to-canvas'
7
+ require_relative '../lib/github-to-canvas'
6
8
 
7
9
  options = {}
8
10
  OptionParser.new do |opts|
@@ -191,8 +193,8 @@ OptionParser.new do |opts|
191
193
  options[:clone_from_yaml] = file
192
194
  end
193
195
  opts.on("--contains-html",
194
- "Escapes all HTML included in source markdown by replacing '<' and '>' with HTML charset values") do |html|
195
- options[:contains_html] = html
196
+ "DEPRECATED: HTML in code blocks handled by Rouge gem.") do |html|
197
+ puts "--contains-html flag is DEPRECATED: HTML in code blocks handled by Rouge gem."
196
198
  end
197
199
  opts.on("--canvas-to-canvas COURSE",
198
200
  "Copies an existing Canvas lesson into another Canvas lesson") do |canvas_to_canvas|
@@ -238,8 +240,7 @@ if options[:read_from_github]
238
240
  forkable: !!options[:forkable],
239
241
  fis_links: !!options[:fis],
240
242
  aaq: !!options[:aaq],
241
- prework: !!options[:prework],
242
- contains_html: options[:contains_html])
243
+ prework: !!options[:prework])
243
244
  abort
244
245
  end
245
246
 
@@ -254,8 +255,7 @@ if options[:create_from_github]
254
255
  forkable: !!options[:forkable],
255
256
  fis_links: !!options[:fis],
256
257
  aaq: !!options[:aaq],
257
- prework: !!options[:prework],
258
- contains_html: options[:contains_html])
258
+ prework: !!options[:prework])
259
259
  else
260
260
  puts 'Canvas course ID and lesson type required. Example: github-to-canvas --create-from-github URL --course ID --type TYPE'
261
261
  end
@@ -274,8 +274,7 @@ if options[:align_from_github]
274
274
  forkable: !!options[:forkable],
275
275
  fis_links: !!options[:fis],
276
276
  aaq: !!options[:aaq],
277
- prework: !!options[:prework],
278
- contains_html: options[:contains_html])
277
+ prework: !!options[:prework])
279
278
  else
280
279
  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'
281
280
  end
@@ -309,7 +308,6 @@ if options[:csv_build]
309
308
  aaq: !!options[:aaq],
310
309
  forkable: !!options[:forkable],
311
310
  branch: options[:branch],
312
- contains_html: options[:contains_html],
313
311
  git_links: !!options[:git_links])
314
312
  abort
315
313
  end
@@ -323,7 +321,6 @@ if options[:csv_align]
323
321
  aaq: !!options[:aaq],
324
322
  forkable: !!options[:forkable],
325
323
  branch: options[:branch],
326
- contains_html: options[:contains_html],
327
324
  git_links: !!options[:git_links])
328
325
  abort
329
326
  end
@@ -336,7 +333,6 @@ if options[:build_course]
336
333
  aaq: !!options[:aaq],
337
334
  prework: !!options[:prework],
338
335
  forkable: !!options[:forkable],
339
- contains_html: options[:contains_html],
340
336
  git_links: !!options[:git_links])
341
337
  abort
342
338
  end
@@ -351,7 +347,6 @@ if options[:add_to_course]
351
347
  forkable: !!options[:forkable],
352
348
  aaq: !!options[:aaq],
353
349
  prework: !!options[:prework],
354
- contains_html: options[:contains_html],
355
350
  git_links: !!options[:git_links])
356
351
  else
357
352
  puts '--course required'
@@ -367,7 +362,6 @@ if options[:update_course_lessons]
367
362
  forkable: !!options[:forkable],
368
363
  aaq: !!options[:aaq],
369
364
  prework: !!options[:prework],
370
- contains_html: options[:contains_html],
371
365
  git_links: !!options[:git_links])
372
366
  abort
373
367
  end
@@ -433,8 +427,7 @@ if options[:create_lesson]
433
427
  only_update_content: !!options[:only_content],
434
428
  forkable: !!options[:forkable],
435
429
  aaq: !!options[:aaq],
436
- prework: !!options[:prework],
437
- contains_html: options[:contains_html])
430
+ prework: !!options[:prework])
438
431
  end
439
432
 
440
433
  if options[:align]
@@ -453,6 +446,5 @@ if options[:align]
453
446
  only_update_content: !!options[:only_content],
454
447
  forkable: !!options[:forkable],
455
448
  aaq: !!options[:aaq],
456
- prework: !!options[:prework],
457
- contains_html: options[:contains_html])
449
+ prework: !!options[:prework])
458
450
  end
@@ -23,7 +23,7 @@ class GithubToCanvas
23
23
  when 'map'
24
24
  CanvasInterface.map_course_info(options)
25
25
  when 'csv'
26
- CanvasInterface.csv(options[:file_to_convert])
26
+ CanvasInterface.csv(options[:file_to_convert]) # not working properly
27
27
  when 'canvas_read'
28
28
  puts CanvasInterface.read_lesson(options[:filepath])
29
29
  when 'canvas_copy'
@@ -201,9 +201,6 @@ class GithubToCanvas
201
201
  options[:name] = lesson[1]
202
202
  options[:type] = lesson[3]
203
203
  options[:branch] = "master" if !options[:branch]
204
- if !options[:contains_html]
205
- options[:contains_html] = (lesson[4] == "yes" || lesson[4] == "Yes") ? true : false
206
- end
207
204
 
208
205
 
209
206
  html = RepositoryConverter.remote_file_conversion(options)
@@ -243,9 +240,6 @@ class GithubToCanvas
243
240
  options[:id] = lesson[5]
244
241
  options[:course_id] = lesson[6]
245
242
  options[:branch] = "master" if !options[:branch]
246
- if !options[:contains_html]
247
- options[:contains_html] = (lesson[4] == "yes" || lesson[4] == "Yes") ? true : false
248
- end
249
243
 
250
244
 
251
245
  html = RepositoryConverter.remote_file_conversion(options)
@@ -1,7 +1,6 @@
1
1
  require 'json'
2
2
  require 'rest-client'
3
3
  require 'yaml'
4
- # require 'byebug'
5
4
  class CanvasInterface
6
5
 
7
6
  def self.create_course(course_info)
@@ -98,9 +97,6 @@ class CanvasInterface
98
97
  lesson_info = lesson_info[0] if lesson_info.kind_of?(Array)
99
98
  url = url.sub(/[^\/]+$/, lesson_info["page_id"].to_s)
100
99
  end
101
- puts url
102
- puts payload
103
- puts headers
104
100
  response = RestClient.put(url, payload, headers)
105
101
  rescue Exception => e
106
102
  puts "Something went wrong while pushing lesson #{options[:id]} to course #{options[:course_id]}"
@@ -221,12 +217,9 @@ class CanvasInterface
221
217
  response = RestClient.get(url, self.headers)
222
218
  lessons = JSON.parse(response.body)
223
219
  lessons = lessons.map do |lesson|
224
- if lesson["type"] == "ExternalUrl"
225
- next
226
- end
227
220
  lesson = lesson.slice("id","title","name","indent","type","html_url","page_url","url","completion_requirement", "published")
228
221
  lesson["repository"] = ""
229
- lesson['id'] = lesson['url'].gsub(/^(.*[\\\/])/,'')
222
+ lesson['id'] = lesson['url']&.gsub(/^(.*[\\\/])/,'')
230
223
  lesson
231
224
  end
232
225
  if ([200, 201].include? response.code) && (!lessons.empty?)
@@ -251,6 +244,7 @@ class CanvasInterface
251
244
  course_info = YAML.load(File.read("#{Dir.pwd}/#{options[:file_to_convert]}"))
252
245
  course_info[:modules] = course_info[:modules].map do |mod|
253
246
  mod[:lessons] = mod[:lessons].map do |lesson|
247
+ next lesson unless lesson.key?("url")
254
248
 
255
249
  url = lesson["url"]
256
250
  response = RestClient.get(url, headers={
@@ -1,15 +1,9 @@
1
1
  require 'redcarpet'
2
- # require 'byebug'
3
- class CustomRender < Redcarpet::Render::HTML
4
- def block_code(code, lang)
5
- "<pre>" \
6
- "<code>#{multi_line(code)}</code>" \
7
- "</pre>"
8
- end
2
+ require 'rouge'
3
+ require 'rouge/plugins/redcarpet'
9
4
 
10
- def multi_line(code)
11
- code.gsub(/\n(?=[^.])/, "<br />")
12
- end
5
+ class CustomRender < Redcarpet::Render::HTML
6
+ include Rouge::Plugins::Redcarpet
13
7
  end
14
8
 
15
9
  class RepositoryConverter
@@ -17,7 +11,6 @@ class RepositoryConverter
17
11
  # GithubInterface.get_updated_repo(options[:filepath], options[:branch])
18
12
  markdown = RepositoryInterface.read_local_file(options[:filepath], options[:file_to_convert])
19
13
  raw_remote_url = self.set_raw_image_remote_url(options[:filepath])
20
- markdown = self.escape_existing_html(markdown) if options[:contains_html]
21
14
  markdown = self.fix_local_images(options, markdown, raw_remote_url)
22
15
  html = self.convert_to_html(markdown)
23
16
  # self.fix_local_html_links(options, html, options[:filepath])
@@ -26,14 +19,6 @@ class RepositoryConverter
26
19
  def self.remote_file_conversion(options)
27
20
  markdown = GithubInterface.read_remote(options[:filepath])
28
21
  raw_remote_url = self.set_raw_image_remote_url(options[:filepath])
29
- if options[:contains_html]
30
- begin
31
- markdown = self.escape_existing_html(markdown)
32
- rescue
33
- puts "Error reading remote markdown"
34
- abort
35
- end
36
- end
37
22
  if (!options[:branch])
38
23
  options[:branch] = 'master'
39
24
  end
@@ -43,15 +28,19 @@ class RepositoryConverter
43
28
  end
44
29
 
45
30
  def self.convert_to_html(markdown)
46
- renderer = CustomRender.new(escape_html: true, prettify: true, hard_wrap: true)
47
- redcarpet = Redcarpet::Markdown.new(CustomRender, options={tables: true, autolink: true, fenced_code_blocks: true, disable_indented_code_blocks: true})
31
+ options = {
32
+ tables: true,
33
+ autolink: true,
34
+ fenced_code_blocks: true,
35
+ no_intra_emphasis: true
36
+ }
37
+ redcarpet = Redcarpet::Markdown.new(CustomRender, options)
48
38
  html = redcarpet.render(markdown)
49
39
  puts "Markdown converted to HTML"
50
- self.remove_line_breaks(html)
40
+ html
51
41
  end
52
42
 
53
43
  def self.adjust_converted_html(options, html)
54
-
55
44
  if options[:remove_header_and_footer]
56
45
  html = self.remove_header_and_footer(html)
57
46
  end
@@ -60,58 +49,12 @@ class RepositoryConverter
60
49
  html = self.add_fis_links(options, html)
61
50
  end
62
51
 
63
- if options[:contains_html]
64
- html = self.fix_escaped_inline_html_code(html)
65
- end
66
-
67
- html
68
- end
69
-
70
- def self.fix_escaped_inline_html_code(html)
71
-
72
- # stops HTML/JSX code blocks from rendering as HTML in Canvas
73
- # html = html.gsub("&amp;gt;</code>", "&gt;</code>")
74
- # html = html.gsub("&amp;gt;</code>", "&gt;</code>")
75
-
76
- # fixes < and > code snippets
77
-
78
- # html = html.gsub(/<pre><code>(.*?)<\/code><\/pre>/) { |string|
79
- # byebug
80
- # }
81
- # html = html.gsub("&amp;gt;", "&gt;")
82
-
83
- # # fixes blockquotes
84
- # html = html.gsub(/\n<p>&gt\;(.*)\n&gt\;/) { |bq|
85
- # bq.delete_prefix!("\n<p>&gt;")
86
- # "\n<blockquote>" + bq
87
- # }
88
- # html = html.gsub(/\n&gt\;(.*)\n&gt\;/) { |bq|
89
- # bq.delete_prefix!("\n&gt;")
90
- # " " + bq
91
- # }
92
- # html = html.gsub(/\n&gt\;(.*)<\/p>/) { |bq|
93
- # bq.delete_prefix!("\n&gt\;")
94
- # bq.delete_suffix!("</p>")
95
- # " " + bq + "</blockquote>"
96
- # }
97
-
98
52
  html
99
53
  end
100
-
101
-
102
- def self.escape_existing_html(markdown)
103
- # markdown = markdown.gsub(/<\/(?!iframe)/, "&lt;/")
104
- # markdown = markdown.gsub(/<(?!iframe)/, "&lt;")
105
- # markdown = markdown.gsub(/(?<!iframe)>/, "&gt;")
106
- # byebug
107
- # markdown = markdown.gsub(/```(.*?)```/) {|s|
108
- # byebug
109
- # }
110
- end
111
-
54
+
112
55
  def self.remove_header_and_footer(html)
113
56
  new_html = self.remove_html_header(html)
114
- new_html = self.remove_footer(new_html)
57
+ # new_html = self.remove_footer(new_html)
115
58
  new_html
116
59
  end
117
60
 
@@ -128,7 +71,7 @@ class RepositoryConverter
128
71
  end
129
72
 
130
73
  def self.remove_html_header(html)
131
- html.gsub(/<h1>.*<\/h1>/,"")
74
+ html.gsub(/<h1>.*?<\/h1>/,"")
132
75
  end
133
76
 
134
77
  def self.fix_local_html_links(options, html, filepath)
@@ -1,3 +1,3 @@
1
1
  class GithubToCanvas
2
- VERSION = "0.1.13"
2
+ VERSION = "0.1.17"
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.13
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxwellbenton
@@ -11,47 +11,47 @@ cert_chain: []
11
11
  date: 2020-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: faraday
14
+ name: redcarpet
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.15'
19
+ version: '3.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.15'
26
+ version: '3.5'
27
27
  - !ruby/object:Gem::Dependency
28
- name: redcarpet
28
+ name: rest-client
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.5'
33
+ version: '2.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.5'
40
+ version: '2.1'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rest-client
42
+ name: rouge
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.1'
47
+ version: '3.26'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.1'
54
+ version: '3.26'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: json
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []
111
- rubygems_version: 3.2.3
111
+ rubygems_version: 3.0.9
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: github-to-canvas is a tool for migrating and aligning GitHub content with