Class: Markbridge::AST::Url
- Defined in:
- lib/markbridge/ast/url.rb
Overview
Represents a hyperlink/URL element.
Instance Attribute Summary collapse
-
#href ⇒ String?
readonly
The URL/href for this link.
Attributes inherited from Element
Instance Method Summary collapse
-
#bare? ⇒ Boolean
Whether this link is "bare" — it has no link text of its own: either no children, or a single Text child whose content is exactly the href (how parsers model a URL that stands for itself).
-
#initialize(href: nil) ⇒ Url
constructor
Create a new URL element.
Methods inherited from Element
#<<, #descendants, #each_descendant, #replace_child
Constructor Details
#initialize(href: nil) ⇒ Url
Create a new URL element.
21 22 23 24 |
# File 'lib/markbridge/ast/url.rb', line 21 def initialize(href: nil) super() @href = href end |
Instance Attribute Details
#href ⇒ String? (readonly)
Returns the URL/href for this link.
16 17 18 |
# File 'lib/markbridge/ast/url.rb', line 16 def href @href end |
Instance Method Details
#bare? ⇒ Boolean
Whether this link is "bare" — it has no link text of its own: either no children, or a single Text child whose content is exactly the href (how parsers model a URL that stands for itself). Consumers that record or rewrite links need this judgment too (a bare URL must stay bare to keep autolinking and oneboxing working), so it lives on the node rather than in the renderer.
35 36 37 38 39 |
# File 'lib/markbridge/ast/url.rb', line 35 def return true if children.empty? children.size == 1 && children.first.instance_of?(Text) && children.first.text == href end |