mdc/lib/parsing/parser.rb
##
# Parse the given string or file into the given presentation.
# @param [String] lines input to be parsed
# @param [String] file_name File to be parsed
# @param [String] default_language language for code blocks not tagged
# @param [Domain::Presentation] presentation Storage of results
Parse the given string or file into the given presentation.
Parse the given string or file into the given presentation .
def parse_lines(lines, file_name, default_language, presentation)
      ps = ParserState.new(presentation, file_name, @last_slide_counter,
                           :NORMAL,
                           :CODE_FENCED,
                           :CODE,
                           :SCRIPT,
                           :EQUATION,
                           :UL1,
                           :UL2,
                           :UL3,
                           :OL1,
                           :OL2,
                           :OL3,
                           :TABLE,
                           :QUOTE,
                           :UML,
                           :IMPORTANT,
                           :QUESTION,
                           :BOX)
      ps.language = default_language
      ps.comment_mode = false
      ps.chapter_counter = @chapter_counter
      handler = @parser_handler
      lines.each do |raw_line|
        line = MarkdownLine.new(raw_line)
        ps.line_counter = ps.line_counter + 1
        if line.code_include? && !ps.code_or_code_fenced?
          handler.code_include(ps, line)
        elsif line.multiple_choice?
          handler.multiple_choice(ps, line)
        elsif line.separator? && !ps.code_or_code_fenced? && !ps.comment_mode
          handler.separator(ps, line)
        elsif line.separator? && !ps.code_or_code_fenced? && ps.comment_mode
          ps.comment_mode = false
        elsif line.vertical_space? && !ps.code_or_code_fenced?
          handler.vertical_space?(ps, line)
        elsif line.chapter_title? && !ps.code_or_code_fenced?
          handler.chapter_title(ps, line)
        elsif line.slide_title? && !ps.code_or_code_fenced?
          handler.slide_title(ps, line)
        elsif line.fenced_code_start? && !ps.code_fenced?
          handler.code_fenced_start(ps, line)
        elsif line.fenced_code_end? && ps.code_fenced?
          ps.normal!
        elsif line.script_end? && ps.script?
          ps.normal!
        elsif ps.script?
          handler.script_line(ps, line)
        elsif line.script_start? && !ps.code_or_code_fenced?
          handler.script_start(ps, line)
        elsif line.equation_start? && !ps.equation?
          handler.equation_start(ps, line)
        elsif line.equation_end? && ps.equation?
          ps.normal!
        elsif ps.equation?
          handler.equation_line(ps, line)
        elsif line.uml_start? && !ps.uml?
          handler.uml_start(ps, line)
        elsif line.uml_end? && ps.uml?
          ps.normal!
        elsif ps.uml?
          handler.uml_line(ps, line)
        elsif line.ol1? && !ps.code_or_code_fenced?
          handler.ol1(ps, line)
        elsif line.ol2? && !ps.code_or_code_fenced?
          handler.ol2(ps, line)
        elsif line.ol3? && !ps.code_or_code_fenced?
          handler.ol3(ps, line)
        elsif line.ul2? && ps.code?
          handler.code_with_stars(ps, line)
        elsif line.ul1? && !ps.code_or_code_fenced?
          handler.ul1(ps, line)
        elsif line.ul2? && !ps.code_or_code_fenced?
          handler.ul2(ps, line)
        elsif line.ul3? && !ps.code_or_code_fenced?
          handler.ul3(ps, line)
        elsif line.source? && !ps.code_or_code_fenced? && !line.empty?
          handler.source_start(ps, line)
        elsif line.source? && ps.code? && !line.empty?
          handler.source_line(ps, line)
        elsif ps.code? && line.empty?
          handler.source_lookahead(ps, lines)
        elsif ps.code_fenced?
          handler.fenced_code_line(ps, line)
        elsif line.quote? || line.quote_source?
          handler.quote(ps, line)
        elsif line.important?
          handler.important(ps, line)
        elsif line.question?
          handler.question(ps, line)
        elsif line.box?
          handler.box(ps, line)
        elsif line.table_row?
          handler.table(ps, line)
        elsif line.space_comment?
          handler.space_comment(ps, line)
        elsif line.comment? & !line.image?
          handler.comment(ps, line)
        else
          handler.inline(ps, line)
        end
      end
      @last_slide_counter = ps.slide_counter
      @chapter_counter = ps.chapter_counter
    end
def parse_lines ( lines , file_name , default_language , presentation ) ps = ParserState . new ( presentation , file_name , @last_slide_counter , :NORMAL , :CODE_FENCED , :CODE , :SCRIPT , :EQUATION , :UL1 , :UL2 , :UL3 , :OL1 , :OL2 , :OL3 , :TABLE , :QUOTE , :UML , :IMPORTANT , :QUESTION , :BOX ) ps . language = default_language ps . comment_mode = false ps . chapter_counter = @chapter_counter handler = @parser_handler lines . each do | raw_line | line = MarkdownLine . new ( raw_line ) ps . line_counter = ps . line_counter + 1 if line . code_include? && ! ps . code_or_code_fenced? handler . code_include ( ps , line ) elsif line . multiple_choice? handler . multiple_choice ( ps , line ) elsif line . separator? && ! ps . code_or_code_fenced? && ! ps . comment_mode handler . separator ( ps , line ) elsif line . separator? && ! ps . code_or_code_fenced? && ps . comment_mode ps . comment_mode = false elsif line . vertical_space? && ! ps . code_or_code_fenced? handler . vertical_space? ( ps , line ) elsif line . chapter_title? && ! ps . code_or_code_fenced? handler . chapter_title ( ps , line ) elsif line . slide_title? && ! ps . code_or_code_fenced? handler . slide_title ( ps , line ) elsif line . fenced_code_start? && ! ps . code_fenced? handler . code_fenced_start ( ps , line ) elsif line . fenced_code_end? && ps . code_fenced? ps . normal! elsif line . script_end? && ps . script? ps . normal! elsif ps . script? handler . script_line ( ps , line ) elsif line . script_start? && ! ps . code_or_code_fenced? handler . script_start ( ps , line ) elsif line . equation_start? && ! ps . equation? handler . equation_start ( ps , line ) elsif line . equation_end? && ps . equation? ps . normal! elsif ps . equation? handler . equation_line ( ps , line ) elsif line . uml_start? && ! ps . uml? handler . uml_start ( ps , line ) elsif line . uml_end? && ps . uml? ps . normal! elsif ps . uml? handler . uml_line ( ps , line ) elsif line . ol1? && ! ps . code_or_code_fenced? handler . ol1 ( ps , line ) elsif line . ol2? && ! ps . code_or_code_fenced? handler . ol2 ( ps , line ) elsif line . ol3? && ! ps . code_or_code_fenced? handler . ol3 ( ps , line ) elsif line . ul2? && ps . code? handler . code_with_stars ( ps , line ) elsif line . ul1? && ! ps . code_or_code_fenced? handler . ul1 ( ps , line ) elsif line . ul2? && ! ps . code_or_code_fenced? handler . ul2 ( ps , line ) elsif line . ul3? && ! ps . code_or_code_fenced? handler . ul3 ( ps , line ) elsif line . source? && ! ps . code_or_code_fenced? && ! line . empty? handler . source_start ( ps , line ) elsif line . source? && ps . code? && ! line . empty? handler . source_line ( ps , line ) elsif ps . code? && line . empty? handler . source_lookahead ( ps , lines ) elsif ps . code_fenced? handler . fenced_code_line ( ps , line ) elsif line . quote? || line . quote_source? handler . quote ( ps , line ) elsif line . important? handler . important ( ps , line ) elsif line . question? handler . question ( ps , line ) elsif line . box? handler . box ( ps , line ) elsif line . table_row? handler . table ( ps , line ) elsif line . space_comment? handler . space_comment ( ps , line ) elsif line . comment? & ! line . image? handler . comment ( ps , line ) else handler . inline ( ps , line ) end end @last_slide_counter = ps . slide_counter @chapter_counter = ps . chapter_counter end
Parse the given string or file into the given presentation.
Parse the given string or file into the given presentation .
#     begin # !INCLUDESRC[x] "path" Language # [ ] Question 1 or [X] Question # --- # --- # <br> # # Chapter Title # ## Slide Title # ```code # ``` # </script> # inside <script>...</script> # <script> # \[ # \] # @startuml # @enduml #   1. item #     1. item #       1. item # special case. Code starts with a * sign #   * Item # > Quote # >! Important text # >? Question text # >: Generic box # | Table | Table | # <!-- Spacing: xx --> # <!-- --> but not after an image, to allow image dimensions # in comments. # Other cases (simple inline matches) #      rescue Exception => e #        puts e #        puts ps.to_s #        exit(-1) #      end # As chapters may be parsed separately, with new invocations of the # parse method, the counter of the last slide of the previous chapter # needs to be saved to ensure correct slide numbering
lines
<not_specific>
file_name
<not_specific>
default_language
<not_specific>
presentation
<not_specific>
<not_specific>
presentation Storage of results
presentation Storage of results