diff --git a/lib/squib/graphics/text.rb b/lib/squib/graphics/text.rb
index f84e386..61951c6 100644
--- a/lib/squib/graphics/text.rb
+++ b/lib/squib/graphics/text.rb
@@ -119,7 +119,8 @@ module Squib
while (key = next_embed(embed.rules.keys, clean_str)) != nil
rule = embed.rules[key]
spacing = rule[:width] * Pango::SCALE
- index = clean_str.index(key)
+ index = clean_str.index(key)
+ index = clean_str[0..index].bytesize #convert to byte index (bug #57)
str = str.sub(key, "aaa")
layout.markup = str
clean_str = layout.text
diff --git a/samples/embed_text.rb b/samples/embed_text.rb
index 4e6cf36..bc51973 100644
--- a/samples/embed_text.rb
+++ b/samples/embed_text.rb
@@ -66,8 +66,8 @@ Squib::Deck.new do
embed.png key: ':purse:', width: 28, height: 28, file: 'shiny-purse.png'
end
- embed_text = 'Markup and typography replacements with ":tool:" icons won\'t fail'
- text(str: embed_text, font: 'Serif 21', markup: true,
+ embed_text = 'Markup --- and typography replacements --- with ":tool:" icons won\'t fail'
+ text(str: embed_text, font: 'Serif 18', markup: true,
x: 600, y: 320, width: 180, height: 300,
align: :center, hint: :magenta) do |embed|
embed.svg key: ':tool:', width: 28, height: 28, file: 'spanner.svg'
diff --git a/spec/data/samples/embed_text.rb.txt b/spec/data/samples/embed_text.rb.txt
index 8dea7d1..628cf95 100644
--- a/spec/data/samples/embed_text.rb.txt
+++ b/spec/data/samples/embed_text.rb.txt
@@ -185,7 +185,7 @@ cairo: translate([600, 320])
cairo: rotate([0])
cairo: move_to([0, 0])
pango: font_description=([MockDouble])
-pango: text=(["Markup and typography replacements with \":tool:\" icons won't fail"])
+pango: text=(["Markup --- and typography replacements --- with \":tool:\" icons won't fail"])
pango: markup=(["foo"])
pango: width=([184320])
pango: height=([307200])