Skip to content

Add Node#fenced method for code block fence metadata#20

Open
kristoph wants to merge 1 commit intosocketry:mainfrom
kristoph:add-node-fenced
Open

Add Node#fenced method for code block fence metadata#20
kristoph wants to merge 1 commit intosocketry:mainfrom
kristoph:add-node-fenced

Conversation

@kristoph
Copy link
Copy Markdown

Adds Markly::Node#fenced method to expose fence metadata for code block nodes.

For fenced code blocks, returns a hash with:

  • :info — the info string (e.g., "ruby" in ```ruby)
  • :length — fence length (number of backticks/tildes)
  • :character — the fence character ("`" or "~")
  • :offset — the indentation offset

Returns nil for indented code blocks or non-code-block nodes.

Example

doc = Markly.parse("```ruby\nputs 'hi'\n```")
doc.walk do |node|
  if node.type == :code_block && (fence = node.fenced)
    puts fence[:info]      # => "ruby"
    puts fence[:character] # => "`"
  end
end

@ioquatix
Copy link
Copy Markdown
Member

ioquatix commented Apr 9, 2026

I'm not sure about the name fenced. I also wonder if we should use a Hash for this. Is there any precedent in other parts of the code? Maybe it's better to use a Data or Struct? 🤷

However, in principle, I am okay with this change.

Returns a hash with {:info, :length, :character, :offset} for fenced code blocks, nil for non-fenced or non-code-block nodes.
@ioquatix
Copy link
Copy Markdown
Member

After thinking about this, what about adding fence_character or fence_marker etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants