github-to-canvas 0.1.15 → 0.1.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -5
- data/README.md +85 -73
- data/bin/github-to-canvas +10 -18
- data/lib/github-to-canvas/canvas_interface.rb +4 -7
- data/lib/github-to-canvas/repository_converter.rb +15 -87
- data/lib/github-to-canvas/version.rb +1 -1
- data/lib/github-to-canvas.rb +1 -7
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9ec39071e3c80339a136e20aec41d807f024ae78683d504bac9b8416b7bd62d
|
4
|
+
data.tar.gz: 59e1d8e61fcd871a903e15410d9d3440ce38386f5b11c2e215af825a08b61910
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6ab65ee006dbb2326437f8805c40bb43b92798e3850f5d474c0c84fe40e969ffd0e1add8ca78f0b242a11aec802e0e47739fd5571bdfbdbeab60e7b3e0a3314
|
7
|
+
data.tar.gz: dec6317c2ccbe88982acd732b9de84c5ee791796369f34c2227383e5bb75105e92e96929f806cec5e06540a1a4544e5e5b5527185eb9e658839cb5f4ac7d151f
|
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
|
8
|
-
|
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
|
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
|
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
|
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
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
- :id: 2021
|
216
|
-
|
217
|
-
|
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,24 @@ 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.
|
253
|
+
|
254
|
+
```yaml
|
255
|
+
---
|
256
|
+
:name: Test Building Course
|
257
|
+
:course_code: TEST-GEM-COURSE
|
258
|
+
:modules:
|
259
|
+
- :name: Module 1
|
260
|
+
:lessons:
|
261
|
+
- title: Lesson 1
|
262
|
+
type: Assignment
|
263
|
+
repository: https://github.com/learn-co-curriculum/react-hooks-component-props-mini-project
|
264
|
+
- title: Lesson 2
|
265
|
+
type: Page
|
266
|
+
repository: https://github.com/learn-co-curriculum/phase-0-pac-1-js-variables
|
267
|
+
```
|
250
268
|
|
251
269
|
With the necessary data configured, use the `--build-course` option and pass in
|
252
270
|
the course's YAML file:
|
@@ -262,7 +280,7 @@ This command will cause the following to happen:
|
|
262
280
|
- Create the first lesson using the repository, title and type, as well as additional command options
|
263
281
|
- Add the newly created lesson to the current module
|
264
282
|
- Create the second lesson and add it to the module...
|
265
|
-
-
|
283
|
+
- Repeat process until all modules and lessons are created
|
266
284
|
|
267
285
|
#### Update Lessons in an Existing Course from a YAML file <a name="updatecourse"></a>
|
268
286
|
|
@@ -285,6 +303,23 @@ github-to-canvas --update-course YAML_FILE -lr --forkable
|
|
285
303
|
The gem will iterate over the data and update every lesson according to the
|
286
304
|
associated repository.
|
287
305
|
|
306
|
+
## Syntax Highlighting <a name="syntaxhighlighting"></a>
|
307
|
+
|
308
|
+
This gem uses the [Rouge](https://github.com/rouge-ruby/rouge) Ruby gem to add
|
309
|
+
syntax highlighting to
|
310
|
+
[fenced code blocks](https://www.markdownguide.org/extended-syntax/#syntax-highlighting).
|
311
|
+
Rouge tokenizes the fenced code blocks and generates HTML elements with CSS
|
312
|
+
classes to style code blocks. The classes generated by Rouge are intended to
|
313
|
+
work with [Pygments](https://pygments.org/).
|
314
|
+
|
315
|
+
You can download and customize CSS themes for the classes generated by Rouge at this site:
|
316
|
+
|
317
|
+
- [http://jwarby.github.io/jekyll-pygments-themes/languages/javascript.html](http://jwarby.github.io/jekyll-pygments-themes/languages/javascript.html)
|
318
|
+
|
319
|
+
After selecting your preferred CSS, you will need to
|
320
|
+
[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)
|
321
|
+
so the CSS can run on each page.
|
322
|
+
|
288
323
|
## Known Issues
|
289
324
|
|
290
325
|
### HTML Code Snippets Do Not Render
|
@@ -294,58 +329,35 @@ includes HTML that is not meant to be rendered, the content will be rendered as
|
|
294
329
|
part of the page's HTML, resulting in unusual display errors in Canvas. Examples of
|
295
330
|
this would be lessons on HTML or JavaScript that include HTML code snippets.
|
296
331
|
|
297
|
-
To
|
298
|
-
|
299
|
-
|
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`:
|
332
|
+
To fix any rendering issues in Canvas, go to the Canvas WYSIWYG editor for the
|
333
|
+
afflicted lesson. Click the HTML editor option (`</>` button in the lower right) to
|
334
|
+
switch to HTML.
|
314
335
|
|
315
|
-
|
316
|
-
- Click the HTML editor option (`</>` button in the lower right) to switch to
|
317
|
-
HTML.
|
318
|
-
- Read the GitHub repo as HTML:
|
336
|
+
Read the GitHub repo as HTML:
|
319
337
|
|
320
|
-
|
321
|
-
|
322
|
-
|
338
|
+
```sh
|
339
|
+
github-to-canvas --read-from-github URL
|
340
|
+
```
|
323
341
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
342
|
+
Copy the output HTML and paste it into the Canvas editor (if your lesson has a
|
343
|
+
`<header>` with github links, leave this in). This should clear up some larger
|
344
|
+
page rendering issues, but may not fix all code snippets issues. To fix these,
|
345
|
+
switch back to the regular Canvas WYSIWYG editor, then open a second tab to the
|
346
|
+
GitHub repo you're converting from. Copy any HTML code snippets from GitHub and
|
347
|
+
paste them into the Canvas editor where they should be displayed.
|
330
348
|
|
331
349
|
The Canvas editor will treat the pasted HTML content as code and will
|
332
350
|
automatically replace some characters, escaping the code from the
|
333
351
|
normal rendering process.
|
334
352
|
|
335
|
-
Note that realigning after fixing this content
|
336
|
-
|
337
|
-
|
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.
|
353
|
+
Note that realigning after fixing this content with the gem will break the
|
354
|
+
rendering for these lessons again. A fix is planned for this issue, but has not
|
355
|
+
been implemented.
|
344
356
|
|
345
357
|
### Markdown Formatting Issues Cause Errors in Canvas
|
346
358
|
|
347
359
|
An empty line should separate individual markdown headers, paragraphs and code snippets
|
348
|
-
in the markdown. Without these empty lines, the contents will be
|
360
|
+
in the markdown. Without these empty lines, the contents will be interpreted as one
|
349
361
|
continuous paragraph and ignore formatting.
|
350
362
|
|
351
363
|
### New Repos That Use a `main` Branch
|
@@ -419,7 +431,7 @@ Run `github-to-canvas --help` for additional options not listed in this Readme.
|
|
419
431
|
|
420
432
|
## Examples of Valid Images This Gem Can Convert
|
421
433
|
|
422
|
-
This gem can convert both standard inline markdown and HTML images.
|
434
|
+
This gem can convert both standard inline markdown and HTML images.
|
423
435
|
|
424
436
|
Inline Markdown:
|
425
437
|
|
@@ -431,5 +443,5 @@ HTML:
|
|
431
443
|
<img src="https://curriculum-content.s3.amazonaws.com/fewpjs/fewpjs-fetch-lab/Image_25_AsynchronousJavaScript.png" width="500">
|
432
444
|
</p>
|
433
445
|
|
434
|
-
[
|
435
|
-
[
|
446
|
+
[canvas lms api]: https://canvas.instructure.com/doc/api/index.html
|
447
|
+
[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
|
-
|
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
|
-
"
|
195
|
-
|
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
|
@@ -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)
|
@@ -56,7 +55,7 @@ class CanvasInterface
|
|
56
55
|
'module_item[title]' => lesson_info["title"],
|
57
56
|
'module_item[type]' => lesson_info["type"].capitalize,
|
58
57
|
'module_item[indent]' => 0,
|
59
|
-
'module_item[page_url]' => lesson_info["
|
58
|
+
'module_item[page_url]' => lesson_info["page_url"],
|
60
59
|
'module_item[completion_requirement][type]' => 'must_view'
|
61
60
|
}
|
62
61
|
elsif lesson_info["type"] == "Quiz"
|
@@ -218,12 +217,9 @@ class CanvasInterface
|
|
218
217
|
response = RestClient.get(url, self.headers)
|
219
218
|
lessons = JSON.parse(response.body)
|
220
219
|
lessons = lessons.map do |lesson|
|
221
|
-
if lesson["type"] == "ExternalUrl"
|
222
|
-
next
|
223
|
-
end
|
224
220
|
lesson = lesson.slice("id","title","name","indent","type","html_url","page_url","url","completion_requirement", "published")
|
225
221
|
lesson["repository"] = ""
|
226
|
-
lesson['id'] = lesson['url']
|
222
|
+
lesson['id'] = lesson['url']&.gsub(/^(.*[\\\/])/,'')
|
227
223
|
lesson
|
228
224
|
end
|
229
225
|
if ([200, 201].include? response.code) && (!lessons.empty?)
|
@@ -248,6 +244,7 @@ class CanvasInterface
|
|
248
244
|
course_info = YAML.load(File.read("#{Dir.pwd}/#{options[:file_to_convert]}"))
|
249
245
|
course_info[:modules] = course_info[:modules].map do |mod|
|
250
246
|
mod[:lessons] = mod[:lessons].map do |lesson|
|
247
|
+
next lesson unless lesson.key?("url")
|
251
248
|
|
252
249
|
url = lesson["url"]
|
253
250
|
response = RestClient.get(url, headers={
|
@@ -290,7 +287,7 @@ class CanvasInterface
|
|
290
287
|
end
|
291
288
|
mod
|
292
289
|
end
|
293
|
-
puts course_info.to_yaml if !options[:urls_only]
|
290
|
+
puts course_info.to_yaml if !(options[:urls_only] || options[:csv])
|
294
291
|
end
|
295
292
|
|
296
293
|
def self.csv(file_to_convert)
|
@@ -1,15 +1,9 @@
|
|
1
1
|
require 'redcarpet'
|
2
|
-
require '
|
3
|
-
|
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
|
-
|
11
|
-
|
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
|
-
|
47
|
-
|
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
|
-
|
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,73 +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
52
|
html
|
68
53
|
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("&gt;</code>", "></code>")
|
74
|
-
# html = html.gsub("&gt;</code>", "></code>")
|
75
|
-
|
76
|
-
# fixes < and > code snippets
|
77
|
-
|
78
|
-
# html = html.gsub(/<pre><code>(.*?)<\/code><\/pre>/) { |string|
|
79
|
-
# byebug
|
80
|
-
# }
|
81
|
-
# html = html.gsub("&gt;", ">")
|
82
|
-
|
83
|
-
# # fixes blockquotes
|
84
|
-
# html = html.gsub(/\n<p>>\;(.*)\n>\;/) { |bq|
|
85
|
-
# bq.delete_prefix!("\n<p>>")
|
86
|
-
# "\n<blockquote>" + bq
|
87
|
-
# }
|
88
|
-
# html = html.gsub(/\n>\;(.*)\n>\;/) { |bq|
|
89
|
-
# bq.delete_prefix!("\n>")
|
90
|
-
# " " + bq
|
91
|
-
# }
|
92
|
-
# html = html.gsub(/\n>\;(.*)<\/p>/) { |bq|
|
93
|
-
# bq.delete_prefix!("\n>\;")
|
94
|
-
# bq.delete_suffix!("</p>")
|
95
|
-
# " " + bq + "</blockquote>"
|
96
|
-
# }
|
97
|
-
|
98
|
-
html
|
99
|
-
end
|
100
|
-
|
101
|
-
|
102
|
-
def self.escape_existing_html(markdown)
|
103
|
-
markdown = markdown.gsub(/```(\n|.)*```/) { |code|
|
104
|
-
# all blocks
|
105
|
-
code = code.gsub("<", "<")
|
106
|
-
code = code.gsub(">", ">")
|
107
|
-
}
|
108
|
-
# markdown = markdown.gsub(/(`)(.+?)(`)/) { |code|
|
109
|
-
# # all backticks
|
110
|
-
|
111
|
-
# if code.match?(/<(.*?)>/)
|
112
|
-
# code = code.gsub("<", "<")
|
113
|
-
# code = code.gsub(">", ">")
|
114
|
-
# end
|
115
|
-
|
116
|
-
# code
|
117
|
-
# }
|
118
|
-
# markdown = markdown.gsub(/<(?!iframe)/, "<")
|
119
|
-
# markdown = markdown.gsub(/(?<!iframe)>/, ">")
|
120
|
-
|
121
|
-
# markdown = markdown.gsub(/```(.*?)```/) {|s|
|
122
|
-
# byebug
|
123
|
-
# }
|
124
|
-
markdown
|
125
|
-
end
|
126
|
-
|
54
|
+
|
127
55
|
def self.remove_header_and_footer(html)
|
128
56
|
new_html = self.remove_html_header(html)
|
129
|
-
new_html = self.remove_footer(new_html)
|
57
|
+
# new_html = self.remove_footer(new_html)
|
130
58
|
new_html
|
131
59
|
end
|
132
60
|
|
@@ -143,7 +71,7 @@ class RepositoryConverter
|
|
143
71
|
end
|
144
72
|
|
145
73
|
def self.remove_html_header(html)
|
146
|
-
html.gsub(/<h1
|
74
|
+
html.gsub(/<h1>.*?<\/h1>/,"")
|
147
75
|
end
|
148
76
|
|
149
77
|
def self.fix_local_html_links(options, html, filepath)
|
data/lib/github-to-canvas.rb
CHANGED
@@ -85,7 +85,7 @@ class GithubToCanvas
|
|
85
85
|
html = RepositoryConverter.remote_file_conversion(options)
|
86
86
|
# Add each lesson to it's module
|
87
87
|
html = RepositoryConverter.adjust_converted_html(options, html)
|
88
|
-
created_lesson_info = CanvasInterface.create_lesson(options, lesson["title"], html)
|
88
|
+
created_lesson_info = CanvasInterface.create_lesson(options, lesson["title"], html)
|
89
89
|
lesson = lesson.merge(created_lesson_info)
|
90
90
|
|
91
91
|
lesson["page_url"] = lesson["url"] if !lesson["page_url"]
|
@@ -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)
|
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.
|
4
|
+
version: 0.1.18
|
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:
|
14
|
+
name: redcarpet
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
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: '
|
26
|
+
version: '3.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rest-client
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
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: '
|
40
|
+
version: '2.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rouge
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
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: '
|
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.
|
111
|
+
rubygems_version: 3.1.4
|
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
|