summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2014-03-16 14:08:25 -0400
committerNick White <git@njw.name>2014-03-16 14:08:25 -0400
commit3d4c629ac293711074ac5a692b58db32f9c8bbc9 (patch)
tree29a00872e22a2201d576b50c5ad5bafc3ad32fd7
parent2a2919d9d26756e898a6fec0572ca01acbaff24b (diff)
downloadtkread-3d4c629ac293711074ac5a692b58db32f9c8bbc9.tar.bz2
tkread-3d4c629ac293711074ac5a692b58db32f9c8bbc9.zip
Improve image link parsing, and remove links completely for now
-rwxr-xr-xtkread29
1 files changed, 28 insertions, 1 deletions
diff --git a/tkread b/tkread
index 126156f..30639ce 100755
--- a/tkread
+++ b/tkread
@@ -123,13 +123,40 @@ proc markup {widget} {
if [file exists $localfile] {
set curimg [image create photo -file $localfile]
$widget image create $insertion -image $curimg
+ set cur $insertion
} else {
- $widget insert [indexmovechar $insertion "- 2"] $alt
+ $widget insert $insertion $alt
+ set cur [indexmovechar $insertion "+ [string length $alt]"]
}
set cur [$widget search {![} $cur end]
}
+ # remove links
+ # TODO: save the link contents and allow the links to be shown / hidden with a keystroke
+ set cur [$widget search {[} 0.0 end]
+ while {$cur != ""} {
+ set altstart [indexmovechar $cur "+ 1"]
+ set cur [$widget search "](" $cur end]
+ if {$cur == ""} { break }
+ set altend $cur
+ set srcstart [indexmovechar $cur "+ 1"]
+ set cur [$widget search ")" $cur end]
+ if {$cur == ""} { break }
+ set srcend $cur
+
+ set alt [$widget get $altstart $altend]
+ set src [$widget get $srcstart $srcend]
+
+ $widget delete [indexmovechar $altstart "- 1"] [indexmovechar $srcend "+ 1"]
+ set insertion [indexmovechar $altstart "- 1"]
+ $widget insert $insertion $alt
+
+ set cur [indexmovechar $insertion "+ [string length $alt]"]
+ set cur [$widget search {[} $cur end]
+ }
+
+
# process underlined headings
foreach fmt $underlinefmt {
set searchchar [lindex $fmt 0]