Module: Ast::Crispr::Markdown::Markly::Selectors
- Defined in:
- lib/ast/crispr/markdown/markly.rb
Class Method Summary collapse
- .heading_section(heading_text:, level: nil, id: nil, limit: nil, metadata: {}, **options) ⇒ Object
- .html_comment(text:, id: nil, limit: nil, metadata: {}, **options) ⇒ Object
- .html_comment_block(start_text:, end_text:, id: nil, limit: nil, span: :nearest, include_trailing_gap: false, metadata: {}, **options) ⇒ Object
- .html_details(summary_text: nil, id: nil, limit: nil, metadata: {}, **options) ⇒ Object
- .inline_reference(label: nil, reference_kind: nil, id: nil, limit: nil, metadata: {}, **options) ⇒ Object
- .link_definition(label: nil, url: nil, id: nil, limit: nil, metadata: {}, **options) ⇒ Object
- .list_item(text: nil, id: nil, limit: nil, metadata: {}, **options) ⇒ Object
Class Method Details
.heading_section(heading_text:, level: nil, id: nil, limit: nil, metadata: {}, **options) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/ast/crispr/markdown/markly.rb', line 115 def heading_section(heading_text:, level: nil, id: nil, limit: nil, metadata: {}, **) Ast::Crispr::OwnerSelector.new( id: id || "heading_section_#{heading_text}", limit: limit, metadata: .merge( adapter: Ast::Crispr::Markdown::Markly.adapter, owner_scope: :heading_sections, selector_kind: :heading_section, selection_intent: :section_branch, include_trailing_gap: false ).merge(), locate: lambda do |context| context.structural_owners(owner_scope: :heading_sections).filter_map do |owner| next unless owner.heading_text.to_s.strip == heading_text.to_s.strip next if level && owner.level != level Ast::Crispr::Match.new( node: owner, start_line: owner.location.start_line, end_line: owner.location.end_line, metadata: { start_boundary: :owner_start, end_boundary: :owner_end, payload_kind: :section_branch, heading_text: owner.heading_text, level: owner.level, base: owner.base } ) end end ) end |
.html_comment(text:, id: nil, limit: nil, metadata: {}, **options) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/ast/crispr/markdown/markly.rb', line 182 def html_comment(text:, id: nil, limit: nil, metadata: {}, **) Ast::Crispr::OwnerSelector.new( id: id || "html_comment_#{text}", limit: limit, metadata: .merge( adapter: Ast::Crispr::Markdown::Markly.adapter, owner_scope: :html_comments, selector_kind: :html_comment, selection_intent: :predicate_filter, include_trailing_gap: false ).merge(), locate: lambda do |context| context.structural_owners(owner_scope: :html_comments).filter_map do |owner| next unless owner.text.to_s == text.to_s Ast::Crispr::Match.new( node: owner, start_line: owner.location.start_line, end_line: owner.location.end_line, metadata: { start_boundary: :owner_start, end_boundary: :owner_end, payload_kind: :structural_owner_body, text: owner.text } ) end end ) end |
.html_comment_block(start_text:, end_text:, id: nil, limit: nil, span: :nearest, include_trailing_gap: false, metadata: {}, **options) ⇒ Object
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/ast/crispr/markdown/markly.rb', line 313 def html_comment_block(start_text:, end_text:, id: nil, limit: nil, span: :nearest, include_trailing_gap: false, metadata: {}, **) Ast::Crispr::OwnerSelector.new( id: id || "html_comment_block_#{start_text}", limit: limit, metadata: .merge( adapter: Ast::Crispr::Markdown::Markly.adapter, owner_scope: :html_comments, selector_kind: :html_comment_block, selection_intent: :predicate_filter, include_trailing_gap: include_trailing_gap ).merge(), locate: lambda do |context| comments = context.structural_owners(owner_scope: :html_comments) if span.to_sym == :outermost opening = comments.find { |comment| comment.text.to_s == start_text.to_s } closing = comments.reverse.find do |comment| opening && comment.text.to_s == end_text.to_s && comment.location.end_line >= opening.location.start_line end next [] unless opening && closing end_line = closing.location.end_line end_line = context.(end_line) if include_trailing_gap next [ Ast::Crispr::Match.new( node: opening, start_line: opening.location.start_line, end_line: end_line, metadata: { start_boundary: :owner_start, end_boundary: (include_trailing_gap ? :owner_end_plus_trailing_gap : :owner_end), payload_kind: :structural_owner_body, start_text: start_text, end_text: end_text } ) ] end comments.each_with_index.filter_map do |owner, index| next unless owner.text.to_s == start_text.to_s closing = comments[index + 1..]&.find { |comment| comment.text.to_s == end_text.to_s } next unless closing end_line = closing.location.end_line end_line = context.(end_line) if include_trailing_gap Ast::Crispr::Match.new( node: owner, start_line: owner.location.start_line, end_line: end_line, metadata: { start_boundary: :owner_start, end_boundary: (include_trailing_gap ? :owner_end_plus_trailing_gap : :owner_end), payload_kind: :structural_owner_body, start_text: start_text, end_text: end_text } ) end end ) end |
.html_details(summary_text: nil, id: nil, limit: nil, metadata: {}, **options) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/ast/crispr/markdown/markly.rb', line 213 def html_details(summary_text: nil, id: nil, limit: nil, metadata: {}, **) Ast::Crispr::OwnerSelector.new( id: id || ['html_details', summary_text].compact.join(':'), limit: limit, metadata: .merge( adapter: Ast::Crispr::Markdown::Markly.adapter, owner_scope: :html_details, selector_kind: :html_details, selection_intent: :predicate_filter, include_trailing_gap: false ).merge(), locate: lambda do |context| context.structural_owners(owner_scope: :html_details).filter_map do |owner| next if summary_text && owner.summary_text.to_s.strip != summary_text.to_s.strip Ast::Crispr::Match.new( node: owner, start_line: owner.location.start_line, end_line: owner.location.end_line, metadata: { start_boundary: :owner_start, end_boundary: :owner_end, payload_kind: :structural_owner_body, summary_text: owner.summary_text } ) end end ) end |
.inline_reference(label: nil, reference_kind: nil, id: nil, limit: nil, metadata: {}, **options) ⇒ Object
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/ast/crispr/markdown/markly.rb', line 277 def inline_reference(label: nil, reference_kind: nil, id: nil, limit: nil, metadata: {}, **) Ast::Crispr::OwnerSelector.new( id: id || ['inline_reference', label, reference_kind].compact.join(':'), limit: limit, metadata: .merge( adapter: Ast::Crispr::Markdown::Markly.adapter, owner_scope: :inline_references, selector_kind: :inline_reference, selection_intent: :predicate_filter, include_trailing_gap: false ).merge(), locate: lambda do |context| context.structural_owners(owner_scope: :inline_references).filter_map do |owner| next if label && !owner.labels.include?(label.to_s) next if reference_kind && owner.reference_kind != reference_kind.to_sym Ast::Crispr::Match.new( node: owner, start_line: owner.location.start_line, end_line: owner.location.end_line, metadata: { start_boundary: :owner_start, end_boundary: :owner_end, payload_kind: :structural_owner_body, label: owner.label, labels: owner.labels, reference_kind: owner.reference_kind, start_column: owner.start_column, end_column: owner.end_column } ) end end ) end |
.link_definition(label: nil, url: nil, id: nil, limit: nil, metadata: {}, **options) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/ast/crispr/markdown/markly.rb', line 149 def link_definition(label: nil, url: nil, id: nil, limit: nil, metadata: {}, **) Ast::Crispr::OwnerSelector.new( id: id || ['link_definition', label, url].compact.join(':'), limit: limit, metadata: .merge( adapter: Ast::Crispr::Markdown::Markly.adapter, owner_scope: :link_definitions, selector_kind: :link_definition, selection_intent: :predicate_filter, include_trailing_gap: false ).merge(), locate: lambda do |context| context.structural_owners(owner_scope: :link_definitions).filter_map do |owner| next if label && owner.label.to_s != label.to_s next if url && owner.url.to_s != url.to_s Ast::Crispr::Match.new( node: owner, start_line: owner.location.start_line, end_line: owner.location.end_line, metadata: { start_boundary: :owner_start, end_boundary: :owner_end, payload_kind: :structural_owner_body, label: owner.label, url: owner.url } ) end end ) end |
.list_item(text: nil, id: nil, limit: nil, metadata: {}, **options) ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/ast/crispr/markdown/markly.rb', line 244 def list_item(text: nil, id: nil, limit: nil, metadata: {}, **) Ast::Crispr::OwnerSelector.new( id: id || ['list_item', text].compact.join(':'), limit: limit, metadata: .merge( adapter: Ast::Crispr::Markdown::Markly.adapter, owner_scope: :list_items, selector_kind: :list_item, selection_intent: :predicate_filter, include_trailing_gap: false ).merge(), locate: lambda do |context| context.structural_owners(owner_scope: :list_items).filter_map do |owner| next if text && !owner.text.to_s.include?(text.to_s) Ast::Crispr::Match.new( node: owner, start_line: owner.location.start_line, end_line: owner.location.end_line, metadata: { start_boundary: :owner_start, end_boundary: :owner_end, payload_kind: :structural_owner_body, depth: owner.depth, marker: owner.marker, text: owner.text } ) end end ) end |