diff --git a/ext/commonmarker/src/node.rs b/ext/commonmarker/src/node.rs index 889be7d9..2b7b2f85 100644 --- a/ext/commonmarker/src/node.rs +++ b/ext/commonmarker/src/node.rs @@ -669,6 +669,14 @@ impl CommonmarkerNode { fn get_string_content(&self) -> Result { let node = self.inner.borrow(); + match node.data.value { + ComrakNodeValue::Code(ref code) => return Ok(code.literal.to_string()), + ComrakNodeValue::CodeBlock(ref code_block) => { + return Ok(code_block.literal.to_string()) + } + _ => {} + } + match node.data.value.text() { Some(s) => Ok(s.to_string()), None => Err(magnus::Error::new( @@ -681,6 +689,18 @@ impl CommonmarkerNode { fn set_string_content(&self, new_content: String) -> Result { let mut node = self.inner.borrow_mut(); + match node.data.value { + ComrakNodeValue::Code(ref mut code) => { + code.literal = new_content; + return Ok(true); + } + ComrakNodeValue::CodeBlock(ref mut code_block) => { + code_block.literal = new_content; + return Ok(true); + } + _ => {} + } + match node.data.value.text_mut() { Some(s) => { *s = new_content; diff --git a/lib/commonmarker/version.rb b/lib/commonmarker/version.rb index abefa122..bb385a6e 100644 --- a/lib/commonmarker/version.rb +++ b/lib/commonmarker/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Commonmarker - VERSION = "1.1.1" + VERSION = "1.1.2" end diff --git a/test/node_test.rb b/test/node_test.rb index 764f5c55..3b9bbd4f 100644 --- a/test/node_test.rb +++ b/test/node_test.rb @@ -102,9 +102,10 @@ def test_delete class StringContentTest < Minitest::Test def setup - @document = Commonmarker.parse("**HELLO!** \n***\n This has nodes!") + @document = Commonmarker.parse("**HELLO!** \n***\n This has `nodes`!") @paragraph = @document.first_child @emph = @paragraph.first_child + @code_inline = @document.last_child.last_child.previous_sibling end def test_node_can_get_string_content @@ -128,6 +129,16 @@ def test_node_can_protect_against_nodes_without_string_content assert_match(%r{HELLO!}, @document.to_html) end + + def test_code_inline_can_get_string_content + assert_equal("nodes", @code_inline.string_content) + end + + def test_code_inline_can_set_string_content + @code_inline.string_content = "string content" + + assert_match(%r{string content}, @document.to_html) + end end class UrlTest < Minitest::Test