Skip to content

Commit

Permalink
Merge pull request #22 from icyleaf/test/crystal-0.31
Browse files Browse the repository at this point in the history
Compatibility with Crystal 0.31
  • Loading branch information
icyleaf authored Sep 25, 2019
2 parents d6fc062 + e5d8b33 commit 20962e6
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 40 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ jobs:
working_directory: ~/markd
steps:
- checkout
- run:
name: "Crystal version"
command: crystal version
- run:
name: "Spec"
command: crystal spec
8 changes: 4 additions & 4 deletions src/markd/parsers/inline.cr
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,15 @@ module Markd::Parser
chars_length = chars.size

if chars_length % 3 == 0
em_count = chars_length / 3
em_count = chars_length // 3
elsif chars_length % 2 == 0
en_count = chars_length / 2
en_count = chars_length // 2
elsif chars_length % 3 == 2
en_count = 1
em_count = (chars_length - 2) / 3
em_count = (chars_length - 2) // 3
else
en_count = 2
em_count = (chars_length - 4) / 3
em_count = (chars_length - 4) // 3
end

"\u{2014}" * em_count + "\u{2013}" * en_count
Expand Down
8 changes: 4 additions & 4 deletions src/markd/rules/block_quote.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Markd::Rule
struct BlockQuote
include Rule

def match(parser : Parser, container : Node)
def match(parser : Parser, container : Node) : MatchValue
if match?(parser)
seek(parser)
parser.close_unmatched_blocks
Expand All @@ -14,7 +14,7 @@ module Markd::Rule
end
end

def continue(parser : Parser, container : Node)
def continue(parser : Parser, container : Node) : ContinueStatus
if match?(parser)
seek(parser)
ContinueStatus::Continue
Expand All @@ -23,15 +23,15 @@ module Markd::Rule
end
end

def token(parser : Parser, container : Node)
def token(parser : Parser, container : Node) : Nil
# do nothing
end

def can_contain?(type : Node::Type) : Bool
!type.item?
end

def accepts_lines?
def accepts_lines? : Bool
false
end

Expand Down
6 changes: 3 additions & 3 deletions src/markd/rules/code_block.cr
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module Markd::Rule
end
end

def continue(parser : Parser, container : Node)
def continue(parser : Parser, container : Node) : ContinueStatus
line = parser.line
indent = parser.indent
if container.fenced?
Expand Down Expand Up @@ -71,7 +71,7 @@ module Markd::Rule
ContinueStatus::Continue
end

def token(parser : Parser, container : Node)
def token(parser : Parser, container : Node) : Nil
if container.fenced?
# fenced
first_line, _, text = container.text.partition('\n')
Expand All @@ -88,7 +88,7 @@ module Markd::Rule
false
end

def accepts_lines?
def accepts_lines? : Bool
true
end
end
Expand Down
8 changes: 4 additions & 4 deletions src/markd/rules/document.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ module Markd::Rule
struct Document
include Rule

def match(parser : Parser, container : Node)
def match(parser : Parser, container : Node) : MatchValue
MatchValue::None
end

def continue(parser : Parser, container : Node)
def continue(parser : Parser, container : Node) : ContinueStatus
ContinueStatus::Continue
end

def token(parser : Parser, container : Node)
def token(parser : Parser, container : Node) : Nil
# do nothing
end

def can_contain?(type : Node::Type) : Bool
!type.item?
end

def accepts_lines?
def accepts_lines? : Bool
false
end
end
Expand Down
6 changes: 3 additions & 3 deletions src/markd/rules/heading.cr
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ module Markd::Rule
end
end

def token(parser : Parser, container : Node)
def token(parser : Parser, container : Node) : Nil
# do nothing
end

def continue(parser : Parser, container : Node)
def continue(parser : Parser, container : Node) : ContinueStatus
# a heading can never container > 1 line, so fail to match
ContinueStatus::Stop
end
Expand All @@ -56,7 +56,7 @@ module Markd::Rule
false
end

def accepts_lines?
def accepts_lines? : Bool
false
end

Expand Down
8 changes: 4 additions & 4 deletions src/markd/rules/html_block.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Markd::Rule
struct HTMLBlock
include Rule

def match(parser : Parser, container : Node)
def match(parser : Parser, container : Node) : MatchValue
if !parser.indented && parser.line[parser.next_nonspace]? == '<'
text = parser.line[parser.next_nonspace..-1]
block_type_size = Rule::HTML_BLOCK_OPEN.size - 1
Expand All @@ -24,19 +24,19 @@ module Markd::Rule
MatchValue::None
end

def continue(parser : Parser, container : Node)
def continue(parser : Parser, container : Node) : ContinueStatus
(parser.blank && {5, 6}.includes?(container.data["html_block_type"])) ? ContinueStatus::Stop : ContinueStatus::Continue
end

def token(parser : Parser, container : Node)
def token(parser : Parser, container : Node) : Nil
container.text = container.text.gsub(/(\n *)+$/, "")
end

def can_contain?(type)
false
end

def accepts_lines?
def accepts_lines? : Bool
true
end
end
Expand Down
8 changes: 4 additions & 4 deletions src/markd/rules/item.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ module Markd::Rule
struct Item
include Rule

def match(parser : Parser, container : Node)
def match(parser : Parser, container : Node) : MatchValue
# match and parse in Rule::List
MatchValue::None
end

def continue(parser : Parser, container : Node)
def continue(parser : Parser, container : Node) : ContinueStatus
indent_offset = container.data["marker_offset"].as(Int32) + container.data["padding"].as(Int32)

if parser.blank
Expand All @@ -26,15 +26,15 @@ module Markd::Rule
ContinueStatus::Continue
end

def token(parser : Parser, container : Node)
def token(parser : Parser, container : Node) : Nil
# do nothing
end

def can_contain?(type : Node::Type)
!type.item?
end

def accepts_lines?
def accepts_lines? : Bool
false
end
end
Expand Down
8 changes: 4 additions & 4 deletions src/markd/rules/list.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Markd::Rule
BULLET_LIST_MARKERS = {'*', '+', '-'}
ORDERED_LIST_MARKERS = {'.', ')'}

def match(parser : Parser, container : Node)
def match(parser : Parser, container : Node) : MatchValue
if (!parser.indented || container.type.list?)
data = parse_list_marker(parser, container)
return MatchValue::None unless data && !data.empty?
Expand All @@ -25,11 +25,11 @@ module Markd::Rule
end
end

def continue(parser : Parser, container : Node)
def continue(parser : Parser, container : Node) : ContinueStatus
ContinueStatus::Continue
end

def token(parser : Parser, container : Node)
def token(parser : Parser, container : Node) : Nil
item = container.first_child?
while item
if ends_with_blankline?(item) && item.next?
Expand All @@ -55,7 +55,7 @@ module Markd::Rule
type.item?
end

def accepts_lines?
def accepts_lines? : Bool
false
end

Expand Down
8 changes: 4 additions & 4 deletions src/markd/rules/paragraph.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ module Markd::Rule
struct Paragraph
include Rule

def match(parser : Parser, container : Node)
def match(parser : Parser, container : Node) : MatchValue
MatchValue::None
end

def continue(parser : Parser, container : Node)
def continue(parser : Parser, container : Node) : ContinueStatus
parser.blank ? ContinueStatus::Stop : ContinueStatus::Continue
end

def token(parser : Parser, container : Node)
def token(parser : Parser, container : Node) : Nil
has_reference_defs = false

while container.text[0]? == '[' &&
Expand All @@ -26,7 +26,7 @@ module Markd::Rule
false
end

def accepts_lines?
def accepts_lines? : Bool
true
end
end
Expand Down
8 changes: 4 additions & 4 deletions src/markd/rules/thematic_break.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Markd::Rule

THEMATIC_BREAK = /^(?:(?:\*[ \t]*){3,}|(?:_[ \t]*){3,}|(?:-[ \t]*){3,})[ \t]*$/

def match(parser : Parser, container : Node)
def match(parser : Parser, container : Node) : MatchValue
if !parser.indented && parser.line[parser.next_nonspace..-1].match(THEMATIC_BREAK)
parser.close_unmatched_blocks
parser.add_child(Node::Type::ThematicBreak, parser.next_nonspace)
Expand All @@ -15,20 +15,20 @@ module Markd::Rule
end
end

def continue(parser : Parser, container : Node)
def continue(parser : Parser, container : Node) : ContinueStatus
# a thematic break can never container > 1 line, so fail to match:
ContinueStatus::Stop
end

def token(parser : Parser, container : Node)
def token(parser : Parser, container : Node) : Nil
# do nothing
end

def can_contain?(type)
false
end

def accepts_lines?
def accepts_lines? : Bool
false
end
end
Expand Down
4 changes: 2 additions & 2 deletions src/markd/utils.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ module Markd
def self.timer(label : String, measure_time? : Bool)
return yield unless measure_time?

start_time = Time.now
start_time = Time.utc
yield

puts "#{label}: #{(Time.now - start_time).total_milliseconds}ms"
puts "#{label}: #{(Time.utc - start_time).total_milliseconds}ms"
end

DECODE_ENTITIES_REGEX = Regex.new("\\\\" + Rule::ESCAPABLE_STRING, Regex::Options::IGNORE_CASE)
Expand Down

0 comments on commit 20962e6

Please sign in to comment.