File tree 3 files changed +33
-2
lines changed
3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -669,6 +669,14 @@ impl CommonmarkerNode {
669
669
fn get_string_content ( & self ) -> Result < String , magnus:: Error > {
670
670
let node = self . inner . borrow ( ) ;
671
671
672
+ match node. data . value {
673
+ ComrakNodeValue :: Code ( ref code) => return Ok ( code. literal . to_string ( ) ) ,
674
+ ComrakNodeValue :: CodeBlock ( ref code_block) => {
675
+ return Ok ( code_block. literal . to_string ( ) )
676
+ }
677
+ _ => { }
678
+ }
679
+
672
680
match node. data . value . text ( ) {
673
681
Some ( s) => Ok ( s. to_string ( ) ) ,
674
682
None => Err ( magnus:: Error :: new (
@@ -681,6 +689,18 @@ impl CommonmarkerNode {
681
689
fn set_string_content ( & self , new_content : String ) -> Result < bool , magnus:: Error > {
682
690
let mut node = self . inner . borrow_mut ( ) ;
683
691
692
+ match node. data . value {
693
+ ComrakNodeValue :: Code ( ref mut code) => {
694
+ code. literal = new_content;
695
+ return Ok ( true ) ;
696
+ }
697
+ ComrakNodeValue :: CodeBlock ( ref mut code_block) => {
698
+ code_block. literal = new_content;
699
+ return Ok ( true ) ;
700
+ }
701
+ _ => { }
702
+ }
703
+
684
704
match node. data . value . text_mut ( ) {
685
705
Some ( s) => {
686
706
* s = new_content;
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
module Commonmarker
4
- VERSION = "1.1.1 "
4
+ VERSION = "1.1.2 "
5
5
end
Original file line number Diff line number Diff line change @@ -102,9 +102,10 @@ def test_delete
102
102
103
103
class StringContentTest < Minitest ::Test
104
104
def setup
105
- @document = Commonmarker . parse ( "**HELLO!** \n ***\n This has nodes!" )
105
+ @document = Commonmarker . parse ( "**HELLO!** \n ***\n This has ` nodes` !" )
106
106
@paragraph = @document . first_child
107
107
@emph = @paragraph . first_child
108
+ @code_inline = @document . last_child . last_child . previous_sibling
108
109
end
109
110
110
111
def test_node_can_get_string_content
@@ -128,6 +129,16 @@ def test_node_can_protect_against_nodes_without_string_content
128
129
129
130
assert_match ( %r{<strong>HELLO!</strong>} , @document . to_html )
130
131
end
132
+
133
+ def test_code_inline_can_get_string_content
134
+ assert_equal ( "nodes" , @code_inline . string_content )
135
+ end
136
+
137
+ def test_code_inline_can_set_string_content
138
+ @code_inline . string_content = "string content"
139
+
140
+ assert_match ( %r{<code>string content</code>} , @document . to_html )
141
+ end
131
142
end
132
143
133
144
class UrlTest < Minitest ::Test
You can’t perform that action at this time.
0 commit comments