Class: Mdlint::Dialect
- Inherits:
-
Object
- Object
- Mdlint::Dialect
- Defined in:
- lib/mdlint/dialect.rb,
sig/mdlint.rbs
Constant Summary collapse
- BUILT_IN_FEATURES =
{ commonmark: [], gfm: %i[tables task_lists strikethrough bare_autolinks] }.freeze
Class Attribute Summary collapse
-
.features ⇒ Hash[Symbol, Array[Symbol]]
readonly
Returns the value of attribute features.
Instance Attribute Summary collapse
-
#features ⇒ Array[Symbol]
readonly
Returns the value of attribute features.
-
#name ⇒ Symbol
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #feature?(feature) ⇒ Boolean
- #gfm? ⇒ Boolean
-
#initialize(name = :commonmark, features: nil) ⇒ Dialect
constructor
A new instance of Dialect.
- #to_sym ⇒ Symbol
Constructor Details
#initialize(name = :commonmark, features: nil) ⇒ Dialect
Returns a new instance of Dialect.
36 37 38 39 |
# File 'lib/mdlint/dialect.rb', line 36 def initialize(name = :commonmark, features: nil) @name = name.to_s.downcase.to_sym @features = Array(features || self.class.features.fetch(@name, [])).map(&:to_sym).freeze end |
Class Attribute Details
.features ⇒ Hash[Symbol, Array[Symbol]] (readonly)
Returns the value of attribute features.
13 14 15 |
# File 'lib/mdlint/dialect.rb', line 13 def features @features end |
Instance Attribute Details
#features ⇒ Array[Symbol] (readonly)
Returns the value of attribute features.
34 35 36 |
# File 'lib/mdlint/dialect.rb', line 34 def features @features end |
#name ⇒ Symbol (readonly)
Returns the value of attribute name.
34 35 36 |
# File 'lib/mdlint/dialect.rb', line 34 def name @name end |
Class Method Details
.register(name, features: []) ⇒ Symbol
15 16 17 18 19 20 21 |
# File 'lib/mdlint/dialect.rb', line 15 def register(name, features: []) key = name.to_s.downcase.to_sym raise ArgumentError, "dialect name cannot be empty" if key.to_s.empty? @features[key] = Array(features).map(&:to_sym).uniq.freeze key end |
.registered ⇒ Array[Symbol]
23 24 25 |
# File 'lib/mdlint/dialect.rb', line 23 def registered @features.keys end |
.resolve(value) ⇒ Dialect
27 28 29 30 31 |
# File 'lib/mdlint/dialect.rb', line 27 def resolve(value) return value if value.is_a?(self) new(value || :commonmark) end |
Instance Method Details
#feature?(feature) ⇒ Boolean
45 46 47 |
# File 'lib/mdlint/dialect.rb', line 45 def feature?(feature) @features.include?(feature.to_sym) end |
#gfm? ⇒ Boolean
41 42 43 |
# File 'lib/mdlint/dialect.rb', line 41 def gfm? feature?(:tables) && feature?(:strikethrough) end |
#to_sym ⇒ Symbol
49 50 51 |
# File 'lib/mdlint/dialect.rb', line 49 def to_sym @name end |