motion-kramdown 0.6.0 → 1.16.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +6 -2
- data/lib/kramdown.rb +1 -1
- data/lib/kramdown/converter.rb +10 -11
- data/lib/kramdown/converter/base.rb +19 -12
- data/lib/kramdown/converter/hash_ast.rb +38 -0
- data/lib/kramdown/converter/html.rb +71 -39
- data/lib/kramdown/converter/kramdown.rb +19 -10
- data/lib/kramdown/converter/latex.rb +28 -10
- data/lib/kramdown/converter/man.rb +303 -0
- data/lib/kramdown/converter/math_engine/itex2mml.rb +2 -2
- data/lib/kramdown/converter/math_engine/mathjax.rb +13 -3
- data/lib/kramdown/converter/math_engine/mathjaxnode.rb +56 -0
- data/lib/kramdown/converter/math_engine/ritex.rb +2 -2
- data/lib/kramdown/converter/math_engine/sskatex.rb +97 -0
- data/lib/kramdown/converter/pdf.rb +6 -6
- data/lib/kramdown/converter/remove_html_tags.rb +5 -3
- data/lib/kramdown/converter/syntax_highlighter.rb +5 -2
- data/lib/kramdown/converter/syntax_highlighter/coderay.rb +8 -5
- data/lib/kramdown/converter/syntax_highlighter/minted.rb +35 -0
- data/lib/kramdown/converter/syntax_highlighter/rouge.rb +48 -10
- data/lib/kramdown/converter/toc.rb +2 -2
- data/lib/kramdown/document.rb +16 -19
- data/lib/kramdown/element.rb +5 -1
- data/lib/kramdown/error.rb +1 -1
- data/lib/kramdown/options.rb +103 -7
- data/lib/kramdown/parser.rb +1 -1
- data/lib/kramdown/parser/base.rb +12 -18
- data/lib/kramdown/parser/gfm.rb +142 -11
- data/lib/kramdown/parser/html.rb +28 -18
- data/lib/kramdown/parser/kramdown.rb +45 -36
- data/lib/kramdown/parser/kramdown/abbreviation.rb +1 -1
- data/lib/kramdown/parser/kramdown/autolink.rb +2 -8
- data/lib/kramdown/parser/kramdown/blank_line.rb +2 -2
- data/lib/kramdown/parser/kramdown/block_boundary.rb +4 -4
- data/lib/kramdown/parser/kramdown/blockquote.rb +4 -4
- data/lib/kramdown/parser/kramdown/codeblock.rb +11 -8
- data/lib/kramdown/parser/kramdown/codespan.rb +1 -1
- data/lib/kramdown/parser/kramdown/emphasis.rb +2 -2
- data/lib/kramdown/parser/kramdown/eob.rb +1 -1
- data/lib/kramdown/parser/kramdown/escaped_chars.rb +1 -1
- data/lib/kramdown/parser/kramdown/extensions.rb +6 -3
- data/lib/kramdown/parser/kramdown/footnote.rb +4 -5
- data/lib/kramdown/parser/kramdown/header.rb +2 -2
- data/lib/kramdown/parser/kramdown/horizontal_rule.rb +1 -1
- data/lib/kramdown/parser/kramdown/html.rb +8 -8
- data/lib/kramdown/parser/kramdown/html_entity.rb +2 -2
- data/lib/kramdown/parser/kramdown/line_break.rb +1 -1
- data/lib/kramdown/parser/kramdown/link.rb +5 -4
- data/lib/kramdown/parser/kramdown/list.rb +17 -10
- data/lib/kramdown/parser/kramdown/math.rb +2 -2
- data/lib/kramdown/parser/kramdown/paragraph.rb +19 -8
- data/lib/kramdown/parser/kramdown/smart_quotes.rb +3 -3
- data/lib/kramdown/parser/kramdown/table.rb +10 -12
- data/lib/kramdown/parser/kramdown/typographic_symbol.rb +1 -1
- data/lib/kramdown/parser/markdown.rb +2 -2
- data/lib/kramdown/utils.rb +2 -1
- data/lib/kramdown/utils/configurable.rb +2 -2
- data/lib/kramdown/utils/entities.rb +1 -1
- data/lib/kramdown/utils/html.rb +2 -2
- data/lib/kramdown/utils/lru_cache.rb +40 -0
- data/lib/kramdown/utils/ordered_hash.rb +2 -71
- data/lib/kramdown/utils/string_scanner.rb +2 -2
- data/lib/kramdown/utils/unidecoder.rb +2 -2
- data/lib/kramdown/version.rb +2 -2
- data/lib/rubymotion/require_override.rb +9 -0
- data/lib/rubymotion/version.rb +1 -1
- data/spec/{helpers → motion-kramdown/_helpers}/it_behaves_like.rb +0 -0
- data/spec/{helpers → motion-kramdown/_helpers}/option_file.rb +2 -2
- data/spec/{helpers → motion-kramdown/_helpers}/tidy.rb +0 -0
- data/spec/motion-kramdown/bench_mark.rb +37 -0
- data/spec/{document_tree.rb → motion-kramdown/document_tree.rb} +11 -1
- data/spec/{gfm_to_html.rb → motion-kramdown/gfm_to_html.rb} +51 -18
- data/spec/{html_to_html.rb → motion-kramdown/html_to_html.rb} +27 -9
- data/spec/{html_to_kramdown_to_html.rb → motion-kramdown/html_to_kramdown_to_html.rb} +35 -16
- data/spec/motion-kramdown/kramdown_to_xxx.rb +75 -0
- data/spec/{test_location.rb → motion-kramdown/test_location.rb} +0 -0
- data/spec/{test_string_scanner_kramdown.rb → motion-kramdown/test_string_scanner_kramdown.rb} +0 -0
- data/spec/motion-kramdown/text_manpage.rb +11 -0
- data/spec/{text_to_kramdown_to_html.rb → motion-kramdown/text_to_kramdown_to_html.rb} +30 -19
- data/spec/{text_to_latex.rb → motion-kramdown/text_to_latex.rb} +0 -0
- data/spec/{helpers/spec_options.rb → spec_helper.rb} +13 -2
- metadata +54 -33
- data/lib/kramdown/compatibility.rb +0 -36
- data/spec/bench_mark.rb +0 -43
- data/spec/kramdown_to_xxx.rb +0 -42
data/lib/kramdown/element.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2016 Thomas Leitner <t_leitner@gmx.at>
|
5
5
|
#
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
7
7
|
#++
|
@@ -98,6 +98,10 @@ module Kramdown
|
|
98
98
|
#
|
99
99
|
# The +value+ field has to contain the content of the code block.
|
100
100
|
#
|
101
|
+
# The option :lang specifies a highlighting language with possible HTML style options (e.g.
|
102
|
+
# php?start_inline=1) and should be used instead of a possibly also available language embedded in
|
103
|
+
# a class name of the form 'language-LANG'.
|
104
|
+
#
|
101
105
|
#
|
102
106
|
# === :ul
|
103
107
|
#
|
data/lib/kramdown/error.rb
CHANGED
data/lib/kramdown/options.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2016 Thomas Leitner <t_leitner@gmx.at>
|
5
5
|
#
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
7
7
|
#++
|
8
8
|
#
|
9
9
|
|
10
|
-
|
10
|
+
require 'yaml'
|
11
11
|
|
12
12
|
module Kramdown
|
13
13
|
|
@@ -133,14 +133,14 @@ module Kramdown
|
|
133
133
|
# - a comma separated string which is split into an array of values
|
134
134
|
# - or an array.
|
135
135
|
#
|
136
|
-
#
|
137
|
-
def self.simple_array_validator(val, name, size)
|
136
|
+
# Optionally, the array is checked for the correct size.
|
137
|
+
def self.simple_array_validator(val, name, size = nil)
|
138
138
|
if String === val
|
139
139
|
val = val.split(/,/)
|
140
140
|
elsif !(Array === val)
|
141
141
|
raise Kramdown::Error, "Invalid type #{val.class} for option #{name}"
|
142
142
|
end
|
143
|
-
if val.size != size
|
143
|
+
if size && val.size != size
|
144
144
|
raise Kramdown::Error, "Option #{name} needs exactly #{size} values"
|
145
145
|
end
|
146
146
|
val
|
@@ -473,6 +473,37 @@ EOF
|
|
473
473
|
val
|
474
474
|
end
|
475
475
|
|
476
|
+
define(:typographic_symbols, Object, {}, <<EOF) do |val|
|
477
|
+
Defines a mapping from typographical symbol to output characters
|
478
|
+
|
479
|
+
Typographical symbols are normally output using their equivalent Unicode
|
480
|
+
codepoint. However, sometimes one wants to change the output, mostly to
|
481
|
+
fallback to a sequence of ASCII characters.
|
482
|
+
|
483
|
+
This option allows this by specifying a mapping from typographical
|
484
|
+
symbol to its output string. For example, the mapping {hellip: ...} would
|
485
|
+
output the standard ASCII representation of an ellipsis.
|
486
|
+
|
487
|
+
The available typographical symbol names are:
|
488
|
+
|
489
|
+
* hellip: ellipsis
|
490
|
+
* mdash: em-dash
|
491
|
+
* ndash: en-dash
|
492
|
+
* laquo: left guillemet
|
493
|
+
* raquo: right guillemet
|
494
|
+
* laquo_space: left guillemet followed by a space
|
495
|
+
* raquo_space: right guillemet preceeded by a space
|
496
|
+
|
497
|
+
Default: {}
|
498
|
+
Used by: HTML/Latex converter
|
499
|
+
EOF
|
500
|
+
val = simple_hash_validator(val, :typographic_symbols)
|
501
|
+
val.keys.each do |k|
|
502
|
+
val[k.kind_of?(String) ? str_to_sym(k) : k] = val.delete(k).to_s
|
503
|
+
end
|
504
|
+
val
|
505
|
+
end
|
506
|
+
|
476
507
|
define(:remove_block_html_tags, Boolean, true, <<EOF)
|
477
508
|
Remove block HTML tags
|
478
509
|
|
@@ -525,7 +556,7 @@ Options for the syntax highlighter can be set with the
|
|
525
556
|
syntax_highlighter_opts configuration option.
|
526
557
|
|
527
558
|
Default: coderay
|
528
|
-
Used by: HTML converter
|
559
|
+
Used by: HTML/Latex converter
|
529
560
|
EOF
|
530
561
|
|
531
562
|
define(:syntax_highlighter_opts, Object, {}, <<EOF) do |val|
|
@@ -538,7 +569,7 @@ The value needs to be a hash with key-value pairs that are understood by
|
|
538
569
|
the used syntax highlighter.
|
539
570
|
|
540
571
|
Default: {}
|
541
|
-
Used by: HTML converter
|
572
|
+
Used by: HTML/Latex converter
|
542
573
|
EOF
|
543
574
|
val = simple_hash_validator(val, :syntax_highlighter_opts)
|
544
575
|
val.keys.each do |k|
|
@@ -580,6 +611,71 @@ EOF
|
|
580
611
|
val
|
581
612
|
end
|
582
613
|
|
614
|
+
define(:footnote_backlink, String, '↩', <<EOF)
|
615
|
+
Defines the text that should be used for the footnote backlinks
|
616
|
+
|
617
|
+
The footnote backlink is just text, so any special HTML characters will
|
618
|
+
be escaped.
|
619
|
+
|
620
|
+
If the footnote backlint text is an empty string, no footnote backlinks
|
621
|
+
will be generated.
|
622
|
+
|
623
|
+
Default: '&8617;'
|
624
|
+
Used by: HTML converter
|
625
|
+
EOF
|
626
|
+
|
627
|
+
define(:footnote_backlink_inline, Boolean, false, <<EOF)
|
628
|
+
Specifies whether the footnote backlink should always be inline
|
629
|
+
|
630
|
+
With the default of false the footnote backlink is placed at the end of
|
631
|
+
the last paragraph if there is one, or an extra paragraph with only the
|
632
|
+
footnote backlink is created.
|
633
|
+
|
634
|
+
Setting this option to true tries to place the footnote backlink in the
|
635
|
+
last, possibly nested paragraph or header. If this fails (e.g. in the
|
636
|
+
case of a table), an extra paragraph with only the footnote backlink is
|
637
|
+
created.
|
638
|
+
|
639
|
+
Default: false
|
640
|
+
Used by: HTML converter
|
641
|
+
EOF
|
642
|
+
|
643
|
+
define(:gfm_quirks, Object, [:paragraph_end], <<EOF) do |val|
|
644
|
+
Enables a set of GFM specific quirks
|
645
|
+
|
646
|
+
The way how GFM is transformed on Github often differs from the way
|
647
|
+
kramdown does things. Many of these differences are negligible but
|
648
|
+
others are not.
|
649
|
+
|
650
|
+
This option allows one to enable/disable certain GFM quirks, i.e. ways
|
651
|
+
in which GFM parsing differs from kramdown parsing.
|
652
|
+
|
653
|
+
The value has to be a list of quirk names that should be enabled,
|
654
|
+
separated by commas. Possible names are:
|
655
|
+
|
656
|
+
* paragraph_end
|
657
|
+
|
658
|
+
Disables the kramdown restriction that at least one blank line has to
|
659
|
+
be used after a paragraph before a new block element can be started.
|
660
|
+
|
661
|
+
Note that if this quirk is used, lazy line wrapping does not fully
|
662
|
+
work anymore!
|
663
|
+
|
664
|
+
* no_auto_typographic
|
665
|
+
|
666
|
+
Disables automatic conversion of some characters into their
|
667
|
+
corresponding typographic symbols (like `--` to em-dash etc).
|
668
|
+
This helps to achieve results closer to what GitHub Flavored
|
669
|
+
Markdown produces.
|
670
|
+
|
671
|
+
Default: paragraph_end
|
672
|
+
Used by: GFM parser
|
673
|
+
EOF
|
674
|
+
val = simple_array_validator(val, :gfm_quirks)
|
675
|
+
val.map! {|v| str_to_sym(v.to_s)}
|
676
|
+
val
|
677
|
+
end
|
678
|
+
|
583
679
|
end
|
584
680
|
|
585
681
|
end
|
data/lib/kramdown/parser.rb
CHANGED
data/lib/kramdown/parser/base.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2016 Thomas Leitner <t_leitner@gmx.at>
|
5
5
|
#
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
7
7
|
#++
|
8
8
|
#
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
require 'kramdown/utils'
|
11
|
+
require 'kramdown/parser'
|
12
12
|
|
13
13
|
module Kramdown
|
14
14
|
|
@@ -89,12 +89,10 @@ module Kramdown
|
|
89
89
|
# Modify the string +source+ to be usable by the parser (unifies line ending characters to
|
90
90
|
# +\n+ and makes sure +source+ ends with a new line character).
|
91
91
|
def adapt_source(source)
|
92
|
-
|
93
|
-
|
94
|
-
raise "The source text contains invalid characters for the used encoding #{source.encoding}"
|
95
|
-
end
|
96
|
-
source = source.encode('UTF-8')
|
92
|
+
unless source.valid_encoding?
|
93
|
+
raise "The source text contains invalid characters for the used encoding #{source.encoding}"
|
97
94
|
end
|
95
|
+
source = source.encode('UTF-8')
|
98
96
|
source.gsub(/\r\n?/, "\n").chomp + "\n"
|
99
97
|
end
|
100
98
|
|
@@ -113,16 +111,12 @@ module Kramdown
|
|
113
111
|
# method works correctly under Ruby 1.8 and Ruby 1.9.
|
114
112
|
def extract_string(range, strscan)
|
115
113
|
result = nil
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
strscan.string.force_encoding(enc)
|
123
|
-
end
|
124
|
-
else
|
125
|
-
result = strscan.string[range]
|
114
|
+
begin
|
115
|
+
enc = strscan.string.encoding
|
116
|
+
strscan.string.force_encoding('ASCII-8BIT')
|
117
|
+
result = strscan.string[range].force_encoding(enc)
|
118
|
+
ensure
|
119
|
+
strscan.string.force_encoding(enc)
|
126
120
|
end
|
127
121
|
result
|
128
122
|
end
|
data/lib/kramdown/parser/gfm.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (C) 2009-
|
4
|
+
# Copyright (C) 2009-2016 Thomas Leitner <t_leitner@gmx.at>
|
5
5
|
#
|
6
6
|
# This file is part of kramdown which is licensed under the MIT.
|
7
7
|
#++
|
8
8
|
#
|
9
9
|
|
10
10
|
|
11
|
-
|
11
|
+
require 'kramdown/parser'
|
12
12
|
|
13
13
|
module Kramdown
|
14
14
|
module Parser
|
@@ -16,47 +16,178 @@ module Kramdown
|
|
16
16
|
|
17
17
|
def initialize(source, options)
|
18
18
|
super
|
19
|
+
@options[:auto_id_stripping] = true
|
20
|
+
@id_counter = Hash.new(-1)
|
21
|
+
|
19
22
|
@span_parsers.delete(:line_break) if @options[:hard_wrap]
|
23
|
+
@span_parsers.delete(:typographic_syms) if @options[:gfm_quirks].include?(:no_auto_typographic)
|
24
|
+
if @options[:gfm_quirks].include?(:paragraph_end)
|
25
|
+
atx_header_parser = :atx_header_gfm_quirk
|
26
|
+
@paragraph_end = self.class::PARAGRAPH_END_GFM
|
27
|
+
else
|
28
|
+
atx_header_parser = :atx_header_gfm
|
29
|
+
@paragraph_end = self.class::PARAGRAPH_END
|
30
|
+
end
|
31
|
+
|
20
32
|
{:codeblock_fenced => :codeblock_fenced_gfm,
|
21
|
-
:atx_header =>
|
33
|
+
:atx_header => atx_header_parser}.each do |current, replacement|
|
22
34
|
i = @block_parsers.index(current)
|
23
35
|
@block_parsers.delete(current)
|
24
36
|
@block_parsers.insert(i, replacement)
|
25
37
|
end
|
38
|
+
|
39
|
+
i = @span_parsers.index(:escaped_chars)
|
40
|
+
@span_parsers[i] = :escaped_chars_gfm if i
|
41
|
+
@span_parsers << :strikethrough_gfm
|
26
42
|
end
|
27
43
|
|
28
44
|
def parse
|
29
45
|
super
|
30
|
-
|
46
|
+
update_elements(@root)
|
31
47
|
end
|
32
48
|
|
33
|
-
def
|
49
|
+
def update_elements(element)
|
34
50
|
element.children.map! do |child|
|
35
|
-
if child.type == :text && child.value =~ /\n/
|
51
|
+
if child.type == :text && @options[:hard_wrap] && child.value =~ /\n/
|
36
52
|
children = []
|
37
53
|
lines = child.value.split(/\n/, -1)
|
38
54
|
omit_trailing_br = (Kramdown::Element.category(element) == :block && element.children[-1] == child &&
|
39
55
|
lines[-1].empty?)
|
40
56
|
lines.each_with_index do |line, index|
|
41
|
-
|
42
|
-
|
57
|
+
new_element_options = { :location => child.options[:location] + index }
|
58
|
+
|
59
|
+
children << Element.new(:text, (index > 0 ? "\n#{line}" : line), nil, new_element_options)
|
60
|
+
children << Element.new(:br, nil, nil, new_element_options) if index < lines.size - 2 ||
|
43
61
|
(index == lines.size - 2 && !omit_trailing_br)
|
44
62
|
end
|
45
63
|
children
|
46
64
|
elsif child.type == :html_element
|
47
65
|
child
|
66
|
+
elsif child.type == :header && @options[:auto_ids] && !child.attr.has_key?('id')
|
67
|
+
child.attr['id'] = generate_gfm_header_id(child.options[:raw_text])
|
68
|
+
child
|
48
69
|
else
|
49
|
-
|
70
|
+
update_elements(child)
|
50
71
|
child
|
51
72
|
end
|
52
73
|
end.flatten!
|
53
74
|
end
|
54
75
|
|
76
|
+
# Update the raw text for automatic ID generation.
|
77
|
+
def update_raw_text(item)
|
78
|
+
raw_text = ''
|
79
|
+
|
80
|
+
append_text = lambda do |child|
|
81
|
+
if child.type == :text || child.type == :codespan || child.type ==:math
|
82
|
+
raw_text << child.value
|
83
|
+
elsif child.type == :entity
|
84
|
+
raw_text << child.value.char
|
85
|
+
elsif child.type == :smart_quote
|
86
|
+
raw_text << ::Kramdown::Utils::Entities.entity(child.value.to_s).char
|
87
|
+
elsif child.type == :typographic_sym
|
88
|
+
if child.value == :laquo_space
|
89
|
+
raw_text << "« "
|
90
|
+
elsif child.value == :raquo_space
|
91
|
+
raw_text << " »"
|
92
|
+
else
|
93
|
+
raw_text << ::Kramdown::Utils::Entities.entity(child.value.to_s).char
|
94
|
+
end
|
95
|
+
else
|
96
|
+
child.children.each {|c| append_text.call(c)}
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
append_text.call(item)
|
101
|
+
item.options[:raw_text] = raw_text
|
102
|
+
end
|
103
|
+
|
104
|
+
NON_WORD_RE = (RUBY_VERSION > "1.9" ? /[^\p{Word}\- \t]/ : /[^\w\- \t]/)
|
105
|
+
|
106
|
+
def generate_gfm_header_id(text)
|
107
|
+
result = text.downcase
|
108
|
+
result.gsub!(NON_WORD_RE, '')
|
109
|
+
result.tr!(" \t", '-')
|
110
|
+
@id_counter[result] += 1
|
111
|
+
result << (@id_counter[result] > 0 ? "-#{@id_counter[result]}" : '')
|
112
|
+
@options[:auto_id_prefix] + result
|
113
|
+
end
|
114
|
+
|
55
115
|
ATX_HEADER_START = /^\#{1,6}\s/
|
56
116
|
define_parser(:atx_header_gfm, ATX_HEADER_START, nil, 'parse_atx_header')
|
117
|
+
define_parser(:atx_header_gfm_quirk, ATX_HEADER_START)
|
118
|
+
|
119
|
+
# Copied from kramdown/parser/kramdown/header.rb, removed the first line
|
120
|
+
def parse_atx_header_gfm_quirk
|
121
|
+
start_line_number = @src.current_line_number
|
122
|
+
@src.check(ATX_HEADER_MATCH)
|
123
|
+
level, text, id = @src[1], @src[2].to_s.strip, @src[3]
|
124
|
+
return false if text.empty?
|
125
|
+
|
126
|
+
@src.pos += @src.matched_size
|
127
|
+
el = new_block_el(:header, nil, nil, :level => level.length, :raw_text => text, :location => start_line_number)
|
128
|
+
add_text(text, el)
|
129
|
+
el.attr['id'] = id if id
|
130
|
+
@tree.children << el
|
131
|
+
true
|
132
|
+
end
|
57
133
|
|
58
|
-
|
59
|
-
|
134
|
+
FENCED_CODEBLOCK_START = /^[ ]{0,3}[~`]{3,}/
|
135
|
+
FENCED_CODEBLOCK_MATCH = /^[ ]{0,3}(([~`]){3,})\s*?((\S+?)(?:\?\S*)?)?\s*?\n(.*?)^[ ]{0,3}\1\2*\s*?\n/m
|
136
|
+
define_parser(:codeblock_fenced_gfm, FENCED_CODEBLOCK_START, nil, 'parse_codeblock_fenced')
|
137
|
+
|
138
|
+
STRIKETHROUGH_DELIM = /~~/
|
139
|
+
STRIKETHROUGH_MATCH = /#{STRIKETHROUGH_DELIM}[^\s~](.*?)[^\s~]#{STRIKETHROUGH_DELIM}/m
|
140
|
+
define_parser(:strikethrough_gfm, STRIKETHROUGH_MATCH, '~~')
|
141
|
+
|
142
|
+
def parse_strikethrough_gfm
|
143
|
+
line_number = @src.current_line_number
|
144
|
+
|
145
|
+
@src.pos += @src.matched_size
|
146
|
+
el = Element.new(:html_element, 'del', {}, :category => :span, :line => line_number)
|
147
|
+
@tree.children << el
|
148
|
+
|
149
|
+
env = save_env
|
150
|
+
reset_env(:src => Kramdown::Utils::StringScanner.new(@src.matched[2..-3], line_number),
|
151
|
+
:text_type => :text)
|
152
|
+
parse_spans(el)
|
153
|
+
restore_env(env)
|
154
|
+
|
155
|
+
el
|
156
|
+
end
|
157
|
+
|
158
|
+
# To handle task-lists we override the parse method for lists, converting matching text into checkbox input
|
159
|
+
# elements where necessary (as well as applying classes to the ul/ol and li elements).
|
160
|
+
def parse_list
|
161
|
+
super
|
162
|
+
current_list = @tree.children.select{ |element| [:ul, :ol].include?(element.type) }.last
|
163
|
+
|
164
|
+
is_tasklist = false
|
165
|
+
box_unchecked = '<input type="checkbox" class="task-list-item-checkbox" disabled="disabled" />'
|
166
|
+
box_checked = '<input type="checkbox" class="task-list-item-checkbox" disabled="disabled" checked="checked" />'
|
167
|
+
|
168
|
+
current_list.children.each do |li|
|
169
|
+
next unless li.children.size > 0 && li.children[0].type == :p
|
170
|
+
# li -> p -> raw_text
|
171
|
+
checked = li.children[0].children[0].value.gsub!(/\A\s*\[ \]\s+/, box_unchecked)
|
172
|
+
unchecked = li.children[0].children[0].value.gsub!(/\A\s*\[x\]\s+/i, box_checked)
|
173
|
+
is_tasklist ||= (!checked.nil? || !unchecked.nil?)
|
174
|
+
|
175
|
+
li.attr['class'] = 'task-list-item' if is_tasklist
|
176
|
+
end
|
177
|
+
|
178
|
+
current_list.attr['class'] = 'task-list' if is_tasklist
|
179
|
+
|
180
|
+
true
|
181
|
+
end
|
182
|
+
|
183
|
+
ESCAPED_CHARS_GFM = /\\([\\.*_+`<>()\[\]{}#!:\|"'\$=\-~])/
|
184
|
+
define_parser(:escaped_chars_gfm, ESCAPED_CHARS_GFM, '\\\\', :parse_escaped_chars)
|
185
|
+
|
186
|
+
PARAGRAPH_END_GFM = /#{LAZY_END}|#{LIST_START}|#{ATX_HEADER_START}|#{DEFINITION_LIST_START}|#{BLOCKQUOTE_START}|#{FENCED_CODEBLOCK_START}/
|
187
|
+
|
188
|
+
def paragraph_end
|
189
|
+
@paragraph_end
|
190
|
+
end
|
60
191
|
|
61
192
|
end
|
62
193
|
end
|