forked from bridgetownrb/bridgetown
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:bridgetownrb/bridgetown
- Loading branch information
Showing
32 changed files
with
428 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
bridgetown-core/lib/bridgetown-core/concerns/prioritizable.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
module Bridgetown | ||
module Prioritizable | ||
module ClassMethods | ||
# @!method priorities | ||
# @return [Hash<Symbol, Object>] | ||
|
||
# Get or set the priority of this class. When called without an | ||
# argument it returns the priority. When an argument is given, it will | ||
# set the priority. | ||
# | ||
# @param priority [Symbol] new priority (optional) | ||
# Valid options are: `:lowest`, `:low`, `:normal`, `:high`, `:highest` | ||
# @return [Symbol] | ||
def priority(priority = nil) | ||
@priority ||= nil | ||
@priority = priority if priority && priorities.key?(priority) | ||
@priority || :normal | ||
end | ||
|
||
# Spaceship is priority [higher -> lower] | ||
# | ||
# @param other [Class] The class to be compared. | ||
# @return [Integer] -1, 0, 1. | ||
def <=>(other) | ||
priorities[other.priority] <=> priorities[priority] | ||
end | ||
end | ||
|
||
def self.included(klass) | ||
klass.extend ClassMethods | ||
klass.class_attribute :priorities, instance_accessor: false | ||
end | ||
|
||
# Spaceship is priority [higher -> lower] | ||
# | ||
# @param other [object] The object to be compared. | ||
# @return [Integer] -1, 0, 1. | ||
def <=>(other) | ||
self.class <=> other.class | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
bridgetown-core/lib/bridgetown-core/kramdown/parser/gfm.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Frozen-string-literal: true | ||
|
||
require "kramdown-parser-gfm" | ||
|
||
module Kramdown | ||
module Parser | ||
class GFM | ||
MARK_DELIMITER = %r{(==|::)+}.freeze | ||
MARK_MATCH = %r{#{MARK_DELIMITER}(?!\s|=|:).*?[^\s=:]#{MARK_DELIMITER}}m.freeze | ||
|
||
# Monkey-patch GFM initializer to add our new mark parser | ||
alias_method :_old_initialize, :initialize | ||
def initialize(source, options) | ||
_old_initialize(source, options) | ||
@span_parsers << :mark if @options[:mark_highlighting] | ||
end | ||
|
||
def parse_mark | ||
line_number = @src.current_line_number | ||
|
||
@src.pos += @src.matched_size | ||
el = Element.new(:html_element, "mark", {}, category: :span, line: line_number) | ||
@tree.children << el | ||
|
||
env = save_env | ||
reset_env(src: Kramdown::Utils::StringScanner.new(@src.matched[2..-3], line_number), | ||
text_type: :text) | ||
parse_spans(el) | ||
restore_env(env) | ||
|
||
el | ||
end | ||
define_parser(:mark, MARK_MATCH) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.