diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2017-07-15 23:53:18 -0600 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2017-07-15 23:53:18 -0600 |
| commit | bc004af685ed7cf7de1883fbca47e39afdaca483 (patch) | |
| tree | 3674257b4192fe88919d7a2610b42c8e49e1b1e5 /lib | |
| parent | 513c4f074aca479403df049b7ed858ad19f2e20b (diff) | |
match atx section title more efficiently
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/asciidoctor.rb | 18 | ||||
| -rw-r--r-- | lib/asciidoctor/parser.rb | 12 |
2 files changed, 15 insertions, 15 deletions
diff --git a/lib/asciidoctor.rb b/lib/asciidoctor.rb index 7de5b39a..5d566f16 100644 --- a/lib/asciidoctor.rb +++ b/lib/asciidoctor.rb @@ -621,23 +621,23 @@ module Asciidoctor ## Section titles - # Matches a single-line (Atx-style) section title. + # Matches an Atx (single-line) section title. # # Examples # # == Foo - # # ^ a level 1 (h2) section title + # // ^ a level 1 (h2) section title # # == Foo == - # # ^ also a level 1 (h2) section title + # // ^ also a level 1 (h2) section title # - # match[1] is the delimiter, whose length determines the level - # match[2] is the title itself - # match[3] is an inline anchor, which becomes the section id - AtxSectionTitleRx = /^(=={0,5}|#\#{0,5})[ \t]+(.+?)(?:[ \t]+\1)?$/ + AtxSectionTitleRx = /^(=={0,5})[ \t]+(.+?)(?:[ \t]+\1)?$/ - # Matches the restricted section name for a two-line (Setext-style) section title. - # The name cannot begin with a dot and has at least one alphanumeric character. + # Matches an extended Atx section title that includes support for the Markdown variant. + ExtAtxSectionTitleRx = /^(=={0,5}|#\#{0,5})[ \t]+(.+?)(?:[ \t]+\1)?$/ + + # Matches the title only (first line) of an Setext (two-line) section title. + # The title cannot begin with a dot and must have at least one alphanumeric character. SetextSectionTitleRx = /^((?=.*#{CG_WORD}+.*)[^.].*?)$/ # Matches an anchor (i.e., id + optional reference text) inside a section title. diff --git a/lib/asciidoctor/parser.rb b/lib/asciidoctor/parser.rb index 8a0c87a4..775b0790 100644 --- a/lib/asciidoctor/parser.rb +++ b/lib/asciidoctor/parser.rb @@ -1651,10 +1651,10 @@ class Parser is_single_line_section_title?(line1) || (line2.nil_or_empty? ? nil : is_two_line_section_title?(line1, line2)) end - def self.is_single_line_section_title?(line1) - if (line1.start_with?('=') || (Compliance.markdown_syntax && line1.start_with?('#'))) && AtxSectionTitleRx =~ line1 - #if line1.start_with?('=', '#') && AtxSectionTitleRx =~ line1 && (line1.start_with?('=') || Compliance.markdown_syntax) - # NOTE level is 1 less than number of line markers + # NOTE level is 1 less than number of line markers + def self.is_single_line_section_title?(line) + if Compliance.markdown_syntax ? ((line.start_with? '=', '#') && ExtAtxSectionTitleRx =~ line) : + ((line.start_with? '=') && AtxSectionTitleRx =~ line) $1.length - 1 end end @@ -1714,8 +1714,8 @@ class Parser sect_id = sect_reftext = nil line1 = reader.read_line - #if line1.start_with?('=', '#') && AtxSectionTitleRx =~ line1 && (line1.start_with?('=') || Compliance.markdown_syntax) - if (line1.start_with?('=') || (Compliance.markdown_syntax && line1.start_with?('#'))) && AtxSectionTitleRx =~ line1 + if Compliance.markdown_syntax ? ((line1.start_with? '=', '#') && ExtAtxSectionTitleRx =~ line1) : + ((line1.start_with? '=') && AtxSectionTitleRx =~ line1) # NOTE level is 1 less than number of line markers sect_level, sect_title, single_line = $1.length - 1, $2, true if sect_title.end_with?(']]') && InlineSectionAnchorRx =~ sect_title && !$1 # escaped |
