Module: GithubToCanvasQuiz::Parser::Canvas::Helpers

Included in:
Answer::Base, Question, Quiz
Defined in:
lib/github_to_canvas_quiz/parser/canvas/helpers.rb

Instance Method Summary collapse

Instance Method Details

#choose_text(text, html) ⇒ Object



7
8
9
# File 'lib/github_to_canvas_quiz/parser/canvas/helpers.rb', line 7

def choose_text(text, html)
  html.empty? ? text : clean_html(html)
end

#clean_html(html) ⇒ Object



11
12
13
14
# File 'lib/github_to_canvas_quiz/parser/canvas/helpers.rb', line 11

def clean_html(html)
  html = remove_canvas_cruft(html)
  HTMLEntities.new.decode(html)
end

#remove_canvas_cruft(html) ⇒ Object



16
17
18
19
20
21
# File 'lib/github_to_canvas_quiz/parser/canvas/helpers.rb', line 16

def remove_canvas_cruft(html)
  nodes = Nokogiri::HTML5.fragment(html)
  nodes.css('.screenreader-only').remove
  cleaned_html = nodes.to_html
  cleaned_html.gsub(/\(?Links to an external site.\)?/, '')
end